import React from 'react'; import { CodeBuilder } from '../../CodeBuilder/CodeBuilder'; import { CodeHinter } from '../../CodeBuilder/CodeHinter'; import CodeMirror from '@uiw/react-codemirror'; import 'codemirror/theme/duotone-light.css'; 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 = (e, keyIndex, option, index) => { const value = e.target.value; const { options } = this.state; options[option][index][keyIndex] = value; this.setState({ options }); this.props.optionsChanged(options); }; render() { const { options } = this.state; return (
{/* { this.changeOption('url', e.target.value)}} placeholder="https://api.example.com/v2/endpoint.json" /> */} { this.changeOption('url', value)}} /> {/* setCursorPosition(instance.getCursor().ch)} // onChange={(instance) => delayedHandleChange(instance)} value={options.url} // onFocus={(instance) => handleOnFocus(instance)} // onBlur={() => { // setShowDropdown(false); // }} options={{ mode: 'javascript', lineWrapping: true, scrollbarStyle: null, lineNumbers: false }} /> */}
{['url_params', 'headers', 'body'].map((option) => (
{options[option].map((pair, index) => (
this.keyValuePairValueChanged(e, 0, option, index)} /> this.keyValuePairValueChanged(e, 1, option, index)} /> { this.removeKeyValuePair(option, index); }} > x
))}
))}
); } } export { Restapi };