From 44a2441f7a8896fe3b4a7f12bc4a70c6a3747ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Wed, 14 May 2025 08:16:56 +0200 Subject: [PATCH 01/10] 2536 - add a new Note component --- client/.eslintrc | 2 ++ client/src/components/Note.tsx | 24 ++++++++++++++++++++++++ client/src/styles/components.css | 2 ++ client/tailwind.config.js | 4 ++++ 4 files changed, 32 insertions(+) create mode 100644 client/src/components/Note.tsx diff --git a/client/.eslintrc b/client/.eslintrc index d9e5e72243..ff8c523e0d 100644 --- a/client/.eslintrc +++ b/client/.eslintrc @@ -92,6 +92,8 @@ "bg-surface-neutral-secondary-hover", "bg-surface-neutral-tertiary", "bg-surface-popover-canvas", + "bg-surface-warning-primary", + "bg-surface-warning-secondary", "border-accent", "border-content-neutral-tertiary", "border-input", diff --git a/client/src/components/Note.tsx b/client/src/components/Note.tsx new file mode 100644 index 0000000000..01017ff472 --- /dev/null +++ b/client/src/components/Note.tsx @@ -0,0 +1,24 @@ +import {XIcon} from 'lucide-react'; +import {ReactNode} from 'react'; +import {twMerge} from 'tailwind-merge'; + +import {Button} from './ui/button'; + +export const Note = ({content, icon}: {content: string; icon?: ReactNode}) => { + return ( +
+ {icon && icon} + +

{content}

+ + +
+ ); +}; diff --git a/client/src/styles/components.css b/client/src/styles/components.css index c460ed4c71..f95ad9599c 100644 --- a/client/src/styles/components.css +++ b/client/src/styles/components.css @@ -53,6 +53,8 @@ --surface-neutral-secondary-hover: 214 32% 91%; --surface-neutral-tertiary: 214 32% 91%; --surface-popover-canvas: 210 40% 98%; + --surface-warning-primary: 48, 96%, 53%; + --surface-warning-secondary: 55, 92%, 95%; --content-brand-primary: 217 91% 40%; --content-destructive: 0 74% 42%; --content-neutral-primary: 229 84% 5%; diff --git a/client/tailwind.config.js b/client/tailwind.config.js index 6bf9f394eb..a2ae49479f 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -134,6 +134,10 @@ module.exports = { popover: { canvas: 'hsl(var(--surface-popover-canvas))', }, + warning: { + primary: 'hsl(var(--surface-warning-primary))', + secondary: 'hsl(var(--surface-warning-secondary))', + }, }, }, height: { From 2fe08d3755dc3f74f765e5deb95fb47550014101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Wed, 14 May 2025 08:17:18 +0200 Subject: [PATCH 02/10] 2536 - JSON Schema Builder - move small components around --- .../components/SchemaAddButton.tsx | 22 ------------ .../components/SchemaBox.tsx | 7 ---- .../components/SchemaCheckbox.tsx | 27 -------------- .../components/SchemaCloseButton.tsx | 19 ---------- .../components/SchemaCollapseButton.tsx | 20 ----------- .../components/SchemaControls.tsx | 35 ++++++++++++++++--- .../components/SchemaCreator.tsx | 10 ++++-- .../components/SchemaMenu.tsx | 2 +- .../components/SchemaMenuButton.tsx | 19 ---------- .../components/SchemaMenuItem.tsx | 25 ++++++++++++- .../PropertyJsonSchemaBuilderSheet.tsx | 13 +++++-- 11 files changed, 73 insertions(+), 126 deletions(-) delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaAddButton.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaBox.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaCheckbox.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaCloseButton.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaCollapseButton.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenuButton.tsx diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaAddButton.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaAddButton.tsx deleted file mode 100755 index b78a6af28d..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaAddButton.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import {PlusIcon} from 'lucide-react'; - -import SchemaRoundedButton from './SchemaRoundedButton'; - -interface AddButtonProps { - onClick?: () => void; - title?: string; -} - -const SchemaAddButton = ({onClick = () => {}, title}: AddButtonProps) => { - return ( - - - - ); -}; - -export default SchemaAddButton; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaBox.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaBox.tsx deleted file mode 100755 index 1e8b124e87..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaBox.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React, {PropsWithChildren} from 'react'; - -const SchemaBox = ({children}: PropsWithChildren) => { - return
{children}
; -}; - -export default SchemaBox; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCheckbox.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCheckbox.tsx deleted file mode 100755 index 08cd9eb932..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCheckbox.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import {Label} from '@/components/ui/label'; -import {Toggle} from '@/components/ui/toggle'; -import React from 'react'; - -const handleChange = (handler: (value: boolean) => void) => { - return (event: React.FormEvent): void => { - handler((event.target as HTMLInputElement).checked); - }; -}; - -interface SchemaCheckboxProps { - value: boolean; - onChange: (v: boolean) => void; - label?: string; -} - -const SchemaCheckbox = ({label, onChange, value}: SchemaCheckboxProps) => { - return ( -
- - - -
- ); -}; - -export default SchemaCheckbox; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCloseButton.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCloseButton.tsx deleted file mode 100755 index 4f3338ca28..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCloseButton.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import {XIcon} from 'lucide-react'; -import React from 'react'; - -import SchemaRoundedButton from './SchemaRoundedButton'; - -interface CloseButtonProps { - onClick?: () => void; - title?: string; -} - -const SchemaCloseButton = ({onClick = () => {}, title}: CloseButtonProps) => { - return ( - - - - ); -}; - -export default SchemaCloseButton; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCollapseButton.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCollapseButton.tsx deleted file mode 100755 index d6dfaeb6fe..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCollapseButton.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import {ChevronRightIcon} from '@radix-ui/react-icons'; -import {ChevronDownIcon} from 'lucide-react'; - -import SchemaRoundedButton from './SchemaRoundedButton'; - -interface CollapseButtonProps { - onClick?: () => void; - isCollapsed?: boolean; - title?: string; -} - -const SchemaCollapseButton = ({isCollapsed = false, onClick = () => {}, title}: CollapseButtonProps) => { - return ( - - {isCollapsed ? : } - - ); -}; - -export default SchemaCollapseButton; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index 67e6f4eb67..abd742f70e 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -1,16 +1,15 @@ -import SchemaAddButton from '@/components/JsonSchemaBuilder/components/SchemaAddButton'; -import SchemaCollapseButton from '@/components/JsonSchemaBuilder/components/SchemaCollapseButton'; import SchemaDeleteButton from '@/components/JsonSchemaBuilder/components/SchemaDeleteButton'; import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; import SchemaMenu from '@/components/JsonSchemaBuilder/components/SchemaMenu'; -import SchemaMenuButton from '@/components/JsonSchemaBuilder/components/SchemaMenuButton'; import SchemaMenuModal from '@/components/JsonSchemaBuilder/components/SchemaMenuModal'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; -import React, {useState} from 'react'; +import {ChevronDownIcon, ChevronRightIcon, EllipsisVerticalIcon, PlusIcon} from 'lucide-react'; +import {useState} from 'react'; import {useTranslation} from 'react-i18next'; import * as helpers from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; +import SchemaRoundedButton from './SchemaRoundedButton'; interface SchemaControlsProps { schema: SchemaRecordType; @@ -110,3 +109,31 @@ export const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayContro ); }; + +const SchemaMenuButton = ({onClick = () => {}, title}: {onClick?: () => void; title?: string}) => ( + + + +); + +const SchemaAddButton = ({onClick = () => {}, title}: {onClick?: () => void; title?: string}) => ( + + + +); + +interface CollapseButtonProps { + onClick?: () => void; + isCollapsed?: boolean; + title?: string; +} + +const SchemaCollapseButton = ({isCollapsed = false, onClick = () => {}, title}: CollapseButtonProps) => ( + + {isCollapsed ? : } + +); diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx index cd3b49483f..7db68f1943 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx @@ -1,6 +1,6 @@ -import SchemaBox from '@/components/JsonSchemaBuilder/components/SchemaBox'; import {AsteriskIcon} from 'lucide-react'; -import React, {useState} from 'react'; +import {PropsWithChildren, useState} from 'react'; +import {twMerge} from 'tailwind-merge'; import { addSchemaProperty, @@ -56,7 +56,7 @@ const SchemaCreator = ({ /> -
+
{isSchemaObject(schema) && hasSchemaProperties(schema) && ( ( +
{children}
+); diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx index 64402f2e00..634226c462 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx @@ -1,4 +1,4 @@ -import React, {useMemo} from 'react'; +import {useMemo} from 'react'; import {useTranslation} from 'react-i18next'; import Select from 'react-select'; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenuButton.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenuButton.tsx deleted file mode 100755 index ea931cd3fe..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenuButton.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import {EllipsisVerticalIcon} from 'lucide-react'; -import React from 'react'; - -import SchemaRoundedButton from './SchemaRoundedButton'; - -interface MenuButtonProps { - onClick?: () => void; - title?: string; -} - -const SchemaMenuButton = ({onClick = () => {}, title}: MenuButtonProps) => { - return ( - - - - ); -}; - -export default SchemaMenuButton; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx index 8031037bb2..8615b66b16 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx @@ -1,4 +1,3 @@ -import SchemaCheckbox from '@/components/JsonSchemaBuilder/components/SchemaCheckbox'; import SchemaDeleteButton from '@/components/JsonSchemaBuilder/components/SchemaDeleteButton'; import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; import {Label} from '@/components/ui/label'; @@ -24,6 +23,8 @@ import {SchemaMenuOptionType, SchemaRecordType} from '../utils/types'; import '../../CreatableSelect/CreatableSelect.css'; +import {Toggle} from '@/components/ui/toggle'; + interface ItemProps { onDelete: () => void; children: React.ReactNode; @@ -182,3 +183,25 @@ export const RequiredMultiSelectItem: React.FunctionComponent = ( ); }; + +interface SchemaCheckboxProps { + value: boolean; + onChange: (value: boolean) => void; + label?: string; +} + +const SchemaCheckbox = ({label, onChange, value}: SchemaCheckboxProps) => { + const handleChange = + (handler: (value: boolean) => void) => + (event: React.FormEvent): void => { + handler((event.target as HTMLInputElement).checked); + }; + + return ( +
+ + + +
+ ); +}; diff --git a/client/src/pages/platform/workflow-editor/components/properties/components/property-json-schema-builder/PropertyJsonSchemaBuilderSheet.tsx b/client/src/pages/platform/workflow-editor/components/properties/components/property-json-schema-builder/PropertyJsonSchemaBuilderSheet.tsx index 196287eadf..8f15f420a1 100755 --- a/client/src/pages/platform/workflow-editor/components/properties/components/property-json-schema-builder/PropertyJsonSchemaBuilderSheet.tsx +++ b/client/src/pages/platform/workflow-editor/components/properties/components/property-json-schema-builder/PropertyJsonSchemaBuilderSheet.tsx @@ -1,9 +1,11 @@ import JsonSchemaBuilder from '@/components/JsonSchemaBuilder/JsonSchemaBuilder'; import {SchemaRecordType} from '@/components/JsonSchemaBuilder/utils/types'; +import {Note} from '@/components/Note'; import {Sheet, SheetCloseButton, SheetContent, SheetDescription, SheetHeader, SheetTitle} from '@/components/ui/sheet'; import {Tabs, TabsContent, TabsList, TabsTrigger} from '@/components/ui/tabs'; import {SPACE} from '@/shared/constants'; import Editor from '@monaco-editor/react'; +import {MessageCircleQuestionIcon} from 'lucide-react'; import React from 'react'; interface PropertyJsonSchemaBuilderSheetProps { @@ -24,7 +26,7 @@ const PropertyJsonSchemaBuilderSheet = ({locale, onChange, onClose, schema}: Pro
- JSON Schema Builder + Response template Define desired response format for the output
@@ -37,14 +39,19 @@ const PropertyJsonSchemaBuilderSheet = ({locale, onChange, onClose, schema}: Pro Designer - Editor + Code Editor
-
+
+ } + /> + From 78d44ec8abff0c6dbbbf393b5ae54630b206e6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Wed, 14 May 2025 14:40:30 +0200 Subject: [PATCH 03/10] 2536 - JSON Schema Builder - SF --- .../components/SchemaControls.tsx | 136 ++++++++--------- .../components/SchemaDeleteButton.tsx | 18 --- .../components/SchemaInput.tsx | 1 + .../components/SchemaMenu.tsx | 14 +- .../components/SchemaMenuDialog.tsx | 35 +++++ .../components/SchemaMenuItem.tsx | 137 ++++++++---------- .../components/SchemaMenuList.tsx | 16 +- .../components/SchemaMenuModal.tsx | 37 ----- .../components/SchemaRoundedButton.tsx | 26 ---- .../components/SchemaTypesSelect.tsx | 59 ++++---- .../JsonSchemaBuilder/utils/constants.ts | 12 +- 11 files changed, 218 insertions(+), 273 deletions(-) delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaDeleteButton.tsx create mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenuDialog.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenuModal.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaRoundedButton.tsx diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index abd742f70e..9cfcda8b06 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -1,15 +1,13 @@ -import SchemaDeleteButton from '@/components/JsonSchemaBuilder/components/SchemaDeleteButton'; import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; import SchemaMenu from '@/components/JsonSchemaBuilder/components/SchemaMenu'; -import SchemaMenuModal from '@/components/JsonSchemaBuilder/components/SchemaMenuModal'; +import SchemaMenuDialog from '@/components/JsonSchemaBuilder/components/SchemaMenuDialog'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; -import {ChevronDownIcon, ChevronRightIcon, EllipsisVerticalIcon, PlusIcon} from 'lucide-react'; +import {Button} from '@/components/ui/button'; +import {ChevronDownIcon, ChevronRightIcon, CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; import {useState} from 'react'; -import {useTranslation} from 'react-i18next'; import * as helpers from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; -import SchemaRoundedButton from './SchemaRoundedButton'; interface SchemaControlsProps { schema: SchemaRecordType; @@ -34,44 +32,71 @@ export const SchemaControls = ({ }: SchemaControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); - const {t} = useTranslation(); - return ( -
-
+
+
onChange(helpers.setSchemaTitle(title, schema))} - placeholder={t('title')} + placeholder="Title" value={helpers.getSchemaTitle(schema)} /> onChange(helpers.setSchemaTypeAndRemoveWrongFields(t, schema))} + onChange={(translation) => onChange(helpers.setSchemaTypeAndRemoveWrongFields(translation, schema))} type={helpers.getSchemaType(schema)} /> - {typeof onChangeKey === 'function' ? ( - - ) : null} + {typeof onChangeKey === 'function' && ( + + )}
-
- {typeof onCollapse === 'function' ? ( - - ) : null} - - setIsMenuOpen((o) => !o)} title={t('extraOptions')} /> - - {typeof onDelete === 'function' ? : null} - - {typeof onAdd === 'function' ? : null} +
+ {typeof onCollapse === 'function' && ( + + )} + + + + {typeof onDelete === 'function' && ( + + )} + + {typeof onAdd === 'function' && ( + + )}
{isMenuOpen && ( - setIsMenuOpen(false)} title={t('extraFields')}> + setIsMenuOpen(false)} title="Extra fields"> - + )}
); @@ -86,54 +111,35 @@ interface SchemaArrayControlsProps { export const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); - const {t} = useTranslation(); - return (
onChange(helpers.setSchemaTypeAndRemoveWrongFields(t, schema))} + onChange={(value) => onChange(helpers.setSchemaTypeAndRemoveWrongFields(value, schema))} type={helpers.getSchemaType(schema)} />
- setIsMenuOpen((o) => !o)} title={t('extraOptions')} /> - - {typeof onAdd === 'function' ? : null} + + + {typeof onAdd === 'function' && ( + + )}
- {isMenuOpen ? ( - setIsMenuOpen(false)} title={t('extraFields')}> + {isMenuOpen && ( + setIsMenuOpen(false)} title="Extra fields"> - - ) : null} + + )}
); }; - -const SchemaMenuButton = ({onClick = () => {}, title}: {onClick?: () => void; title?: string}) => ( - - - -); - -const SchemaAddButton = ({onClick = () => {}, title}: {onClick?: () => void; title?: string}) => ( - - - -); - -interface CollapseButtonProps { - onClick?: () => void; - isCollapsed?: boolean; - title?: string; -} - -const SchemaCollapseButton = ({isCollapsed = false, onClick = () => {}, title}: CollapseButtonProps) => ( - - {isCollapsed ? : } - -); diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaDeleteButton.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaDeleteButton.tsx deleted file mode 100755 index f3c47afab1..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaDeleteButton.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import {TrashIcon} from 'lucide-react'; - -import SchemaRoundedButton from './SchemaRoundedButton'; - -interface DeleteButtonProps { - onClick?: () => void; - title?: string; -} - -const SchemaDeleteButton = ({onClick = () => {}, title}: DeleteButtonProps) => { - return ( - - - - ); -}; - -export default SchemaDeleteButton; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx index 7b70e19b5d..dfdd59f095 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx @@ -38,6 +38,7 @@ const SchemaInput = ({label, onChange, placeholder, type = 'text', value = ''}: setLocalVal(e.target.value)} onKeyPress={handleEnterPress(onChangeValue)} diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx index 634226c462..26e541f594 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx @@ -14,10 +14,13 @@ interface SchemaMenuProps { } const SchemaMenu = ({onChange, schema}: SchemaMenuProps) => { - const {t} = useTranslation(); + const {t: translation} = useTranslation(); const type = helpers.getSchemaType(schema); - const allOptions = useMemo(() => helpers.translateLabels(t, helpers.getSchemaMenuOptions(type)), [type, t]); + const allOptions = useMemo( + () => helpers.translateLabels(translation, helpers.getSchemaMenuOptions(type)), + [type, translation] + ); const fields = helpers.getAllSchemaKeys(schema); @@ -29,12 +32,11 @@ const SchemaMenu = ({onChange, schema}: SchemaMenuProps) => { t('noOptions')} + noOptionsMessage="No options" // eslint-disable-next-line @typescript-eslint/no-explicit-any onChange={(option: any) => { onChange(setSchemaField(field.value, option.value, schema)); }} options={options} - placeholder={t('options')} + placeholder="Options" value={selected} />
@@ -152,8 +144,6 @@ export const RequiredMultiSelectItem: React.FunctionComponent = ( onChange, schema, }: ItemTypeProps) => { - const {t} = useTranslation(); - if (!isSchemaObject(schema) || !hasSchemaProperties(schema)) { return null; } @@ -164,19 +154,18 @@ export const RequiredMultiSelectItem: React.FunctionComponent = ( return ( onChange(deleteSchemaField(field.value, schema))}>
- + { - onChange(option); - }} - value={helpers.findOption(type)(options)?.value} - > - - - - - - {options.map((option) => ( - - {option.label} - - ))} - - -
- ); -}; +const SchemaTypesSelect = ({onChange, type}: SchemaTypesSelectProps) => ( +
+ + + +
+); export default SchemaTypesSelect; diff --git a/client/src/components/JsonSchemaBuilder/utils/constants.ts b/client/src/components/JsonSchemaBuilder/utils/constants.ts index 3575c7ba4d..1920b2fa23 100755 --- a/client/src/components/JsonSchemaBuilder/utils/constants.ts +++ b/client/src/components/JsonSchemaBuilder/utils/constants.ts @@ -20,27 +20,27 @@ import { export const SCHEMA_TYPES: SchemaTypeOptionType[] = [ { - label: 'schemaTypes.text', + label: 'Text', value: 'string', }, { - label: 'schemaTypes.integer', + label: 'Integer', value: 'integer', }, { - label: 'schemaTypes.decimal', + label: 'Number', value: 'number', }, { - label: 'schemaTypes.boolean', + label: 'Boolean', value: 'boolean', }, { - label: 'schemaTypes.object', + label: 'Object', value: 'object', }, { - label: 'schemaTypes.array', + label: 'Array', value: 'array', }, ]; From 337591400ded0b46155784202467e78986516a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 07:21:11 +0200 Subject: [PATCH 04/10] 2536 - JSON Schema Builder - move collapse trigger --- .../components/SchemaControls.tsx | 25 +-- .../components/SchemaCreator.tsx | 173 +++++++++--------- 2 files changed, 93 insertions(+), 105 deletions(-) diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index 9cfcda8b06..f554b6fdc8 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -3,7 +3,7 @@ import SchemaMenu from '@/components/JsonSchemaBuilder/components/SchemaMenu'; import SchemaMenuDialog from '@/components/JsonSchemaBuilder/components/SchemaMenuDialog'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; import {Button} from '@/components/ui/button'; -import {ChevronDownIcon, ChevronRightIcon, CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; +import {CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; import {useState} from 'react'; import * as helpers from '../utils/helpers'; @@ -20,16 +20,7 @@ interface SchemaControlsProps { onChange: (schema: SchemaRecordType) => void; } -export const SchemaControls = ({ - isCollapsed, - onAdd, - onChange, - onChangeKey, - onCollapse, - onDelete, - schema, - schemakey, -}: SchemaControlsProps) => { +export const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemakey}: SchemaControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); return ( @@ -53,18 +44,6 @@ export const SchemaControls = ({
- {typeof onCollapse === 'function' && ( - - )} - + +
{children}
+
); }; export default SchemaCreator; - -const SchemaBox = ({children}: PropsWithChildren) => ( -
{children}
-); From 4d0a9fa935afedc093caf9853d06c7d7c15166af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 16:14:48 +0200 Subject: [PATCH 05/10] 2536 - improve Note component --- client/src/components/Note.tsx | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/client/src/components/Note.tsx b/client/src/components/Note.tsx index 01017ff472..7ea0994afc 100644 --- a/client/src/components/Note.tsx +++ b/client/src/components/Note.tsx @@ -4,21 +4,14 @@ import {twMerge} from 'tailwind-merge'; import {Button} from './ui/button'; -export const Note = ({content, icon}: {content: string; icon?: ReactNode}) => { - return ( -
- {icon && icon} +export const Note = ({content, icon}: {content: string; icon?: ReactNode}) => ( +
+ {icon && icon} -

{content}

+

{content}

- -
- ); -}; + +
+); From cb76607d654dccf2e48b0b59e9b83e5360cdc01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 16:31:36 +0200 Subject: [PATCH 06/10] 2536 - JSON Schema Builder - set default values and change labels --- .../components/SchemaControls.tsx | 87 +++++++++++------- .../components/SchemaCreator.tsx | 90 +++++++++++-------- .../components/SchemaInput.tsx | 6 +- .../components/SchemaMenu.tsx | 15 ++-- .../components/SchemaMenuDialog.tsx | 10 ++- .../components/SchemaTypesSelect.tsx | 7 +- .../JsonSchemaBuilder/utils/constants.ts | 2 +- 7 files changed, 128 insertions(+), 89 deletions(-) diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index f554b6fdc8..ecb6a93664 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -1,12 +1,17 @@ import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; -import SchemaMenu from '@/components/JsonSchemaBuilder/components/SchemaMenu'; import SchemaMenuDialog from '@/components/JsonSchemaBuilder/components/SchemaMenuDialog'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; import {Button} from '@/components/ui/button'; import {CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; -import {useState} from 'react'; - -import * as helpers from '../utils/helpers'; +import {useEffect, useState} from 'react'; + +import { + addSchemaProperty, + getSchemaTitle, + getSchemaType, + setSchemaTitle, + setSchemaTypeAndRemoveWrongFields, +} from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; interface SchemaControlsProps { @@ -20,26 +25,34 @@ interface SchemaControlsProps { onChange: (schema: SchemaRecordType) => void; } -export const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemakey}: SchemaControlsProps) => { +const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemakey}: SchemaControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); + const isObjectSchema = getSchemaType(schema) === 'object'; + + useEffect(() => { + if (!schema.type || !getSchemaType(schema)) { + onChange(setSchemaTypeAndRemoveWrongFields('object', schema)); + } + }, [schema, onChange]); + return ( -
+
- onChange(helpers.setSchemaTitle(title, schema))} - placeholder="Title" - value={helpers.getSchemaTitle(schema)} + onChange(setSchemaTypeAndRemoveWrongFields(translation, schema))} + type={getSchemaType(schema)} /> - onChange(helpers.setSchemaTypeAndRemoveWrongFields(translation, schema))} - type={helpers.getSchemaType(schema)} + onChange(setSchemaTitle(title, schema))} + placeholder="Untitled Pill" + value={getSchemaTitle(schema)} /> {typeof onChangeKey === 'function' && ( - + )}
@@ -65,39 +78,48 @@ export const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, )} - {typeof onAdd === 'function' && ( - )}
{isMenuOpen && ( - setIsMenuOpen(false)} title="Extra fields"> - - + setIsMenuOpen(false)} + schema={schema} + title="Extra fields" + /> )}
); }; interface SchemaArrayControlsProps { - schema: SchemaRecordType; - onChange: (schema: SchemaRecordType) => void; onAdd?: () => void; + onChange: (schema: SchemaRecordType) => void; + schema: SchemaRecordType; } -export const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps) => { +const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); return ( -
+
onChange(helpers.setSchemaTypeAndRemoveWrongFields(value, schema))} - type={helpers.getSchemaType(schema)} + onChange={(value) => onChange(setSchemaTypeAndRemoveWrongFields(value, schema))} + type={getSchemaType(schema)} /> -
+
{isMenuOpen && ( - setIsMenuOpen(false)} title="Extra fields"> - - + setIsMenuOpen(false)} + schema={schema} + title="Extra fields" + /> )}
); }; + +export {SchemaControls, SchemaArrayControls}; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx index 59cf87b23f..4113d5a160 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx @@ -18,6 +18,7 @@ import { } from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; import {SchemaArrayControls, SchemaControls} from './SchemaControls'; +import {Badge} from '@/components/ui/badge'; interface SchemaCreatorProps { isRequired?: boolean; @@ -35,44 +36,49 @@ const SchemaCreator = ({ onDelete = () => {}, schema, schemakey = '__root__', -}: SchemaCreatorProps) => ( -
-
- {isRequired && } - - onChange(addSchemaProperty(schema)) : undefined} - onChange={onChange} - onChangeKey={schemakey !== '__root__' ? onChangeKey : undefined} - onDelete={schemakey !== '__root__' ? () => onDelete(schemakey) : undefined} - schema={schema} - schemakey={schemakey} - /> -
+}: SchemaCreatorProps) => { + const objectPropertiesCount = + isSchemaObject(schema) && getSchemaProperties(schema) ? Object.keys(getSchemaProperties(schema)).length : 0; -
- {isSchemaObject(schema) && hasSchemaProperties(schema) && ( - - onChange(setSchemaProperty(key, s, schema))} - onChangeKey={(oldkey, newkey) => onChange(renameSchemaProperty(oldkey, newkey, schema))} - onDelete={(key) => onChange(deleteSchemaProperty(key, schema))} - schema={schema} - /> - - )} + return ( +
+
+ {isRequired && } + + onChange(addSchemaProperty(schema)) : undefined} + onChange={onChange} + onChangeKey={schemakey !== '__root__' ? onChangeKey : undefined} + onDelete={schemakey !== '__root__' ? () => onDelete(schemakey) : undefined} + schema={schema} + schemakey={schemakey} + /> +
- {isSchemaArray(schema) && ( - - onChange(setSchemaItems(s, schema))} - schema={getSchemaItems(schema)} - /> - - )} +
+ {isSchemaObject(schema) && hasSchemaProperties(schema) && ( + + onChange(setSchemaProperty(key, s, schema))} + onChangeKey={(oldkey, newkey) => onChange(renameSchemaProperty(oldkey, newkey, schema))} + onDelete={(key) => onChange(deleteSchemaProperty(key, schema))} + schema={schema} + /> + + )} + + {isSchemaArray(schema) && ( + + onChange(setSchemaItems(s, schema))} + schema={getSchemaItems(schema)} + /> + + )} +
-
-); + ); +}; interface SchemaArrayItemsProps { schema: SchemaRecordType; @@ -80,7 +86,7 @@ interface SchemaArrayItemsProps { } const SchemaArrayItems = ({onChange, schema}: SchemaArrayItemsProps) => ( -
+ <> onChange(addSchemaProperty(schema)) : undefined} onChange={onChange} @@ -106,7 +112,7 @@ const SchemaArrayItems = ({onChange, schema}: SchemaArrayItemsProps) => ( /> )} -
+ ); interface SchemaObjectPropertiesProps { @@ -133,7 +139,7 @@ const SchemaObjectProperties = ({onChange, onChangeKey, onDelete, schema}: Schem ); -const SchemaBox = ({children}: PropsWithChildren) => { +const SchemaBox = ({children, itemCount}: {itemCount?: number} & PropsWithChildren) => { const [isCollapsed, setIsCollapsed] = useState(false); return ( @@ -152,7 +158,13 @@ const SchemaBox = ({children}: PropsWithChildren) => { -
{children}
+ {isCollapsed ? ( + + {itemCount} items nested + + ) : ( +
{children}
+ )}
); }; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx index dfdd59f095..4d1547b9df 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx @@ -18,7 +18,7 @@ interface SchemaInputProps { type?: string; } -const SchemaInput = ({label, onChange, placeholder, type = 'text', value = ''}: SchemaInputProps) => { +const SchemaInput = ({label, onChange, placeholder, type = 'text', value = 'Untitled Pill'}: SchemaInputProps) => { const [localVal, setLocalVal] = useState(value); useEffect(() => { @@ -34,7 +34,7 @@ const SchemaInput = ({label, onChange, placeholder, type = 'text', value = ''}: }; return ( -
+
-
+ ); }; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx index 26e541f594..d7c2e2df5b 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx @@ -2,7 +2,7 @@ import {useMemo} from 'react'; import {useTranslation} from 'react-i18next'; import Select from 'react-select'; -import * as helpers from '../utils/helpers'; +import {getAllSchemaKeys, getSchemaMenuOptions, getSchemaType, setSchemaField, translateLabels} from '../utils/helpers'; import {SchemaMenuOptionType, SchemaRecordType} from '../utils/types'; import SchemaMenuList from './SchemaMenuList'; @@ -16,13 +16,10 @@ interface SchemaMenuProps { const SchemaMenu = ({onChange, schema}: SchemaMenuProps) => { const {t: translation} = useTranslation(); - const type = helpers.getSchemaType(schema); - const allOptions = useMemo( - () => helpers.translateLabels(translation, helpers.getSchemaMenuOptions(type)), - [type, translation] - ); + const type = getSchemaType(schema); + const fields = getAllSchemaKeys(schema); - const fields = helpers.getAllSchemaKeys(schema); + const allOptions = useMemo(() => translateLabels(translation, getSchemaMenuOptions(type)), [type, translation]); const displayFields = useMemo(() => allOptions.filter((item) => fields.includes(item.value)), [allOptions, fields]); @@ -32,9 +29,7 @@ const SchemaMenu = ({onChange, schema}: SchemaMenuProps) => { onChange(option)} value={helpers.findOption(type)(SCHEMA_TYPES)?.value} > @@ -38,7 +39,7 @@ const SchemaTypesSelect = ({onChange, type}: SchemaTypesSelectProps) => ( ))} -
+ ); export default SchemaTypesSelect; diff --git a/client/src/components/JsonSchemaBuilder/utils/constants.ts b/client/src/components/JsonSchemaBuilder/utils/constants.ts index 1920b2fa23..15074a9536 100755 --- a/client/src/components/JsonSchemaBuilder/utils/constants.ts +++ b/client/src/components/JsonSchemaBuilder/utils/constants.ts @@ -20,7 +20,7 @@ import { export const SCHEMA_TYPES: SchemaTypeOptionType[] = [ { - label: 'Text', + label: 'String', value: 'string', }, { From 7d97caca53a6812b2be34a6966af74354321ea93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 16:42:30 +0200 Subject: [PATCH 07/10] 2536 - JSON Schema Builder - prevent children from exceeding parent's width --- .../JsonSchemaBuilder/components/SchemaControls.tsx | 4 ++-- .../JsonSchemaBuilder/components/SchemaCreator.tsx | 8 ++++---- .../JsonSchemaBuilder/components/SchemaInput.tsx | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index ecb6a93664..77a1fd56fb 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -38,7 +38,7 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak return (
-
+
onChange(setSchemaTypeAndRemoveWrongFields(translation, schema))} type={getSchemaType(schema)} @@ -56,7 +56,7 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak )}
-
+
{isCollapsed ? ( diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx index 4d1547b9df..f05a651fa5 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx @@ -34,11 +34,11 @@ const SchemaInput = ({label, onChange, placeholder, type = 'text', value = 'Unti }; return ( -
+
setLocalVal(e.target.value)} onKeyPress={handleEnterPress(onChangeValue)} From 0e2bce787cd1b5e5fe3d5fcd3af21491c3f843f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 18:23:15 +0200 Subject: [PATCH 08/10] 2536 - JSON Schema Builder - change extra fields dialog into popover --- .../components/SchemaControls.tsx | 94 ++++++++++++------- .../components/SchemaCreator.tsx | 8 +- .../components/SchemaInput.tsx | 20 ++-- .../components/SchemaMenu.tsx | 41 -------- .../components/SchemaMenuDialog.tsx | 39 -------- .../components/SchemaMenuItem.tsx | 8 +- .../components/SchemaMenuPopover.tsx | 83 ++++++++++++++++ 7 files changed, 159 insertions(+), 134 deletions(-) delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx delete mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenuDialog.tsx create mode 100755 client/src/components/JsonSchemaBuilder/components/SchemaMenuPopover.tsx diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index 77a1fd56fb..c577abbaba 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -1,5 +1,5 @@ import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; -import SchemaMenuDialog from '@/components/JsonSchemaBuilder/components/SchemaMenuDialog'; +import SchemaMenuPopover from '@/components/JsonSchemaBuilder/components/SchemaMenuPopover'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; import {Button} from '@/components/ui/button'; import {CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; @@ -13,6 +13,8 @@ import { setSchemaTypeAndRemoveWrongFields, } from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; +import {Badge} from '@/components/ui/badge'; +import {twMerge} from 'tailwind-merge'; interface SchemaControlsProps { schema: SchemaRecordType; @@ -30,6 +32,8 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak const isObjectSchema = getSchemaType(schema) === 'object'; + const extraFields = Object.keys(schema).filter((key) => key !== 'type' && key !== 'items' && key !== 'properties'); + useEffect(() => { if (!schema.type || !getSchemaType(schema)) { onChange(setSchemaTypeAndRemoveWrongFields('object', schema)); @@ -56,15 +60,34 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak )}
-
- + + {typeof onDelete === 'function' && (
- - {isMenuOpen && ( - setIsMenuOpen(false)} - schema={schema} - title="Extra fields" - /> - )}
); }; @@ -112,6 +126,8 @@ interface SchemaArrayControlsProps { const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); + const extraFields = Object.keys(schema).filter((key) => key !== 'type' && key !== 'items' && key !== 'properties'); + return (
- + + {typeof onAdd === 'function' && ( )}
- - {isMenuOpen && ( - setIsMenuOpen(false)} - schema={schema} - title="Extra fields" - /> - )}
); }; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx index a78868cd0e..76fe0d6299 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx @@ -158,13 +158,7 @@ const SchemaBox = ({children, itemCount}: {itemCount?: number} & PropsWithChildr - {isCollapsed ? ( - - {itemCount} items nested - - ) : ( -
{children}
- )} + {isCollapsed ? {itemCount} items nested :
{children}
}
); }; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx index f05a651fa5..f91ccf8858 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaInput.tsx @@ -18,21 +18,21 @@ interface SchemaInputProps { type?: string; } -const SchemaInput = ({label, onChange, placeholder, type = 'text', value = 'Untitled Pill'}: SchemaInputProps) => { - const [localVal, setLocalVal] = useState(value); - - useEffect(() => { - setLocalVal(value); - }, [value]); +const SchemaInput = ({label, onChange, placeholder, type = 'text', value = 'Untitled'}: SchemaInputProps) => { + const [localValue, setLocalValue] = useState(value); const onChangeValue = () => { - if (localVal === value) { + if (localValue === value) { return; } - onChange(localVal); + onChange(localValue); }; + useEffect(() => { + setLocalValue(value); + }, [value]); + return (
@@ -40,11 +40,11 @@ const SchemaInput = ({label, onChange, placeholder, type = 'text', value = 'Unti setLocalVal(e.target.value)} + onChange={(e) => setLocalValue(e.target.value)} onKeyPress={handleEnterPress(onChangeValue)} placeholder={placeholder} type={type} - value={localVal} + value={localValue} />
); diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx deleted file mode 100755 index d7c2e2df5b..0000000000 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenu.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import {useMemo} from 'react'; -import {useTranslation} from 'react-i18next'; -import Select from 'react-select'; - -import {getAllSchemaKeys, getSchemaMenuOptions, getSchemaType, setSchemaField, translateLabels} from '../utils/helpers'; -import {SchemaMenuOptionType, SchemaRecordType} from '../utils/types'; -import SchemaMenuList from './SchemaMenuList'; - -import '../../CreatableSelect/CreatableSelect.css'; - -interface SchemaMenuProps { - schema: SchemaRecordType; - onChange: (schema: SchemaRecordType) => void; -} - -const SchemaMenu = ({onChange, schema}: SchemaMenuProps) => { - const {t: translation} = useTranslation(); - - const type = getSchemaType(schema); - const fields = getAllSchemaKeys(schema); - - const allOptions = useMemo(() => translateLabels(translation, getSchemaMenuOptions(type)), [type, translation]); - - const displayFields = useMemo(() => allOptions.filter((item) => fields.includes(item.value)), [allOptions, fields]); - - return ( -
- - - + onChange(setSchemaField(option.value, undefined, schema)) + } + options={allOptions.filter( + (option) => !displayFields.some((field) => field.value === option.value) + )} + placeholder="Description, Required, etc." + value={undefined} + /> + + + + + +
+ + + ); +}; + +export default SchemaMenuPopover; From 24ab18ff0d0a52466e7349ed7b728ea6951cde5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Thu, 15 May 2025 18:31:20 +0200 Subject: [PATCH 09/10] 2536 - JSON Schema Builder - SF --- .../JsonSchemaBuilder/components/SchemaControls.tsx | 4 ++-- .../components/JsonSchemaBuilder/components/SchemaCreator.tsx | 2 +- .../JsonSchemaBuilder/components/SchemaMenuItem.tsx | 2 +- client/src/components/Note.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx index c577abbaba..ba8c9c1910 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaControls.tsx @@ -1,9 +1,11 @@ import SchemaInput from '@/components/JsonSchemaBuilder/components/SchemaInput'; import SchemaMenuPopover from '@/components/JsonSchemaBuilder/components/SchemaMenuPopover'; import SchemaTypesSelect from '@/components/JsonSchemaBuilder/components/SchemaTypesSelect'; +import {Badge} from '@/components/ui/badge'; import {Button} from '@/components/ui/button'; import {CircleEllipsisIcon, PlusIcon, TrashIcon} from 'lucide-react'; import {useEffect, useState} from 'react'; +import {twMerge} from 'tailwind-merge'; import { addSchemaProperty, @@ -13,8 +15,6 @@ import { setSchemaTypeAndRemoveWrongFields, } from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; -import {Badge} from '@/components/ui/badge'; -import {twMerge} from 'tailwind-merge'; interface SchemaControlsProps { schema: SchemaRecordType; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx index 76fe0d6299..63ed5e85aa 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaCreator.tsx @@ -1,3 +1,4 @@ +import {Badge} from '@/components/ui/badge'; import {Button} from '@/components/ui/button'; import {AsteriskIcon, ChevronDownIcon} from 'lucide-react'; import {PropsWithChildren, useState} from 'react'; @@ -18,7 +19,6 @@ import { } from '../utils/helpers'; import {SchemaRecordType} from '../utils/types'; import {SchemaArrayControls, SchemaControls} from './SchemaControls'; -import {Badge} from '@/components/ui/badge'; interface SchemaCreatorProps { isRequired?: boolean; diff --git a/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx b/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx index 7dcafd3313..20b4ef854a 100755 --- a/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx +++ b/client/src/components/JsonSchemaBuilder/components/SchemaMenuItem.tsx @@ -36,7 +36,7 @@ const Item = ({children, onDelete}: ItemProps) => (
{children}
)}
@@ -120,10 +133,11 @@ const SchemaControls = ({onAdd, onChange, onChangeKey, onDelete, schema, schemak interface SchemaArrayControlsProps { onAdd?: () => void; onChange: (schema: SchemaRecordType) => void; + root?: boolean; schema: SchemaRecordType; } -const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps) => { +const SchemaArrayControls = ({onAdd, onChange, root, schema}: SchemaArrayControlsProps) => { const [isMenuOpen, setIsMenuOpen] = useState(false); const extraFields = Object.keys(schema).filter((key) => key !== 'type' && key !== 'items' && key !== 'properties'); @@ -145,11 +159,13 @@ const SchemaArrayControls = ({onAdd, onChange, schema}: SchemaArrayControlsProps