ToolJet/frontend/src/Editor/QueryManager/QueryEditors/Elasticsearch.jsx

113 lines
3 KiB
React
Raw Normal View History

2021-04-28 08:06:14 +00:00
import React from 'react';
import CodeMirror from '@uiw/react-codemirror';
import 'codemirror/theme/duotone-light.css';
import SelectSearch, { fuzzySearch } from 'react-select-search';
class Elasticsearch extends React.Component {
2021-04-30 06:31:32 +00:00
constructor(props) {
super(props);
2021-04-28 08:06:14 +00:00
2021-04-30 06:31:32 +00:00
this.state = {
options: this.props.options
2021-04-30 06:31:32 +00:00
};
}
2021-04-28 08:06:14 +00:00
2021-04-30 06:31:32 +00:00
componentDidMount() {
this.setState({
options: this.props.options
2021-04-30 06:31:32 +00:00
});
}
2021-04-28 08:06:14 +00:00
changeOption = (option, value) => {
2021-04-30 06:31:32 +00:00
this.setState(
{
options: {
...this.state.options,
[option]: value
}
2021-04-30 06:31:32 +00:00
},
() => {
this.props.optionsChanged(this.state.options);
}
);
}
2021-04-28 08:06:14 +00:00
2021-04-30 06:31:32 +00:00
changeOperation = (operation) => {
this.setState(
{
options: {
...this.state.options,
operation
}
2021-04-30 06:31:32 +00:00
},
() => {
this.props.optionsChanged(this.state.options);
}
);
};
2021-04-28 08:06:14 +00:00
2021-04-30 06:31:32 +00:00
render() {
const { options } = this.state;
2021-04-28 08:06:14 +00:00
2021-04-30 06:31:32 +00:00
return (
<div>
{options && (
<div>
<div className="mb-3 mt-2">
2021-04-30 06:31:32 +00:00
<label className="form-label">Operation</label>
<SelectSearch
options={[
{ value: 'search', name: 'Search' }
2021-04-30 06:31:32 +00:00
// { value: 'index', name: 'Index'},
// { value: 'create', name: 'Create'},
// { value: 'update', name: 'Update'},
]}
value={this.state.options.operation}
search={false}
onChange={(value) => {
this.changeOperation(value);
}}
filterOptions={fuzzySearch}
placeholder="Select.."
/>
</div>
{options.operation === 'search' && (
<div>
<div className="mb-3 mt-2">
2021-04-30 06:31:32 +00:00
<label className="form-label text-muted">Index</label>
<input
type="text"
value={this.state.options.index}
onChange={(e) => {
this.changeOption('index', e.target.value);
}}
className="form-control"
/>
</div>
<div className="mb-3 mt-2">
2021-04-30 06:31:32 +00:00
<label className="form-label text-reset">Query</label>
<CodeMirror
height="auto"
2021-04-30 06:31:32 +00:00
fontSize="2"
placeholder={'{ "name": "" }'}
2021-04-30 06:31:32 +00:00
value={options.query}
onChange={(instance) => this.changeOption('query', instance.getValue())}
2021-04-30 06:31:32 +00:00
options={{
theme: 'duotone-light',
mode: 'javascript',
lineWrapping: true,
scrollbarStyle: null
2021-04-30 06:31:32 +00:00
}}
/>
</div>
</div>
)}
</div>
)}
</div>
);
}
2021-04-28 08:06:14 +00:00
}
export { Elasticsearch };