Skip to content

Commit

Permalink
Merge branch 'master' into doc/introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
KhudaDad414 authored Mar 26, 2024
2 parents c1f6de5 + 791dec5 commit ccbb96c
Show file tree
Hide file tree
Showing 14 changed files with 878 additions and 55 deletions.
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)}
/>
);

2 changes: 1 addition & 1 deletion apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"devDependencies": {
"@asyncapi/dotnet-nats-template": "^0.12.1",
"@asyncapi/go-watermill-template": "^0.2.72",
"@asyncapi/html-template": "^2.2.1",
"@asyncapi/html-template": "^2.2.2",
"@asyncapi/java-spring-cloud-stream-template": "^0.13.4",
"@asyncapi/java-spring-template": "^1.5.1",
"@asyncapi/java-template": "^0.2.1",
Expand Down
Loading

0 comments on commit ccbb96c

Please sign in to comment.