From 7d4613c3f68a7b77693ecec342f4a4e92c842f75 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 26 Sep 2023 15:12:01 +0100 Subject: [PATCH 1/4] extract logic from component and disable one to one --- .../DataTable/modals/CreateEditColumn.svelte | 20 ++++++++++++++++++- .../common/RelationshipSelector.svelte | 6 ++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 8f0c5a0b7e..f2e3d8f759 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -73,6 +73,8 @@ // Initial value for column name in other table for linked records fieldName: $tables.selected.name, } + let relationshipOpts1 = Object.values(PrettyRelationshipDefinitions) + let relationshipOpts2 = Object.values(PrettyRelationshipDefinitions) $: if (primaryDisplay) { editableColumn.constraints.presence = { allowEmpty: false } @@ -95,6 +97,21 @@ $: { if (editableColumn.type === LINK_TYPE) { + if (relationshipPart1 === PrettyRelationshipDefinitions.ONE) { + relationshipOpts2 = relationshipOpts2.filter( + opt => opt !== PrettyRelationshipDefinitions.ONE + ) + } else { + relationshipOpts2 = Object.values(PrettyRelationshipDefinitions) + } + + if (relationshipPart2 === PrettyRelationshipDefinitions.ONE) { + relationshipOpts1 = relationshipOpts1.filter( + opt => opt !== PrettyRelationshipDefinitions.ONE + ) + } else { + relationshipOpts1 = Object.values(PrettyRelationshipDefinitions) + } // Determine the relationship type based on the selected values of both parts editableColumn.relationshipType = Object.entries(relationshipMap).find( ([_, parts]) => @@ -104,7 +121,6 @@ editableColumn.tableId = relationshipTableIdSecondary } } - const initialiseField = (field, savingColumn) => { isCreating = !field if (field && !savingColumn) { @@ -564,6 +580,8 @@ bind:relationshipTableIdPrimary={table.name} bind:relationshipTableIdSecondary bind:editableColumn + {relationshipOpts1} + {relationshipOpts2} {linkEditDisabled} {tableOptions} {errors} diff --git a/packages/builder/src/components/common/RelationshipSelector.svelte b/packages/builder/src/components/common/RelationshipSelector.svelte index c050323bb6..7e23927eac 100644 --- a/packages/builder/src/components/common/RelationshipSelector.svelte +++ b/packages/builder/src/components/common/RelationshipSelector.svelte @@ -10,6 +10,8 @@ export let linkEditDisabled export let tableOptions export let errors + export let relationshipOpts1 + export let relationshipOpts2
@@ -17,7 +19,7 @@ "To " + option.toLowerCase()} />
From 8b062524e2b6f41c8dbd553db62f5b09616c3a60 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 26 Sep 2023 15:24:14 +0100 Subject: [PATCH 2/4] fix lint --- .../builder/src/components/common/RelationshipSelector.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/common/RelationshipSelector.svelte b/packages/builder/src/components/common/RelationshipSelector.svelte index 7e23927eac..7ef9f2cc34 100644 --- a/packages/builder/src/components/common/RelationshipSelector.svelte +++ b/packages/builder/src/components/common/RelationshipSelector.svelte @@ -1,6 +1,5 @@