Skip to content

Commit

Permalink
added three more examples and resolved some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmin2 committed May 30, 2024
1 parent 67d41dd commit 7b4fb9d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,39 @@ export const NesteadArray = () => (
/>
);

export const Blank_schema = () => (
<Template
initialSchema={JSON.stringify(
{}, null, 2)}
/>
);

export const Root_string = () => (
<Template
initialSchema={JSON.stringify(
{
"type": "string"
}, null, 2)}
/>
);

export const Multiple_data_types = () => (
<Template
initialSchema={JSON.stringify(
{
type: "object",
properties: {
mixedTypeProperty: {
type: ["boolean", "integer"],
},
},
required: ["mixedTypeProperty"],
},
null,
2
)}
/>
);


export default VisualEditorStory
12 changes: 10 additions & 2 deletions packages/ui/components/VisualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ export const VisualEditor: React.FC<VisualEditorProps> = ({ schema, onSchemaChan
}, [schema]);

const handleSchemaChange = (updatedPart: any) => {
const updatedSchema = { ...schemaObject, ...updatedPart };
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)
} else {
updatedSchema = { ...schemaObject, ...updatedPart };
}
const newSchemaString = JSON.stringify(updatedSchema);
console.log('Schema updated:', newSchemaString);
setSchemaObject(updatedSchema);
Expand Down Expand Up @@ -149,7 +157,7 @@ export const VisualEditor: React.FC<VisualEditorProps> = ({ schema, onSchemaChan
/>
)}
</div>
{(schemaObject.type === "object" || schemaObject.type === "array") && (
{(schemaObject.type === "object" || (schemaObject.type === "array" && schemaObject.items.type === "object")) && (
<SchemaObject
schema={
schemaObject.type === "array" ? schemaObject.items : schemaObject
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/components/VisualEditor/SchemaObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({
const updatedSchema = _.cloneDeep(schema);
const normalizedPath = fullPath.startsWith('.') ? fullPath.slice(1) : fullPath;

if (normalizedPath.startsWith('items.properties')) {
const itemsPath = normalizedPath.split('.properties')[0];
const propertyName = normalizedPath.split('.').pop();
if (normalizedPath === 'items' || normalizedPath.startsWith('items.properties')) {
console.log("normalized path", normalizedPath)
const itemsPath = normalizedPath === 'items' ? normalizedPath : normalizedPath.split('.properties')[0];
const propertyName = normalizedPath === 'items' ? '' : normalizedPath.split('.').pop();
_.set(updatedSchema, `${itemsPath}.properties.${propertyName}`, propertySchema);
} else {
_.set(updatedSchema, normalizedPath, propertySchema);
Expand Down Expand Up @@ -57,6 +58,7 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({
const itemsPath = `${normalizedPath}.items`;
_.unset(currentSchema, itemsPath);
}
_.unset(currentSchema, `${normalizedPath}.properties`)

console.log(`Type changed at ${propertyPath}`, newSchema);
onSchemaChange(currentSchema);
Expand Down

0 comments on commit 7b4fb9d

Please sign in to comment.