ToolJet/frontend/src/Editor/QueryManager/QueryEditors/Elasticsearch.jsx
Arpit 26c9cc655c
Fix linting errors across the app (#785)
* eslint-setup: rules for frontend and server

* setup pre-commit:hook

* frontend:eslint fixes

* frontend eslint errors and warning fixed

* eslint:fix for ./server

* fix server/test: expectatin string lint/error

* pre-commit:updated

* removed unwanted install cmd from docker file

* recommended settings and extension for vscode

* husky prepare script added

* updated extension recommendations

* added prettier as recommended extension

* added pre-commit to package.json

* remove .prettierrc file

* resolve changes

* resolve changes
2021-09-21 19:18:28 +05:30

180 lines
6.6 KiB
JavaScript

import React from 'react';
import 'codemirror/theme/duotone-light.css';
import SelectSearch, { fuzzySearch } from 'react-select-search';
import { CodeHinter } from '../../CodeBuilder/CodeHinter';
import { changeOption } from './utils';
class Elasticsearch extends React.Component {
constructor(props) {
super(props);
this.state = {
options: this.props.options,
};
}
componentDidMount() {
this.setState({
options: this.props.options,
});
}
changeOperation = (operation) => {
this.setState(
{
options: {
...this.state.options,
operation,
},
},
() => {
this.props.optionsChanged(this.state.options);
}
);
};
render() {
const { options } = this.state;
return (
<div>
{options && (
<div>
<div className="mb-3 mt-2">
<label className="form-label">Operation</label>
<SelectSearch
options={[
{ value: 'search', name: 'Search' },
{ value: 'index_document', name: 'Index a document' },
{ value: 'get', name: 'Get a document' },
{ value: 'update', name: 'Update a document' },
]}
value={this.state.options.operation}
search={false}
onChange={(value) => {
this.changeOperation(value);
}}
filterOptions={fuzzySearch}
placeholder="Select.."
/>
</div>
{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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'index', value)}
/>
</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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'id', value)}
/>
</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 } }'}
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
lineNumbers={true}
className="query-hinter"
onChange={(value) => changeOption(this, 'body', value)}
/>
</div>
</div>
)}
{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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'index', value)}
/>
</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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'id', value)}
/>
</div>
</div>
)}
{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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'index', value)}
/>
</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" }'}
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
lineNumbers={true}
className="query-hinter"
onChange={(value) => changeOption(this, 'body', value)}
/>
</div>
</div>
)}
{options.operation === 'search' && (
<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}
theme={this.props.darkMode ? 'monokai' : 'default'}
onChange={(value) => changeOption(this, 'index', value)}
/>
</div>
<div className="mb-3 mt-2">
<label className="form-label text-reset">Query</label>
<CodeHinter
currentState={this.props.currentState}
initialValue={options.query}
mode="sql"
placeholder={'{ "name": "" }'}
theme={this.props.darkMode ? 'monokai' : 'duotone-light'}
lineNumbers={true}
className="query-hinter"
onChange={(value) => changeOption(this, 'query', value)}
/>
</div>
</div>
)}
</div>
)}
</div>
);
}
}
export { Elasticsearch };