Skip to content

Commit

Permalink
updating the jsonforms
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshibobade21 committed Aug 14, 2024
1 parent b95bf39 commit c916384
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
47 changes: 19 additions & 28 deletions src/renderer/components/common/JsonForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,12 @@ export default function JsonForm(props: any) {
let requiredSchema = schema;
const isFormDataEmpty = formData === null || formData === undefined || Object.keys(formData).length < 1;

// const [reqSchema, setReqSchema] = useState(schema);
// const [reqFormData, setReqFormData] = useState(isFormDataEmpty ? getDefaultFormData(schema, {}) : formData);
const [selectedSchemaIndex, setSelectedSchemaIndex] = useState(0);
let formDataToUse = isFormDataEmpty ? getDefaultFormData(schema, {}) : formData;

useEffect(() => {
if (schema?.oneOf) {
const initialSchemaIndex = handleOneOfSchema(schema, formData);
// setSelectedSchemaIndex(initialSchemaIndex);
// setReqSchema(schema.oneOf[initialSchemaIndex]);
// setReqFormData(filterFormData(formData, schema.oneOf[initialSchemaIndex]));

requiredSchema = schema.oneOf[initialSchemaIndex];
formDataToUse = filterFormData(formData, requiredSchema);
}
Expand All @@ -197,9 +191,6 @@ export default function JsonForm(props: any) {
const handleSchemaChange = (event: any) => {
const schemaIndex = parseInt(event.target.value);
setSelectedSchemaIndex(schemaIndex);
// setReqSchema(schema.oneOf[schemaIndex]);
// setReqFormData(filterFormData(formData, schema.oneOf[schemaIndex]));

requiredSchema = schema.oneOf[schemaIndex];
formDataToUse = (filterFormData(formData, schema.oneOf[schemaIndex]));
}
Expand All @@ -209,29 +200,29 @@ export default function JsonForm(props: any) {
{ schema.oneOf &&
<div>
<FormControl>
<RadioGroup
row
name="controlled-radio-buttons-group"
value={selectedSchemaIndex}
onChange={handleSchemaChange}
>
{ schema.oneOf.map((_: any, index: number) => (
<FormControlLabel key={index} value={index} control={<Radio />} label={`Certificate ${index}`} />
))}
</RadioGroup>
<RadioGroup
row
name="controlled-radio-buttons-group"
value={selectedSchemaIndex}
onChange={handleSchemaChange}
>
{ schema.oneOf.map((_: any, index: number) => (
<FormControlLabel key={index} value={index} control={<Radio />} label={`Certificate ${index}`} />
))}
</RadioGroup>
</FormControl>
</div>

}
<JsonForms
schema={requiredSchema}
uischema={makeUISchema(schema, '/', formData)}
data={formDataToUse}
renderers={materialRenderers}
cells={materialCells}
config={{showUnfocusedDescription: true}}
onChange={({ data, errors }) => { onChange(data) }}
/>
<JsonForms
schema={requiredSchema}
uischema={makeUISchema(requiredSchema, '/', formDataToUse)}
data={formDataToUse}
renderers={materialRenderers}
cells={materialCells}
config={{showUnfocusedDescription: true}}
onChange={({ data, errors }) => { onChange(data) }}
/>
</ThemeProvider>
);
}
9 changes: 9 additions & 0 deletions src/services/ResolveRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export const updateSchemaReferences = (schema: any, serverCommon: any): void =>
} catch(error){
console.error("Error resolving reference:", error.message);
}
} else if (key === "pattern" && typeof node[key] === "string") {
// Sanitize pattern for use in RegExp
try {
new RegExp(node[key]);
console.log("trying----------------------------------------------------");
} catch (error) {
console.error("Invalid regular expression pattern:", node[key]);
continue;
}
} else {
traverseAndUpdate(node[key]);
}
Expand Down

0 comments on commit c916384

Please sign in to comment.