2021-06-02 09:14:52 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
import 'codemirror/theme/duotone-light.css';
|
|
|
|
|
import SelectSearch, { fuzzySearch } from 'react-select-search';
|
|
|
|
|
import { CodeHinter } from '../../CodeBuilder/CodeHinter';
|
2021-06-03 06:59:27 +00:00
|
|
|
import { changeOption } from './utils';
|
2021-06-02 09:14:52 +00:00
|
|
|
|
|
|
|
|
class Airtable extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2021-09-21 13:48:28 +00:00
|
|
|
options: this.props.options,
|
2021-06-02 09:14:52 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.setState({
|
2021-09-21 13:48:28 +00:00
|
|
|
options: this.props.options,
|
2021-06-02 09:14:52 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changeOperation = (operation) => {
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
options: {
|
|
|
|
|
...this.state.options,
|
2021-09-21 13:48:28 +00:00
|
|
|
operation,
|
|
|
|
|
},
|
2021-06-02 09:14:52 +00:00
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
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_records', name: 'List records' },
|
2021-06-02 10:12:35 +00:00
|
|
|
{ value: 'retrieve_record', name: 'Retrieve record' },
|
2021-08-12 15:36:31 +00:00
|
|
|
{ value: 'update_record', name: 'Update record' },
|
2021-08-05 11:18:09 +00:00
|
|
|
{ value: 'delete_record', name: 'Delete record' },
|
2021-06-02 09:14:52 +00:00
|
|
|
]}
|
|
|
|
|
value={this.state.options.operation}
|
|
|
|
|
search={true}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
this.changeOperation(value);
|
|
|
|
|
}}
|
|
|
|
|
filterOptions={fuzzySearch}
|
|
|
|
|
placeholder="Select.."
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-08-05 11:18:09 +00:00
|
|
|
{['list_records'].includes(this.state.options.operation) && (
|
2021-06-02 09:14:52 +00:00
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Base ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.base_id}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'base_id', value)}
|
2021-06-02 09:14:52 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Table name</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.table_name}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'table_name', value)}
|
2021-06-02 09:14:52 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Page size</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.page_size}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'page_size', value)}
|
2021-06-02 09:14:52 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Offset</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.offset}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'offset', value)}
|
2021-06-02 09:14:52 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2021-08-05 11:18:09 +00:00
|
|
|
{['retrieve_record'].includes(this.state.options.operation) && (
|
2021-06-02 10:12:35 +00:00
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Base ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.base_id}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'base_id', value)}
|
2021-06-02 10:12:35 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Table name</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.table_name}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'table_name', value)}
|
2021-06-02 10:12:35 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Record ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.record_id}
|
2021-06-02 10:20:50 +00:00
|
|
|
className="codehinter-query-editor-input"
|
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, 'record_id', value)}
|
2021-06-02 10:12:35 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2021-08-12 15:36:31 +00:00
|
|
|
{['update_record'].includes(this.state.options.operation) && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Base ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.base_id}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'base_id', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Table name</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.table_name}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'table_name', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Record ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.record_id}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'record_id', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label">Body</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={'{}'}
|
|
|
|
|
lineNumbers={true}
|
|
|
|
|
className="query-hinter"
|
|
|
|
|
theme={'duotone-light'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'body', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2021-08-05 11:18:09 +00:00
|
|
|
{['delete_record'].includes(this.state.options.operation) && (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Base ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.base_id}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'base_id', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Table name</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.table_name}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'table_name', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mb-3 mt-2">
|
|
|
|
|
<label className="form-label text-muted">Record ID</label>
|
|
|
|
|
<CodeHinter
|
|
|
|
|
currentState={this.props.currentState}
|
|
|
|
|
initialValue={this.state.options.record_id}
|
|
|
|
|
className="codehinter-query-editor-input"
|
|
|
|
|
theme={this.props.darkMode ? 'monokai' : 'default'}
|
|
|
|
|
onChange={(value) => changeOption(this, 'record_id', value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2021-06-02 09:14:52 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 13:48:28 +00:00
|
|
|
export { Airtable };
|