Skip to content

Commit

Permalink
corrected all the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmin2 committed Jun 2, 2024
1 parent 7b4fb9d commit a08b46d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
28 changes: 22 additions & 6 deletions packages/ui/components/VisualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,31 @@ export const VisualEditor: React.FC<VisualEditorProps> = ({ schema, onSchemaChan
}, [schema]);

const handleSchemaChange = (updatedPart: any) => {
let updatedSchema
if(schemaObject.type == "array" && schemaObject.items.type === "object") {
updatedSchema = {...schemaObject, items: {...schemaObject.items, ...updatedPart} }
updatedSchema.items.properties = {...updatedSchema.items.properties, ...updatedPart.items.properties }
console.log("updatedSchemaaa",updatedSchema)
console.log("updatedPartss",updatedPart)
let updatedSchema = _.cloneDeep(schemaObject);
console.log("updatedPart.type", updatedPart.type)

if (updatedSchema.type === 'array') {
if (updatedPart.items && updatedPart.items.type === 'object') {
updatedSchema.items = updatedPart.items;
} else if (updatedPart?.items?.properties) {
updatedSchema.items = {
...updatedSchema.items,
properties: {
...updatedSchema.items.properties,
...updatedPart.items.properties,
},
};
} else if (updatedPart.type !== 'object' ) {
updatedSchema = { ...schemaObject, ...updatedPart };
} else if (Object.keys(updatedPart.properties).length === 0 && updatedPart?.required === undefined){
updatedSchema = { ...schemaObject, ...updatedPart };
} else {
updatedSchema.items = { ...updatedSchema.items, ...updatedPart };
}
} else {
updatedSchema = { ...schemaObject, ...updatedPart };
}

const newSchemaString = JSON.stringify(updatedSchema);
console.log('Schema updated:', newSchemaString);
setSchemaObject(updatedSchema);
Expand Down
15 changes: 13 additions & 2 deletions packages/ui/components/VisualEditor/SchemaObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({

const handleRemoveProperty = (propertyPath: string) => {
const updatedSchema = _.cloneDeep(schema);
const normalizedPath = propertyPath.startsWith('.') ? propertyPath.slice(1) : propertyPath;
_.unset(updatedSchema, normalizedPath);
const normalizedPath = propertyPath.startsWith(".")
? propertyPath.slice(1)
: propertyPath;
console.log("normalized path", normalizedPath)

if (normalizedPath.startsWith('items.properties')) {
const path = normalizedPath.split(".").slice(1).join(".");
console.log("path", path)
_.unset(updatedSchema, path);
} else {
_.unset(updatedSchema, normalizedPath);
}
console.log("updatedSchema", JSON.stringify(updatedSchema))
onSchemaChange(updatedSchema);
};

Expand Down

0 comments on commit a08b46d

Please sign in to comment.