extract logic from component and disable one to one

This commit is contained in:
Peter Clement 2023-09-26 15:12:01 +01:00
parent 18fd154ab5
commit 7d4613c3f6
2 changed files with 23 additions and 3 deletions

View File

@ -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}

View File

@ -10,6 +10,8 @@
export let linkEditDisabled
export let tableOptions
export let errors
export let relationshipOpts1
export let relationshipOpts2
</script>
<div class="relationship-container">
@ -17,7 +19,7 @@
<Select
disabled={linkEditDisabled}
bind:value={relationshipPart1}
options={Object.values(PrettyRelationshipDefinitions)}
options={relationshipOpts1}
/>
</div>
<div class="relationship-label">in</div>
@ -34,7 +36,7 @@
<Select
disabled={linkEditDisabled}
bind:value={relationshipPart2}
options={Object.values(PrettyRelationshipDefinitions)}
options={relationshipOpts2}
getOptionLabel={option => "To " + option.toLowerCase()}
/>
</div>