import React from 'react'; import { CodeHinter } from '../../CodeBuilder/CodeHinter'; import 'codemirror/theme/duotone-light.css'; import SelectSearch, { fuzzySearch } from 'react-select-search'; class Restapi extends React.Component { constructor(props) { super(props); this.state = { options: this.props.options }; } componentDidMount() { this.setState({ options: this.props.options }); } changeOption = (option, value) => { const { options } = this.state; const newOptions = { ...options, [option]: value }; this.setState({ options: newOptions }); this.props.optionsChanged(newOptions); }; addNewKeyValuePair = (option) => { const { options } = this.state; const newOptions = { ...options, [option]: [...options[option], ['', '']] }; this.setState({ options: newOptions }); this.props.optionsChanged(newOptions); }; removeKeyValuePair = (option, index) => { const { options } = this.state; options[option].splice(index, 1); this.setState({ options }); this.props.optionsChanged(options); }; keyValuePairValueChanged = (value, keyIndex, option, index) => { const { options } = this.state; options[option][index][keyIndex] = value; this.setState({ options }); this.props.optionsChanged(options); }; render() { const { options } = this.state; return (
{ this.changeOption('method', value); }} filterOptions={fuzzySearch} placeholder="Method" />
{ this.changeOption('url', value); }} />
{['url_params', 'headers', 'body'].map((option) => (
{(options[option] || []).map((pair, index) => (
this.keyValuePairValueChanged(value, 0, option, index)} /> this.keyValuePairValueChanged(value, 1, option, index)} /> { this.removeKeyValuePair(option, index); }} > x
))}
))}
); } } export { Restapi };