From 8d1300753b8f9a1214a9b494475f5894911ba3dc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 24 May 2024 11:23:31 +0100 Subject: [PATCH] Disable saving options types when an invalid option name exists --- .../DataTable/modals/CreateEditColumn.svelte | 6 ++- .../DataTable/modals/OptionsEditor.svelte | 38 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index f3881c4836..730e51bf48 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -95,6 +95,7 @@ }, } let autoColumnInfo = getAutoColumnInformation() + let optionsValid = true $: rowGoldenSample = RowUtils.generateGoldenSample($rows) $: if (primaryDisplay) { @@ -138,7 +139,8 @@ $: invalid = !editableColumn?.name || (editableColumn?.type === LINK_TYPE && !editableColumn?.tableId) || - Object.keys(errors).length !== 0 + Object.keys(errors).length !== 0 || + !optionsValid $: errors = checkErrors(editableColumn) $: datasource = $datasources.list.find( source => source._id === table?.sourceId @@ -562,6 +564,7 @@ {:else if editableColumn.type === FieldType.LONGFORM}
@@ -585,6 +588,7 @@ {:else if editableColumn.type === DATE_TYPE && !editableColumn.autocolumn}
diff --git a/packages/builder/src/components/backend/DataTable/modals/OptionsEditor.svelte b/packages/builder/src/components/backend/DataTable/modals/OptionsEditor.svelte index 033c50e3d5..8e35e38ae9 100644 --- a/packages/builder/src/components/backend/DataTable/modals/OptionsEditor.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/OptionsEditor.svelte @@ -5,10 +5,11 @@ import { tick } from "svelte" import { Constants } from "@budibase/frontend-core" import { getSequentialName } from "helpers/duplicate" - import { writable } from "svelte/store" + import { derived, writable } from "svelte/store" export let constraints export let optionColors = {} + export let valid = true const flipDurationMs = 130 const { OptionColours } = Constants @@ -21,11 +22,22 @@ invalid: false, })) ) + const enrichedOptions = derived(options, $options => { + let enriched = [] + $options.forEach(option => { + enriched.push({ + ...option, + valid: option.name && !enriched.some(opt => opt.name === option.name), + }) + }) + return enriched + }) let openOption = null let anchor = null $: options.subscribe(updateConstraints) + $: valid = $enrichedOptions.every(option => option.valid) const updateConstraints = options => { constraints.inclusion = options.map(option => option.name) @@ -74,25 +86,9 @@ openOption = null } - const handleNameChange = (id, newName) => { - // Check we don't already have this option - const existing = $options.some(option => { - return (option.name === newName) & (option.id !== id) - }) - const invalid = !newName || existing + const handleNameChange = (id, name) => { options.update(state => { - state.find(option => option.id === id).invalid = invalid - return state.slice() - }) - - // Stop if invalid - if (invalid) { - return - } - - // Update name - options.update(state => { - state.find(option => option.id === id).name = newName + state.find(option => option.id === id).name = name return state.slice() }) } @@ -111,11 +107,11 @@ on:consider={e => options.set(e.detail.items)} on:finalize={e => options.set(e.detail.items)} > - {#each $options as option (option.id)} + {#each $enrichedOptions as option (option.id)}