Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Visual JSON Schema Editor #905

Merged
merged 43 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f19fa19
initial draft
princerajpoot20 Dec 18, 2023
1f8e1ab
initial draft
princerajpoot20 Dec 18, 2023
7ecddd3
fix sonar
princerajpoot20 Dec 18, 2023
f8d508a
minor changes
princerajpoot20 Dec 18, 2023
2af3257
fix build failed
princerajpoot20 Dec 18, 2023
f74b64d
fix build failed
princerajpoot20 Dec 18, 2023
45ff88e
refractor visual editor
princerajpoot20 Jan 8, 2024
3ba5c1c
added property control
princerajpoot20 Jan 8, 2024
660d5e0
refractor schema
princerajpoot20 Jan 8, 2024
b2b82cc
refractor
princerajpoot20 Jan 8, 2024
dc3fff3
added more sample schema
princerajpoot20 Jan 9, 2024
b2a619c
updated codeeditor
princerajpoot20 Jan 9, 2024
7a4da48
Reverting changes that were made by mistake.
princerajpoot20 Jan 9, 2024
bf9f8e9
fix: add property for nestead object
princerajpoot20 Jan 16, 2024
9892384
fix: fixed add property for object
princerajpoot20 Jan 19, 2024
6bad462
fix error for stories
princerajpoot20 Jan 30, 2024
3283fd3
fix: resolved error causing the build to fail
princerajpoot20 Jan 30, 2024
03cd901
ui changes
princerajpoot20 Jan 31, 2024
326420c
ui changes
princerajpoot20 Feb 5, 2024
5411b46
lint fix
princerajpoot20 Feb 11, 2024
0601679
ui changes
princerajpoot20 Feb 11, 2024
882b39d
added required/notRequired icon
princerajpoot20 Feb 14, 2024
405654a
lint fix
princerajpoot20 Feb 14, 2024
b8d7924
fixed required/notRrquired function
princerajpoot20 Feb 14, 2024
bde3692
Merge branch 'master' into message-schema
Amzani Feb 16, 2024
2221583
type error fix
princerajpoot20 Feb 16, 2024
9bef247
Added a field to test toggle required in simple object schema
princerajpoot20 Feb 26, 2024
34f2a9d
git conflict
princerajpoot20 Feb 26, 2024
607c82e
fix add property feature. used lodash liberary in this
princerajpoot20 Mar 1, 2024
fc80583
fix sample json schema having extra bracket at items
princerajpoot20 Mar 8, 2024
8cbaeaf
fix type error
princerajpoot20 Mar 14, 2024
9aec265
Resolve merge conflicts
princerajpoot20 Mar 14, 2024
0f3f65e
fix package-lock.json file after merge conflict
princerajpoot20 Mar 14, 2024
631adf1
added trash icon
princerajpoot20 Mar 14, 2024
88f1e66
align icon to right
princerajpoot20 Mar 14, 2024
63d427d
lint fix
princerajpoot20 Mar 14, 2024
9e457c1
lint fix
princerajpoot20 Mar 14, 2024
62ef4ec
organized files
princerajpoot20 Mar 14, 2024
5a22d95
sonar fix
princerajpoot20 Mar 14, 2024
2142359
Merge branch 'master' into message-schema
Amzani Mar 15, 2024
7e0a2de
Merge branch 'master' into message-schema
princerajpoot20 Mar 15, 2024
e6ea90b
Resolved merge conflicts
princerajpoot20 Mar 25, 2024
343fd5b
Merge branch 'master' into message-schema
Amzani Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 284 additions & 0 deletions apps/design-system/src/components/VisualJsonSchemaEditor.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
import React, { useState } from 'react';
import { VisualEditor, CodeEditor, Examples } from '@asyncapi/studio-ui';

export default {

Check warning on line 4 in apps/design-system/src/components/VisualJsonSchemaEditor.stories.tsx

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Assign object to a variable before exporting as module default

Check warning on line 4 in apps/design-system/src/components/VisualJsonSchemaEditor.stories.tsx

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - macos-latest

Assign object to a variable before exporting as module default
component: VisualEditor,
parameters: {
layout: 'fullscreen',
},
};
type TemplateProps = {
initialSchema: string;
};

