1
0
Fork 0
mirror of synced 2024-07-28 17:46:09 +12:00

Minor cleanup.

This commit is contained in:
mike12345567 2023-10-12 19:07:04 +01:00
parent 16d551542e
commit 535a6e1a47

View file

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