From 74b6f0069b893824313c231a0e4339bde8f8f81c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 17 Feb 2021 17:30:58 +0000 Subject: [PATCH] Fixing some errors found with relationships. --- .../DataTable/modals/CreateEditColumn.svelte | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 8ae492226f..11eaf74bb8 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -18,6 +18,7 @@ import ConfirmDialog from "components/common/ConfirmDialog.svelte" const AUTO_COL = "auto" + const LINK_TYPE = FIELDS.LINK.type let fieldDefinitions = cloneDeep(FIELDS) export let onClosed @@ -44,15 +45,16 @@ $: uneditable = $backendUiStore.selectedTable?._id === TableNames.USERS && UNEDITABLE_USER_FIELDS.includes(field.name) + $: invalid = (field.type === FIELDS.LINK.type && !field.tableId) // used to select what different options can be displayed for column type $: canBeSearched = - field.type !== "link" && + field.type !== LINK_TYPE && field.subtype !== AUTO_COLUMN_SUB_TYPES.CREATED_BY && field.subtype !== AUTO_COLUMN_SUB_TYPES.UPDATED_BY - $: canBeDisplay = field.type !== "link" && field.type !== AUTO_COL + $: canBeDisplay = field.type !== LINK_TYPE && field.type !== AUTO_COL $: canBeRequired = - field.type !== "link" && !uneditable && field.type !== AUTO_COL + field.type !== LINK_TYPE && !uneditable && field.type !== AUTO_COL async function saveColumn() { if (field.type === AUTO_COL) { @@ -84,13 +86,17 @@ } } - function handleFieldConstraints(event) { + function handleTypeChange(event) { const definition = fieldDefinitions[event.target.value.toUpperCase()] if (!definition) { return } field.type = definition.type field.constraints = definition.constraints + // remove any extra fields that may not be related to this type + delete field.autocolumn + delete field.subtype + delete field.tableId } function onChangeRequired(e) { @@ -138,7 +144,7 @@ secondary thin label="Type" - on:change={handleFieldConstraints} + on:change={handleTypeChange} bind:value={field.type}> {#each Object.values(fieldDefinitions) as field} @@ -229,7 +235,7 @@ Delete Column {/if} - +