From bdc2bcd97d4ab6e74b1b95a6473235a40e12e3c7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 18 Oct 2023 14:41:42 +0100 Subject: [PATCH] Add support for multiple dependsOn constraints in the manifest and fix issue with nullish dependsOn contraints --- .../Component/ComponentSettingsSection.svelte | 28 +++++++++++-------- packages/client/manifest.json | 23 +++++++++++++-- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte index 8eb2ebe10b..639cef332e 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/ComponentSettingsSection.svelte @@ -70,14 +70,22 @@ } const shouldDisplay = (instance, setting) => { - // Parse dependant settings - if (setting.dependsOn) { - let dependantSetting = setting.dependsOn + let dependsOn = setting.dependsOn + if (dependsOn && !Array.isArray(dependsOn)) { + dependsOn = [dependsOn] + } + if (!dependsOn?.length) { + return true + } + + // Ensure all conditions are met + return dependsOn.every(condition => { + let dependantSetting = condition let dependantValues = null - let invert = !!setting.dependsOn.invert - if (typeof setting.dependsOn === "object") { - dependantSetting = setting.dependsOn.setting - dependantValues = setting.dependsOn.value + let invert = !!condition.invert + if (typeof condition === "object") { + dependantSetting = condition.setting + dependantValues = condition.value } if (!dependantSetting) { return false @@ -93,14 +101,12 @@ const currentVal = helpers.deepGet(instance, dependantSetting) const anyMatches = dependantValues.some(dependantVal => { if (dependantVal == null) { - return currentVal == null || currentVal === false || currentVal === "" + return currentVal != null && currentVal !== false && currentVal !== "" } return dependantVal === currentVal }) return anyMatches !== invert - } - - return typeof setting.visible == "boolean" ? setting.visible : true + }) } const canRenderControl = (instance, setting, isScreen) => { diff --git a/packages/client/manifest.json b/packages/client/manifest.json index fbf7ffb0b3..ff0fbfac93 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -5567,18 +5567,35 @@ "type": "columns/grid", "label": "Columns", "key": "columns", - "dependsOn": "table" + "dependsOn": [ + "datasource", + { + "setting": "datasource.type", + "value": "custom", + "invert": true + } + ] }, { "type": "filter", "label": "Filtering", - "key": "initialFilter" + "key": "initialFilter", + "dependsOn": { + "setting": "datasource.type", + "value": "custom", + "invert": true + } }, { "type": "field/sortable", "label": "Sort column", "key": "initialSortColumn", - "placeholder": "Default" + "placeholder": "Default", + "dependsOn": { + "setting": "datasource.type", + "value": "custom", + "invert": true + } }, { "type": "select",