Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into bugfixes-restart
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshibobade21 committed Aug 8, 2024
2 parents 14421c0 + 949ed90 commit 756dd98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
55 changes: 24 additions & 31 deletions src/renderer/components/common/JsonForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,47 +105,40 @@ const conditionalSchema = (schema: any, formData: any, prop: any): boolean=> {
return false;
}

const getDefaultFormData = (schema: any, formData: any) => {
if (schema && schema.properties) {
const defaultFormData = { ...formData };
Object.keys(schema.properties).forEach((property) => {
if (schema.properties[property].type && schema.properties[property].default !== undefined || schema.properties[property].type === 'object') {
// If the property is an object, recursively set default values
if (schema.properties[property].type === 'object') {
defaultFormData[property] = getDefaultFormData(
schema.properties[property],
defaultFormData[property] || {}
);
} else {
defaultFormData[property] = schema.properties[property].default;
}
}
});
return defaultFormData;
}
return null;
};

export default function JsonForm(props: any) {
const {schema, onChange, formData} = props;

const isFormDataEmpty = formData === null || formData === undefined;

useEffect(() => {
if (isFormDataEmpty) {
const defaultFormData = getDefaultFormData(schema, formData);
onChange(defaultFormData);
}
}, [isFormDataEmpty, schema, onChange]);

const getDefaultFormData = (schema: any, formData: any) => {
if (schema && schema.properties) {
const defaultFormData = { ...formData };
Object.keys(schema.properties).forEach((property) => {
if (schema.properties[property].type && schema.properties[property].default !== undefined || schema.properties[property].type === 'object') {
// If the property is an object, recursively set default values
if (schema.properties[property].type === 'object') {
defaultFormData[property] = getDefaultFormData(
schema.properties[property],
defaultFormData[property] || {}
);
} else {
defaultFormData[property] = schema.properties[property].default;
}
}
});
return defaultFormData;
}
return null;
};
const isFormDataEmpty = formData === null || formData === undefined || Object.keys(formData).length < 1;

// const [formState, setFormState] = useState(isFormDataEmpty ? getDefaultFormData(schema, {}) : formData);
const formDataToUse = isFormDataEmpty ? getDefaultFormData(schema, {}) : formData;

return (
<ThemeProvider theme={jsonFormTheme}>
<JsonForms
schema={schema}
uischema={makeUISchema(schema, '/', formData)}
data={formData}
data={formDataToUse}
renderers={materialRenderers}
cells={materialCells}
config={{showUnfocusedDescription: true}}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/stages/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Security = () => {
const [schema, setLocalSchema] = useState(useAppSelector(selectSchema));
const [yaml, setLocalYaml] = useState(useAppSelector(selectYaml));
const [setupSchema] = useState(schema?.properties?.zowe?.properties?.setup?.properties?.security);
const [setupYaml, setSetupYaml] = useState(yaml?.zowe?.setup?.security ?? {product: 'RACF'});
const [setupYaml, setSetupYaml] = useState(yaml?.zowe?.setup?.security);
const [showProgress, setShowProgress] = useState(getProgress('securityStatus'));
const [init, setInit] = useState(false);
const [editorVisible, setEditorVisible] = useState(false);
Expand Down Expand Up @@ -213,7 +213,7 @@ const Security = () => {
}

const handleFormChange = (data: any) => {
let newData = init ? (Object.keys(setupYaml).length > 0 ? setupYaml : data?.zowe?.setup?.security) : (data?.zowe?.setup?.security ? data?.zowe?.setup?.security : data);
let newData = (init && setupYaml) ? (Object.keys(setupYaml).length > 0 ? setupYaml : data?.zowe?.setup?.security) : (data?.zowe?.setup?.security ? data?.zowe?.setup?.security : data);
setInit(false);

if (newData) {
Expand Down

0 comments on commit 756dd98

Please sign in to comment.