Skip to content

Commit

Permalink
feat: add organization-config json-schema configuration to the CodeEd…
Browse files Browse the repository at this point in the history
…itor component
  • Loading branch information
marcomontalbano committed Nov 11, 2024
1 parent 6e604b0 commit e5033d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface CodeEditorProps
* JSON Schema to be used when writing JSON
* @default none
*/
jsonSchema?: 'none' | 'order-rules' | 'price-rules'
jsonSchema?: 'none' | 'order-rules' | 'price-rules' | 'organization-config'
/**
* Trigger on every update.
* @param markers List of markers (errors). `null` when there're no errors.
Expand Down Expand Up @@ -116,6 +116,23 @@ export const CodeEditor = forwardRef<HTMLInputElement, CodeEditorProps>(
break
}

case 'organization-config': {
console.log('here', jsonSchema, uri)
schemas.push({
schema: await fetch(
'https://provisioning.commercelayer.io/api/public/schemas/organization_config'
)
.then<JsonValue>(async (res) => await res.json())
.then((json) => {
return clearExamples(json)
}),
uri: `file:///json-schema--${jsonSchema}.json`,
fileMatch: [uri]
})

break
}

case 'order-rules': {
schemas.push({
schema: await fetch(
Expand Down
18 changes: 18 additions & 0 deletions packages/docs/src/stories/forms/ui/CodeEditor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ PriceListRules.args = {
).concat('\n')
}

export const OrganizationConfig = Template.bind({})
OrganizationConfig.args = {
name: 'organization-config',
label: 'Configuration',
height: '600px',
onChange: (value) => {
console.log('organization config • Changed to:', value)
},
onValidate: (markers) => {
console.log('organization config • Markers:', markers)
},
language: 'json',
jsonSchema: 'organization-config',
defaultValue: JSON.stringify({ mfe: { default: {} } }, undefined, 2).concat(
'\n'
)
}

export const WithHint = Template.bind({})
WithHint.args = {
name: 'code-editor-hint',
Expand Down

0 comments on commit e5033d8

Please sign in to comment.