From aae357f50d3616131c345a07d7fd48c6d32eae92 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 1 Jul 2024 16:48:25 +0100 Subject: [PATCH] Refactor RowSelector initialisation into a function --- .../automation/SetupPanel/RowSelector.svelte | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte index b257fa2d30..edfdb4d834 100644 --- a/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte +++ b/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte @@ -56,10 +56,6 @@ meta, }) - $: if ($memoStore?.meta?.fields) { - editableFields = cloneDeep($memoStore?.meta?.fields) - } - $: parsedBindings = bindings.map(binding => { let clone = Object.assign({}, binding) clone.icon = "ShareAndroid" @@ -68,9 +64,18 @@ $: tableId = $memoStore?.row?.tableId - $: if (tableId) { + $: initData(tableId, $memoStore?.meta?.fields, $memoStore?.row) + + const initData = (tableId, metaFields, row) => { + if (!tableId) { + return + } + + // Refesh the editable fields + editableFields = cloneDeep(metaFields || {}) + // Refresh all the row data - editableRow = cloneDeep($memoStore?.row) + editableRow = cloneDeep(row || {}) table = $tables.list.find(table => table._id === tableId) @@ -106,7 +111,7 @@ if (!emptyField && !Object.hasOwn(editableFields, key)) { editableFields = { ...editableFields, - [key]: key, + [key]: {}, } }