diff --git a/src/components/ConfigurationEditorForm/index.tsx b/src/components/ConfigurationEditorForm/index.tsx new file mode 100644 index 0000000..5ccd5df --- /dev/null +++ b/src/components/ConfigurationEditorForm/index.tsx @@ -0,0 +1,112 @@ +import { Theme as AntDTheme } from '@rjsf/antd' +import { withTheme } from '@rjsf/core' +import { UiSchema } from '@rjsf/utils' +import validator from '@rjsf/validator-ajv8' +import { FC, useEffect, useState } from 'react' + +import { ConfigurationEditorPropsType } from '@pages/ConfigurationEditorPage' +import { Tabs } from 'antd' +import equal from 'deep-equal' +import { useParams } from 'react-router-dom' + +const ConfigurationEditorForm: FC = ({ + bufConfig ={}, + JsonSchema, + setBufConfig, + }) => { + const Form = withTheme(AntDTheme) + const sortProps = (a, b) => a.name.localeCompare(b.name) + + const [formState, setFormState] = useState(bufConfig.data) + const [activeTabKey, setActiveTabKey] = useState() + const {id} = useParams() + + useEffect(() => { + if(!equal(formState, bufConfig.data)) { + setFormState(bufConfig.data) + } + }, [bufConfig.data]) + + const uiSchema: UiSchema = { + 'ui:submitButtonOptions': { + norender: true + } + } + + const onFormChange = data => { + if(!equal(data.formData, bufConfig.data)) { + const newData = { + ...bufConfig, + data: { ...data.formData } + } + if(!equal(newData, bufConfig.data)) { + setBufConfig(newData) + } + + } + } + + const handleTabsChange = e => { + setActiveTabKey(e) + } + + const ObjectFieldTemplate = (props) => { + const { + properties, + idSchema, + schema: { properties: schemaProperties } + } = props + properties.sort(sortProps) + + if (idSchema.$id === 'root') { + const propsComplex: [] = [] + const propsSimple: [] = [] + + properties.forEach((prop) => { + const fieldType = schemaProperties[prop.name].type + if (!fieldType || fieldType === 'array' || fieldType === 'object') { + propsComplex.push(prop) + } else { + propsSimple.push(prop) + } + }) + + return ( + element.content), + }] : []), + ...propsComplex.map((element) => ({ + label: schemaProperties[element.name]?.title || element.name, + key: element.name, + children: element.content, + })), + ]} /> + ) + } + + return properties.map((element) => element.content) + } + + return ( +
+
+
+ ) +} + +export default ConfigurationEditorForm