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