This commit is contained in:
Ilija Lazoroski 2022-07-13 15:33:34 +02:00
parent 4240ea02ef
commit 891041d15b
1 changed files with 21 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import Form from 'react-jsonschema-form-bs4'; import Form from 'react-jsonschema-form-bs4';
import React, {useState} from 'react'; import React, {useState, useEffect} from 'react';
import {Nav} from 'react-bootstrap'; import {Nav} from 'react-bootstrap';
import {CREDENTIALS} from '../../services/configuration/credentials.js'; import {CREDENTIALS} from '../../services/configuration/credentials.js';
@ -21,21 +21,34 @@ export default function PropagationConfig(props) {
className, className,
formData formData
} = props; } = props;
console.log(schema, uiSchema, formData);
const [selectedSection, setSelectedSection] = useState(initialSection); const [selectedSection, setSelectedSection] = useState(initialSection);
const [displayedSchema, setDisplayedSchema] = useState(getSchemaByKey(schema, initialSection)); const [displayedSchema, setDisplayedSchema] = useState(getSchemaByKey(schema, initialSection));
const [displayedSchemaUi, setDisplayedSchemaUi] = useState(getUiSchemaByKey(uiSchema, initialSection)); const [displayedSchemaUi, setDisplayedSchemaUi] = useState(getUiSchemaByKey(uiSchema, initialSection));
const [localFormData , setLocalFormData] = useState(formData[initialSection]);
let varLocalFormData = formData[initialSection];
useEffect(() => {
varLocalFormData = localFormData;
}, [localFormData]);
useEffect(() => {
console.log('setSection selectedSection:'+selectedSection);
setLocalFormData(formData[selectedSection]);
setDisplayedSchema(getSchemaByKey(schema, selectedSection));
setDisplayedSchemaUi(getUiSchemaByKey(uiSchema, selectedSection));
setLocalFormData(formData[selectedSection]);
}, [selectedSection])
const onInnerDataChange = (innerData) => { const onInnerDataChange = (innerData) => {
console.log(innerData); console.log('onInnerDataChange is called, section:'+selectedSection);
formData[selectedSection] = innerData.formData; formData[selectedSection] = innerData.formData;
onChange({formData: formData}); onChange({formData: innerData.formData});
} }
const setSection = (sectionKey) => { const setSection = (sectionKey) => {
console.log(sectionKey); console.log('setSection is called with:'+sectionKey);
setSelectedSection(sectionKey); setSelectedSection(sectionKey);
setDisplayedSchema(getSchemaByKey(schema, sectionKey));
setDisplayedSchemaUi(getUiSchemaByKey(uiSchema, sectionKey));
} }
const renderNav = () => { const renderNav = () => {
@ -53,13 +66,12 @@ export default function PropagationConfig(props) {
</Nav>) </Nav>)
} }
console.log(displayedSchemaUi)
return (<div> return (<div>
{renderNav()} {renderNav()}
<Form schema={displayedSchema} <Form schema={displayedSchema}
uiSchema={displayedSchemaUi} uiSchema={displayedSchemaUi}
formData={formData[selectedSection]} formData={varLocalFormData}
onChange={onInnerDataChange} onChange={onInnerDataChange}
customFormats={customFormats} customFormats={customFormats}
className={className} className={className}