diff --git a/src/components/ConfigurationEditorCode/index.tsx b/src/components/ConfigurationEditorCode/index.tsx new file mode 100644 index 0000000..891f258 --- /dev/null +++ b/src/components/ConfigurationEditorCode/index.tsx @@ -0,0 +1,62 @@ +import { FC } from 'react' +import { ConfigurationEditorPropsType } from '@pages/ConfigurationEditorPage' +import Editor from '@monaco-editor/react' +import { ConfigType } from '@pages/ModulesPage/module.type.ts' +import { message } from 'antd' + +const ConfigurationEditorCode: FC = ({setDisableBtn= () => {}, bufConfig, setBufConfig }) => { + const debounce = (func: (...args: any[]) => void, wait: number) => { + let timeout: NodeJS.Timeout + return (...args: []) => { + clearTimeout(timeout) + timeout = setTimeout(() => { + func.apply(this, [...args]) + }, wait) + } + } + + const debouncedHandleError = debounce(() => { + message.error('Невалидный JSON объект') + }, 500) + + const handleChange = (data: string | undefined) => { + + if (data) { + try { + const newData = { + ...bufConfig, + data: {...JSON.parse(data) } + } as ConfigType + setDisableBtn(false) + setBufConfig(newData) + } catch (error) { + debouncedHandleError() + setDisableBtn(true) + } + } + } + + const editorValue = JSON.stringify(bufConfig?.data, null, '\t') + + return ( +
+ +
+ ) +} + +export default ConfigurationEditorCode \ No newline at end of file