2021-04-28 08:06:14 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import 'codemirror/theme/duotone-light.css';
|
|
|
|
|
import SelectSearch, { fuzzySearch } from 'react-select-search';
|
2021-05-09 03:17:19 +00:00
|
|
|
import { CodeHinter } from '../../CodeBuilder/CodeHinter';
|
2021-06-03 06:59:27 +00:00
|
|
|
import { changeOption } from './utils';
|
2021-04-28 08:06:14 +00:00
|
|
|
|
|
|
|
|
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 = {
|
2021-09-21 13:48:28 +00:00
|
|
|
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({
|
2021-09-21 13:48:28 +00:00
|
|
|
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
|
|
|
changeOperation = (operation) => {
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
options: {
|
|
|
|
|
...this.state.options,
|
2021-09-21 13:48:28 +00:00
|
|
|
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>
|
2021-04-30 08:10:57 +00:00
|
|
|
<div className="mb-3 mt-2">
|
2021-04-30 06:31:32 +00:00
|
|
|
<label className="form-label">Operation</label>
|
|
|
|
|
<SelectSearch
|
|
|
|
|
options={[
|
2021-05-14 12:59:33 +00:00
|
|
|
{ value: 'search', name: 'Search' },
|
2021-09-21 13:48:28 +00:00
|
|
|
{ value: 'index_document', name: 'Index a document' },
|
|
|
|
|
{ value: 'get', name: 'Get a document' },
|
|
|
|
|
{ value: 'update', name: 'Update a document' },
|
2021-04-30 06:31:32 +00:00
|
|
|
]}
|
|
|
|
|
value={this.state.options.operation}
|
|
|
|
|
search={false}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
this.changeOperation(value);
|
|
|
|
|
}}
|
|
|
|
|
filterOptions={fuzzySearch}
|
|
|
|
|
placeholder="Select.."
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-05-14 12:59:33 +00:00
|
|
|
|
2021-05-14 13:25:17 +00:00
|
|
|
{options.operation === 'update' && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Index</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.index}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'index', value)}
|
2021-05-14 13:25:17 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Id</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.id}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'id', value)}
|
2021-05-14 13:25:17 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-reset">Body</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={options.body}
|
|
|
|
|
mode="javascript"
|
|
|
|
|
placeholder={'{ doc: { page_count: 225 } }'}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
|
2021-05-14 13:25:17 +00:00
|
|
|
lineNumbers={true}
|
|
|
|
|
className="query-hinter"
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'body', value)}
|
2021-05-14 13:25:17 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2021-05-14 13:16:50 +00:00
|
|
|
{options.operation === 'get' && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Index</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.index}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'index', value)}
|
2021-05-14 13:16:50 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Id</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.id}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'id', value)}
|
2021-05-14 13:16:50 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2021-05-14 12:59:33 +00:00
|
|
|
{options.operation === 'index_document' && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Index</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.index}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'index', value)}
|
2021-05-14 12:59:33 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-reset">Body</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={options.body}
|
|
|
|
|
mode="javascript"
|
|
|
|
|
placeholder={'{ "name": "The Hitchhikers Guide to the Galaxy" }'}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
|
2021-05-14 12:59:33 +00:00
|
|
|
lineNumbers={true}
|
|
|
|
|
className="query-hinter"
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'body', value)}
|
2021-05-14 12:59:33 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2021-04-30 06:31:32 +00:00
|
|
|
{options.operation === 'search' && (
|
|
|
|
|
<div>
|
2021-04-30 08:10:57 +00:00
|
|
|
<div className="mb-3 mt-2">
|
2021-04-30 06:31:32 +00:00
|
|
|
<label className="form-label text-muted">Index</label>
|
2021-05-09 03:17:19 +00:00
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.index}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'index', value)}
|
2021-04-30 06:31:32 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
2021-04-30 08:10:57 +00:00
|
|
|
<div className="mb-3 mt-2">
|
2021-04-30 06:31:32 +00:00
|
|
|
<label className="form-label text-reset">Query</label>
|
2021-05-09 04:25:17 +00:00
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={options.query}
|
|
|
|
|
mode="sql"
|
2021-04-30 08:10:57 +00:00
|
|
|
placeholder={'{ "name": "" }'}
|
2021-07-03 14:17:47 +00:00
|
|
|
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
|
2021-05-09 04:25:17 +00:00
|
|
|
lineNumbers={true}
|
|
|
|
|
className="query-hinter"
|
2021-06-03 06:59:27 +00:00
|
|
|
onChange={(value) => changeOption(this, 'query', value)}
|
2021-04-30 06:31:32 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-04-28 08:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { Elasticsearch };
|