From cebaac9fc4f6eaba789e9b5094865b6bae9ae01b Mon Sep 17 00:00:00 2001 From: "Ricardo M." Date: Mon, 16 Dec 2024 14:12:23 +0100 Subject: [PATCH] chore(Settings): Add experimental features --- packages/ui/src/assets/settingsSchema.json | 14 +++ .../src/components/Form/CustomAutoForm.scss | 5 + .../ui/src/components/Form/CustomAutoForm.tsx | 1 + .../__snapshots__/SettingsForm.test.tsx.snap | 111 ++++++++++++++++++ .../localstorage-settings-adapter.test.ts | 6 + .../ui/src/models/settings/settings.model.ts | 6 + .../KaotoEditorFactory.test.ts | 12 ++ .../settings.provider.test.tsx.snap | 2 +- 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 packages/ui/src/components/Form/CustomAutoForm.scss diff --git a/packages/ui/src/assets/settingsSchema.json b/packages/ui/src/assets/settingsSchema.json index 0b152c257..d7d9a84ef 100644 --- a/packages/ui/src/assets/settingsSchema.json +++ b/packages/ui/src/assets/settingsSchema.json @@ -24,6 +24,20 @@ "default": "onHover", "type": "string", "enum": ["onHover", "onSelection"] + }, + "experimentalFeatures": { + "title": "Experimental features", + "description": "Enable / disable experimental features", + "type": "object", + "additionalProperties": false, + "properties": { + "enableDragAndDrop": { + "title": "Enable Drag & Drop", + "description": "Control whether to enable drag and drop feature", + "type": "boolean", + "default": false + } + } } } } diff --git a/packages/ui/src/components/Form/CustomAutoForm.scss b/packages/ui/src/components/Form/CustomAutoForm.scss new file mode 100644 index 000000000..8d52cb793 --- /dev/null +++ b/packages/ui/src/components/Form/CustomAutoForm.scss @@ -0,0 +1,5 @@ +/* stylelint-disable-next-line selector-class-pattern */ +form.pf-v5-c-form > div:not(.pf-v5-c-form__group) { + display: grid; + gap: var(--pf-v5-c-form--GridGap); +} diff --git a/packages/ui/src/components/Form/CustomAutoForm.tsx b/packages/ui/src/components/Form/CustomAutoForm.tsx index 837cccb63..54b61394e 100644 --- a/packages/ui/src/components/Form/CustomAutoForm.tsx +++ b/packages/ui/src/components/Form/CustomAutoForm.tsx @@ -4,6 +4,7 @@ import { useSchemaBridgeContext } from '../../hooks'; import { IDataTestID } from '../../models'; import { CustomAutoFieldDetector } from './CustomAutoField'; import { CustomAutoFields } from './CustomAutoFields'; +import './CustomAutoForm.scss'; interface CustomAutoFormProps extends IDataTestID { model: unknown; diff --git a/packages/ui/src/components/Settings/__snapshots__/SettingsForm.test.tsx.snap b/packages/ui/src/components/Settings/__snapshots__/SettingsForm.test.tsx.snap index 4252c4394..6c89233d5 100644 --- a/packages/ui/src/components/Settings/__snapshots__/SettingsForm.test.tsx.snap +++ b/packages/ui/src/components/Settings/__snapshots__/SettingsForm.test.tsx.snap @@ -378,6 +378,117 @@ exports[`SettingsForm should render 1`] = ` +
+
+
+
+
+ Experimental features +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
`; diff --git a/packages/ui/src/models/settings/localstorage-settings-adapter.test.ts b/packages/ui/src/models/settings/localstorage-settings-adapter.test.ts index a5490c442..e2b4cee73 100644 --- a/packages/ui/src/models/settings/localstorage-settings-adapter.test.ts +++ b/packages/ui/src/models/settings/localstorage-settings-adapter.test.ts @@ -15,6 +15,9 @@ describe('LocalStorageSettingsAdapter', () => { catalogUrl: 'http://example.com', nodeLabel: NodeLabelType.Description, nodeToolbarTrigger: NodeToolbarTrigger.onSelection, + experimentalFeatures: { + enableDragAndDrop: true, + }, }; adapter.saveSettings(newSettings); @@ -38,6 +41,9 @@ describe('LocalStorageSettingsAdapter', () => { catalogUrl: 'http://example.com', nodeLabel: NodeLabelType.Description, nodeToolbarTrigger: NodeToolbarTrigger.onSelection, + experimentalFeatures: { + enableDragAndDrop: true, + }, }; adapter.saveSettings(newSettings); diff --git a/packages/ui/src/models/settings/settings.model.ts b/packages/ui/src/models/settings/settings.model.ts index a540d46be..bfa077fac 100644 --- a/packages/ui/src/models/settings/settings.model.ts +++ b/packages/ui/src/models/settings/settings.model.ts @@ -12,6 +12,9 @@ export interface ISettingsModel { catalogUrl: string; nodeLabel: NodeLabelType; nodeToolbarTrigger: NodeToolbarTrigger; + experimentalFeatures: { + enableDragAndDrop: boolean; + }; } export interface AbstractSettingsAdapter { @@ -23,6 +26,9 @@ export class SettingsModel implements ISettingsModel { catalogUrl: string = ''; nodeLabel: NodeLabelType = NodeLabelType.Description; nodeToolbarTrigger: NodeToolbarTrigger = NodeToolbarTrigger.onHover; + experimentalFeatures = { + enableDragAndDrop: false, + }; constructor(options: Partial = {}) { Object.assign(this, options); diff --git a/packages/ui/src/multiplying-architecture/KaotoEditorFactory.test.ts b/packages/ui/src/multiplying-architecture/KaotoEditorFactory.test.ts index d13b153c2..7186abee8 100644 --- a/packages/ui/src/multiplying-architecture/KaotoEditorFactory.test.ts +++ b/packages/ui/src/multiplying-architecture/KaotoEditorFactory.test.ts @@ -16,6 +16,9 @@ describe('KaotoEditorFactory', () => { catalogUrl: 'catalog-url', nodeLabel: NodeLabelType.Id, nodeToolbarTrigger: NodeToolbarTrigger.onHover, + experimentalFeatures: { + enableDragAndDrop: false, + }, }; const envelopeContext = { @@ -41,6 +44,9 @@ describe('KaotoEditorFactory', () => { catalogUrl: 'catalog-url', nodeLabel: NodeLabelType.Id, nodeToolbarTrigger: NodeToolbarTrigger.onHover, + experimentalFeatures: { + enableDragAndDrop: false, + }, }; const getVSCodeKaotoSettingsSpy = jest.fn().mockResolvedValue(settingsModel); @@ -91,11 +97,17 @@ describe('KaotoEditorFactory', () => { catalogUrl: '', nodeLabel: NodeLabelType.Id, nodeToolbarTrigger: NodeToolbarTrigger.onHover, + experimentalFeatures: { + enableDragAndDrop: false, + }, }; const expectedSettings: ISettingsModel = { catalogUrl: 'path-prefix/camel-catalog/index.json', nodeLabel: NodeLabelType.Id, nodeToolbarTrigger: NodeToolbarTrigger.onHover, + experimentalFeatures: { + enableDragAndDrop: false, + }, }; const getVSCodeKaotoSettingsSpy = jest.fn().mockResolvedValue(settingsModel); diff --git a/packages/ui/src/providers/__snapshots__/settings.provider.test.tsx.snap b/packages/ui/src/providers/__snapshots__/settings.provider.test.tsx.snap index 966db3f73..3bcce822c 100644 --- a/packages/ui/src/providers/__snapshots__/settings.provider.test.tsx.snap +++ b/packages/ui/src/providers/__snapshots__/settings.provider.test.tsx.snap @@ -4,6 +4,6 @@ exports[`SettingsProvider should render 1`] = `

- {"catalogUrl":"","nodeLabel":"description","nodeToolbarTrigger":"onHover"} + {"catalogUrl":"","nodeLabel":"description","nodeToolbarTrigger":"onHover","experimentalFeatures":{"enableDragAndDrop":false}}

`;