aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/search-component/src/main/js/search/search.js
blob: a742f11dbd43dd2ce77c973b5c81f72937613e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, {Component} from 'react';
import Select from '@jetbrains/ring-ui/components/select/select';
import '@jetbrains/ring-ui/components/input-size/input-size.scss';

class WithFuzzySearchFilterComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {selected: props.data[0]};
  }

  clearSelection = () => {
    this.setState({selected: null});
  };

  onSelect = option => {
    window.location.href = `${window.pathToRoot}${option.location}?query${option.name}`;
    this.setState({selected: option});
    debugger
  };

  render() {
    return (
      <div className="search-container">
        <div className="search">
          <Select
            selectedLabel="Search"
            label="Please type page name"
            filter={{fuzzy: true}}
            clear
            selected={this.state.selected}
            data={this.props.data}
            onSelect={this.onSelect}
          />
        </div>
      </div>
    );
  }
}

export const WithFuzzySearchFilter = () => {
  let data = [];
  if (window.pages) {
    data = window.pages.map((page, i) => ({
      ...page,
      label: page.name,
      key: i + 1,
      type: page.kind
    }));
  }

  return <WithFuzzySearchFilterComponent data={data}/>;
};