From 78aae99e39bb7bbe0dced24da853e847f77f7b5f Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 13 Oct 2020 10:59:24 +0100 Subject: [PATCH] prevent duplicate table names --- .../popovers/CreateEditColumnPopover.svelte | 22 ++++++++++--------- .../modals/CreateTableModal.svelte | 17 ++++++++++++-- .../popovers/EditTablePopover.svelte | 19 ++++++++++++++-- .../standard-components/src/Navigation.svelte | 12 ++++++---- 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte index 2e2ad6f158..bc076266e5 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte @@ -65,16 +65,18 @@
- + {#if !originalName} + + {/if} {#if field.type !== 'link'} model.name === tableName)) { + error = `Table with name ${tableName} already exists. Please choose another name.` + return + } + error = "" } async function saveTable() { @@ -61,12 +72,14 @@ title="Create Table" confirmText="Create" onConfirm={saveTable} - disabled={!name || (dataImport && !dataImport.valid)}> + disabled={error || !name || (dataImport && !dataImport.valid)}> + on:input={checkValid} + bind:value={name} + {error} />
diff --git a/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte index 028b78a1e8..36ccbb4800 100644 --- a/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte @@ -11,6 +11,8 @@ let dropdown let editing let confirmDeleteDialog + let error = "" + let originalName = table.name $: fields = Object.keys(table.schema) @@ -39,6 +41,15 @@ notifier.success("Table renamed successfully") hideEditor() } + + function checkValid(evt) { + const tableName = evt.target.value + if (originalName !== tableName && $backendUiStore.models.some(model => model.name === tableName)) { + error = `Table with name ${tableName} already exists. Please choose another name.` + return + } + error = "" + }
@@ -48,7 +59,11 @@ {#if editing}
Edit Table
- +