Minor cleanup.
This commit is contained in:
parent
16d551542e
commit
535a6e1a47
|
@ -26,7 +26,7 @@
|
||||||
let tableDefinition
|
let tableDefinition
|
||||||
let searchTerm
|
let searchTerm
|
||||||
let open
|
let open
|
||||||
let hasFetchedDefault, fetchedDefault
|
let fetchedDefault
|
||||||
|
|
||||||
$: type =
|
$: type =
|
||||||
datasourceType === "table" ? FieldTypes.LINK : FieldTypes.BB_REFERENCE
|
datasourceType === "table" ? FieldTypes.LINK : FieldTypes.BB_REFERENCE
|
||||||
|
@ -111,20 +111,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: fetchRows(searchTerm, primaryDisplay, hasFetchedDefault)
|
$: fetchRows(searchTerm, primaryDisplay, defaultValue)
|
||||||
|
|
||||||
const fetchRows = async (searchTerm, primaryDisplay, gotDefault) => {
|
const fetchRows = async (searchTerm, primaryDisplay, defaultVal) => {
|
||||||
const allRowsFetched =
|
const allRowsFetched =
|
||||||
$fetch.loaded &&
|
$fetch.loaded &&
|
||||||
!Object.keys($fetch.query?.string || {}).length &&
|
!Object.keys($fetch.query?.string || {}).length &&
|
||||||
!$fetch.hasNextPage
|
!$fetch.hasNextPage
|
||||||
const shouldFetch = !defaultValue ? !allRowsFetched : gotDefault
|
|
||||||
// Don't request until we have the primary display or default value has been fetched
|
// Don't request until we have the primary display or default value has been fetched
|
||||||
if (shouldFetch && primaryDisplay) {
|
if (allRowsFetched || !primaryDisplay) {
|
||||||
await fetch.update({
|
return
|
||||||
query: { string: { [primaryDisplay]: searchTerm } },
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
if (defaultVal) {
|
||||||
|
await fetch.update({
|
||||||
|
query: {equal: {_id: defaultValue}}
|
||||||
|
})
|
||||||
|
fetchedDefault = $fetch.rows?.[0]
|
||||||
|
}
|
||||||
|
await fetch.update({
|
||||||
|
query: { string: { [primaryDisplay]: searchTerm } },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const flatten = values => {
|
const flatten = values => {
|
||||||
|
@ -178,20 +184,6 @@
|
||||||
fetch.nextPage()
|
fetch.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
// the pagination might not include the default row
|
|
||||||
if (defaultValue) {
|
|
||||||
await fetch.update({
|
|
||||||
query: { equal: { _id: defaultValue }}
|
|
||||||
})
|
|
||||||
const fetched = $fetch.rows?.[0]
|
|
||||||
if (fetched) {
|
|
||||||
fetchedDefault = { ...fetched }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hasFetchedDefault = true
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
|
|
Loading…
Reference in New Issue