fixing edge cases and improving reusability
This commit is contained in:
parent
8b062524e2
commit
420972ca6b
|
@ -60,7 +60,9 @@
|
||||||
let relationshipPart1 = PrettyRelationshipDefinitions.Many
|
let relationshipPart1 = PrettyRelationshipDefinitions.Many
|
||||||
let relationshipPart2 = PrettyRelationshipDefinitions.One
|
let relationshipPart2 = PrettyRelationshipDefinitions.One
|
||||||
|
|
||||||
|
let relationshipTableIdPrimary = null
|
||||||
let relationshipTableIdSecondary = null
|
let relationshipTableIdSecondary = null
|
||||||
|
|
||||||
let table = $tables.selected
|
let table = $tables.selected
|
||||||
let confirmDeleteDialog
|
let confirmDeleteDialog
|
||||||
let savingColumn
|
let savingColumn
|
||||||
|
@ -96,7 +98,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
// this parses any changes the user has made when creating a new internal relationship
|
||||||
|
// into what we expect the schema to look like
|
||||||
if (editableColumn.type === LINK_TYPE) {
|
if (editableColumn.type === LINK_TYPE) {
|
||||||
|
relationshipTableIdPrimary = table._id
|
||||||
if (relationshipPart1 === PrettyRelationshipDefinitions.ONE) {
|
if (relationshipPart1 === PrettyRelationshipDefinitions.ONE) {
|
||||||
relationshipOpts2 = relationshipOpts2.filter(
|
relationshipOpts2 = relationshipOpts2.filter(
|
||||||
opt => opt !== PrettyRelationshipDefinitions.ONE
|
opt => opt !== PrettyRelationshipDefinitions.ONE
|
||||||
|
@ -130,6 +135,20 @@
|
||||||
primaryDisplay =
|
primaryDisplay =
|
||||||
$tables.selected.primaryDisplay == null ||
|
$tables.selected.primaryDisplay == null ||
|
||||||
$tables.selected.primaryDisplay === editableColumn.name
|
$tables.selected.primaryDisplay === editableColumn.name
|
||||||
|
|
||||||
|
// Here we are setting the relationship values based on the editableColumn
|
||||||
|
// This part of the code is used when viewing an existing field hence the check
|
||||||
|
// for the tableId
|
||||||
|
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) {
|
||||||
|
relationshipTableIdPrimary = table._id
|
||||||
|
relationshipTableIdSecondary = editableColumn.tableId
|
||||||
|
if (editableColumn.relationshipType in relationshipMap) {
|
||||||
|
const { part1, part2 } =
|
||||||
|
relationshipMap[editableColumn.relationshipType]
|
||||||
|
relationshipPart1 = part1
|
||||||
|
relationshipPart2 = part2
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!savingColumn) {
|
} else if (!savingColumn) {
|
||||||
let highestNumber = 0
|
let highestNumber = 0
|
||||||
Object.keys(table.schema).forEach(columnName => {
|
Object.keys(table.schema).forEach(columnName => {
|
||||||
|
@ -147,16 +166,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allowedTypes = getAllowedTypes()
|
allowedTypes = getAllowedTypes()
|
||||||
|
|
||||||
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) {
|
|
||||||
relationshipTableIdSecondary = editableColumn.tableId
|
|
||||||
if (editableColumn.relationshipType in relationshipMap) {
|
|
||||||
const { part1, part2 } =
|
|
||||||
relationshipMap[editableColumn.relationshipType]
|
|
||||||
relationshipPart1 = part1
|
|
||||||
relationshipPart2 = part2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: initialiseField(field, savingColumn)
|
$: initialiseField(field, savingColumn)
|
||||||
|
@ -217,10 +226,7 @@
|
||||||
$: external = table.type === "external"
|
$: external = table.type === "external"
|
||||||
// in the case of internal tables the sourceId will just be undefined
|
// in the case of internal tables the sourceId will just be undefined
|
||||||
$: tableOptions = $tables.list.filter(
|
$: tableOptions = $tables.list.filter(
|
||||||
opt =>
|
opt => opt.type === table.type && table.sourceId === opt.sourceId
|
||||||
opt._id !== $tables.selected._id &&
|
|
||||||
opt.type === table.type &&
|
|
||||||
table.sourceId === opt.sourceId
|
|
||||||
)
|
)
|
||||||
$: typeEnabled =
|
$: typeEnabled =
|
||||||
!originalName ||
|
!originalName ||
|
||||||
|
@ -577,7 +583,7 @@
|
||||||
<RelationshipSelector
|
<RelationshipSelector
|
||||||
bind:relationshipPart1
|
bind:relationshipPart1
|
||||||
bind:relationshipPart2
|
bind:relationshipPart2
|
||||||
bind:relationshipTableIdPrimary={table.name}
|
bind:relationshipTableIdPrimary
|
||||||
bind:relationshipTableIdSecondary
|
bind:relationshipTableIdSecondary
|
||||||
bind:editableColumn
|
bind:editableColumn
|
||||||
{relationshipOpts1}
|
{relationshipOpts1}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
<div class="relationship-part">
|
<div class="relationship-part">
|
||||||
<Select
|
<Select
|
||||||
disabled
|
disabled
|
||||||
options={[relationshipTableIdPrimary]}
|
options={tableOptions}
|
||||||
value={relationshipTableIdPrimary}
|
getOptionLabel={table => table.name}
|
||||||
|
getOptionValue={table => table._id}
|
||||||
|
bind:value={relationshipTableIdPrimary}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,7 +46,9 @@
|
||||||
<Select
|
<Select
|
||||||
disabled={linkEditDisabled}
|
disabled={linkEditDisabled}
|
||||||
bind:value={relationshipTableIdSecondary}
|
bind:value={relationshipTableIdSecondary}
|
||||||
options={tableOptions}
|
options={tableOptions.filter(
|
||||||
|
table => table._id !== relationshipTableIdPrimary
|
||||||
|
)}
|
||||||
getOptionLabel={table => table.name}
|
getOptionLabel={table => table.name}
|
||||||
getOptionValue={table => table._id}
|
getOptionValue={table => table._id}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue