Skip to content

Commit

Permalink
added all the changes requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmin2 committed Apr 12, 2024
1 parent 2ceb3c6 commit dadc00d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
18 changes: 10 additions & 8 deletions packages/ui/components/VisualEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react';
import SchemaObject from './VisualEditor/SchemaObject';
import _ from 'lodash';
import { getColorForType } from './VisualEditor/SchemaProperty';

interface VisualEditorProps {
schema: string;
Expand All @@ -15,14 +16,7 @@ interface SchemaObjectInterface {
}

export const VisualEditor: React.FC<VisualEditorProps> = ({ schema, onSchemaChange }) => {
const selectStyle = {
backgroundColor: '#0F172A',
color: 'blue',
borderRadius: '3px',
fontSize: '12px',
fontFamily: 'Inter, sans-serif'
};


const [schemaObject, setSchemaObject] = useState<SchemaObjectInterface>({});

useEffect(() => {
Expand All @@ -43,6 +37,14 @@ export const VisualEditor: React.FC<VisualEditorProps> = ({ schema, onSchemaChan
onSchemaChange(newSchemaString);
};

const selectStyle = {
backgroundColor: '#0F172A',
color: getColorForType(schemaObject.type || 'white', schemaObject.items?.type || 'red'),
borderRadius: '3px',
fontSize: '12px',
fontFamily: 'Inter, sans-serif'
};

const renderRootTypeSelector = () => (
<div>
<select
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/components/VisualEditor/SchemaObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({
const normalizedPath = fullPath.startsWith('.') ? fullPath.slice(1) : fullPath;
console.log('Normalised path',normalizedPath);
_.set(updatedSchema, normalizedPath, propertySchema);

console.log(`Property added at ${normalizedPath}`, updatedSchema);
onSchemaChange(updatedSchema);
};

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

Expand Down
29 changes: 19 additions & 10 deletions packages/ui/components/VisualEditor/SchemaProperty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,25 @@ const SchemaProperty: React.FC<SchemaPropertyProps> = ({
const renderArrayItemsProperties = () => {
if (schema.type === 'array' && schema.items && schema.items.type === 'object') {
return (
<SchemaObject
schema={schema.items}
onSchemaChange={(newItemsSchema) => {
const updatedSchema = { ...schema, items: newItemsSchema };
onTypeChange(path, name, updatedSchema);
//Need to updated schema from local schema
}}
path={''}
level={level + 1}
/>
<div>
<strong style={{ marginLeft: `${level * 20 + 20}px` }} className='text-sm'>Array Items</strong>
{_.map(schema.items.properties, (nestedSchema, nestedName) => (
<SchemaProperty
key={nestedName}
name={nestedName}
schema={nestedSchema}
onRemove={onRemove}
onToggleRequired={onToggleNestedRequired}
isRequired={_.includes(schema.items.required, nestedName)}
onTypeChange={onTypeChange}
onAddNestedProperty={onAddNestedProperty}
onRemoveNestedProperty={onRemoveNestedProperty}
onToggleNestedRequired={onToggleNestedRequired}
path={`${path}.items.properties.${nestedName}`}
level={level + 1}
/>
))}
</div>
);
}
return null;
Expand Down

0 comments on commit dadc00d

Please sign in to comment.