const Template: React.FC<TemplateProps> = ({ initialSchema }) => {
const [schema, setSchema] = useState<string>(initialSchema);
const [editorType, setEditorType] = useState<'visual' | 'code' | 'examples'>('visual');


return (
<div>
<div style={{ width: '45vw', minWidth:'550px', background: '#0F172A', color: '#CBD5E1', fontFamily: 'Inter, sans-serif' }}>
<button style={{padding: 5}} onClick={() => setEditorType('visual')}>Visual Editor </button>
<button style={{padding: 5}} onClick={() => setEditorType('code')}>Code Editor </button>
<button style={{padding: 5}} onClick={() => setEditorType('examples')}>Examples </button>
</div>
<div>
{editorType === 'visual' && (
<VisualEditor schema={schema} onSchemaChange={setSchema} />
)}
{editorType === 'code' && (
<CodeEditor schema={schema} onSchemaChange={setSchema} />
)}
{editorType === 'examples' && (
<Examples/>
)}
</div>
</div>
);
};

export const Sample_Schema = () => (
<Template
initialSchema={JSON.stringify({
"type": "object",
"properties": {

"age": {
"type": "integer"
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
},
"pincode":{
"type": "number"
}
},
"required": [
"street",
"city"
]
}
}
}, null, 2)}
/>
);

export const Schema_with_array_object = () => (
<Template
initialSchema={JSON.stringify({
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"type": "boolean"
},
"height": {
"type": ["integer", "null"]
},
"friends": {
"type": "array",
"items": {
"type": "object",
"properties": {
"firstName": {
"type": "string"
}
},
"required": ["firstName"]
}
}
},
"required": ["firstName", "lastName"]
}
, null, 2)}
/>
);

export const WithArray_obj = () => (
<Template
initialSchema={JSON.stringify({
"type": "object",
"properties": {
"books": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"author": {
"type": "string"
}
}
}
}
}
}, null, 2)}
/>
);

export const WithArray_obj_and_obj = () => (
<Template
initialSchema={JSON.stringify({
"type": "object",
"properties": {
"books": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"author": {"type": "string"}
},
"required": ["title"]
}
},
"list": {
"type": "object",
"properties": {
"hii": {"type": "string"}
}
}
},
"required": ["books", "list"]
}, null, 2)}
/>
);

export const Array_of_string = () => (
<Template
initialSchema={JSON.stringify({
"type": "object",
"properties": {
"numbers": {
"type": "array",
"items": {
"type": "number"
}
},
"aString": {
"type": "string"
},
"aNumber": {
"type": "number"
}
},
"required": ["numbers", "aString", "aNumber"]
}, null, 2)}
/>
);

export const Root_Array_of_Object = () => (
<Template
initialSchema={JSON.stringify({
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"isActive": {
"type": "boolean"
}
},
"required": ["id", "name"]
}
}, null, 2)}
/>
);

export const two_property_having_same_name = () => (
<Template
initialSchema={JSON.stringify({

"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"address": { "type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" }
}
}
}
}
}
}

, null, 2)}
/>
);

export const nestead_array = () => (
<Template
initialSchema={JSON.stringify(
{
"type": "object",
"properties": {
"age": {
"type": "integer"
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
},
"pincode": {
"type": "number"
},
"contact_number": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"mobile":{
"type": "stirng"
},
"address": {
"type": "object",
"properties":{
"city":{
"type": "string"
}
}
}
}
}
}
},
"required": [
"street",
"city"
]
}
}
}, null, 2)}
/>
);

3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-yaml": "^6.0.0",
"@codemirror/language": "^6.10.1",
"@codemirror/theme-one-dark": "^6.1.2"
"@codemirror/theme-one-dark": "^6.1.2",
"lodash": "^4.17.21"
}
}
Loading
Loading