2021-05-13 13:31:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import 'codemirror/theme/duotone-light.css';
|
|
|
|
|
import SelectSearch, { fuzzySearch } from 'react-select-search';
|
|
|
|
|
import { CodeHinter } from '../../CodeBuilder/CodeHinter';
|
|
|
|
|
|
|
|
|
|
class Dynamodb extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
options: this.props.options
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.setState({
|
|
|
|
|
options: this.props.options
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeOption = (option, value) => {
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
options: {
|
|
|
|
|
...this.state.options,
|
|
|
|
|
[option]: value
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
this.props.optionsChanged(this.state.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: 'list_tables', name: 'List Tables' },
|
2021-05-24 04:42:57 +00:00
|
|
|
{ value: 'get_item', name: 'Get Item' },
|
2021-05-13 13:31:55 +00:00
|
|
|
]}
|
|
|
|
|
value={this.state.options.operation}
|
|
|
|
|
search={true}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
this.changeOperation(value);
|
|
|
|
|
}}
|
|
|
|
|
filterOptions={fuzzySearch}
|
|
|
|
|
placeholder="Select.."
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2021-05-24 04:42:57 +00:00
|
|
|
|
|
|
|
|
{(this.state.options.operation === 'get_item') && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label">Table</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.table}
|
|
|
|
|
onChange={(value) => this.changeOption('table', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label">Key</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={typeof this.state.options.key === 'string' ? this.state.options.key : JSON.stringify(this.state.options.key )}
|
|
|
|
|
theme="duotone-light"
|
|
|
|
|
mode="javascript"
|
|
|
|
|
lineNumbers={true}
|
|
|
|
|
className="query-hinter"
|
|
|
|
|
onChange={(value) => this.changeOption('key', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2021-05-13 13:31:55 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { Dynamodb };
|