Fix one-to-many relationships allowing selecting multiple rows on both sides
This commit is contained in:
parent
7ba064dd31
commit
d3c17308ab
|
@ -11,5 +11,7 @@
|
|||
</script>
|
||||
|
||||
<Modal bind:this={modal}>
|
||||
<CreateEditColumn on:updatecolumns={() => rows.actions.refreshSchema()} />
|
||||
<CreateEditColumn
|
||||
on:updatecolumns={() => rows.actions.refreshTableDefinition()}
|
||||
/>
|
||||
</Modal>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
let editColumnModal
|
||||
|
||||
const updateColumns = () => {
|
||||
rows.actions.refreshSchema()
|
||||
rows.actions.refreshTableDefinition()
|
||||
}
|
||||
|
||||
const editColumn = column => {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
export let schema
|
||||
export let onChange
|
||||
|
||||
$: selected && console.log(schema.relationshipType)
|
||||
|
||||
const { API } = getContext("sheet")
|
||||
|
||||
let isOpen = false
|
||||
|
@ -22,6 +24,7 @@
|
|||
let candidateIndex
|
||||
let lastSearchId
|
||||
|
||||
$: oneRowOnly = schema?.relationshipType === "one-to-many"
|
||||
$: editable = selected && !readonly
|
||||
$: results = getResults(searchResults, value)
|
||||
$: lookupMap = buildLookupMap(value, isOpen)
|
||||
|
@ -166,6 +169,9 @@
|
|||
if (value?.some(x => x._id === row._id)) {
|
||||
// If the row is already included, remove it and update the candidate
|
||||
// row to be the the same position if possible
|
||||
if (oneRowOnly) {
|
||||
await onChange([])
|
||||
} else {
|
||||
const newValue = value.filter(x => x._id !== row._id)
|
||||
if (!newValue.length) {
|
||||
candidateIndex = null
|
||||
|
@ -173,9 +179,14 @@
|
|||
candidateIndex = Math.min(candidateIndex, newValue.length - 1)
|
||||
}
|
||||
await onChange(newValue)
|
||||
}
|
||||
} else {
|
||||
// If we don't have this row, include it
|
||||
if (oneRowOnly) {
|
||||
await onChange([row])
|
||||
} else {
|
||||
await onChange(sortRows([...(value || []), row]))
|
||||
}
|
||||
candidateIndex = null
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue