From 346f1d652b6046e280119391c7803ad8488f28f5 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 14 Oct 2021 16:36:45 +0100 Subject: [PATCH 1/3] Allow options picker to be used on text columns --- .../ComponentSettingsSection.svelte | 1 + .../PropertyControls/FormFieldSelect.svelte | 16 +++++++++++----- .../PropertyControls/PropertyControl.svelte | 2 ++ packages/client/manifest.json | 1 + .../client/src/components/app/forms/Field.svelte | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte b/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte index f047e9316b..ca6f0d24d1 100644 --- a/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte @@ -75,6 +75,7 @@ {#if canRenderControl(setting)} { + const getOptions = (schema, type, fieldTypes) => { let entries = Object.entries(schema ?? {}) - if (fieldType) { - fieldType = fieldType.split("/")[1] - entries = entries.filter(entry => entry[1].type === fieldType) + + // fallback to using only field/options fields + if (!fieldTypes) { + fieldTypes = [type] } + + const types = fieldTypes.map(fieldType => fieldType.split("/")[1]) + entries = entries.filter(entry => types.includes(entry[1].type)) + return entries.map(entry => entry[0]) } diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte index 4ca7d9fc12..193174fb52 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte @@ -13,6 +13,7 @@ export let control = null export let key = "" export let type = "" + export let fieldTypes = [] export let value = null export let props = {} export let onChange = () => {} @@ -82,6 +83,7 @@ name={key} text={label} {type} + {fieldTypes} {...props} /> {#if bindable && !key.startsWith("_") && type === "text"} diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 2e64b1fb4c..f377a3ede4 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -1950,6 +1950,7 @@ "settings": [ { "type": "field/options", + "fieldTypes": ["field/options", "field/string"], "label": "Field", "key": "field" }, diff --git a/packages/client/src/components/app/forms/Field.svelte b/packages/client/src/components/app/forms/Field.svelte index 3eb52420e5..ca607e7315 100644 --- a/packages/client/src/components/app/forms/Field.svelte +++ b/packages/client/src/components/app/forms/Field.svelte @@ -67,7 +67,7 @@ - {:else if fieldSchema?.type && fieldSchema?.type !== type} + {:else if fieldSchema?.type && fieldSchema?.type !== type && type !== "options"} From f2b4ba2fb2f9b8c8c10c4666826634f6d35a1dc1 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 18 Oct 2021 11:58:42 +0100 Subject: [PATCH 2/3] Code review refactoring --- .../PropertyControls/FormFieldSelect.svelte | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FormFieldSelect.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FormFieldSelect.svelte index 3991390ce6..65b698d779 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FormFieldSelect.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FormFieldSelect.svelte @@ -21,15 +21,18 @@ $: schema = getSchemaForDatasource($currentAsset, datasource, true).schema $: options = getOptions(schema, type, fieldTypes) - const getOptions = (schema, type, fieldTypes) => { + const getOptions = (schema, type) => { let entries = Object.entries(schema ?? {}) - // fallback to using only field/options fields - if (!fieldTypes) { - fieldTypes = [type] + let types = [] + if (type === "field/options") { + // allow options to be used on both options and string fields + types = [type, "field/string"] + } else { + types = [type] } - const types = fieldTypes.map(fieldType => fieldType.split("/")[1]) + types = types.map(type => type.split("/")[1]) entries = entries.filter(entry => types.includes(entry[1].type)) return entries.map(entry => entry[0]) From be41a855d103d81ab874f99bd5dc3419e1982c95 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 18 Oct 2021 12:02:08 +0100 Subject: [PATCH 3/3] Remove redundant fieldTypes --- .../design/PropertiesPanel/ComponentSettingsSection.svelte | 1 - .../PropertiesPanel/PropertyControls/FormFieldSelect.svelte | 3 +-- .../PropertiesPanel/PropertyControls/PropertyControl.svelte | 2 -- packages/client/manifest.json | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte b/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte index ca6f0d24d1..f047e9316b 100644 --- a/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/ComponentSettingsSection.svelte @@ -75,7 +75,6 @@ {#if canRenderControl(setting)} { let entries = Object.entries(schema ?? {}) diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte index acfa057b01..91e67c1685 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/PropertyControl.svelte @@ -13,7 +13,6 @@ export let control = null export let key = "" export let type = "" - export let fieldTypes = [] export let value = null export let props = {} export let onChange = () => {} @@ -83,7 +82,6 @@ name={key} text={label} {type} - {fieldTypes} {...props} /> {#if bindable && !key.startsWith("_") && type === "text"} diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 393c906a55..2adfd96626 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -1950,7 +1950,6 @@ "settings": [ { "type": "field/options", - "fieldTypes": ["field/options", "field/string"], "label": "Field", "key": "field" },