Fix filtering options
This commit is contained in:
parent
aaa1603d1b
commit
bf673bff71
|
@ -89,8 +89,8 @@
|
||||||
$: updateOptions(optionsMap)
|
$: updateOptions(optionsMap)
|
||||||
$: !open && sortOptions()
|
$: !open && sortOptions()
|
||||||
|
|
||||||
// Fetch new options when search term changes
|
// Search for new options when search term changes
|
||||||
$: debouncedFetchRows(searchTerm, primaryDisplay)
|
$: debouncedSearchOptions(searchTerm || "", primaryDisplayField)
|
||||||
|
|
||||||
// Ensure backwards compatibility
|
// Ensure backwards compatibility
|
||||||
$: enrichedDefaultValue = enrichDefaultValue(defaultValue)
|
$: enrichedDefaultValue = enrichDefaultValue(defaultValue)
|
||||||
|
@ -310,28 +310,29 @@
|
||||||
return val.includes(",") ? val.split(",") : val
|
return val.includes(",") ? val.split(",") : val
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchRows(searchTerm: any, primaryDisplay: string) {
|
// Searches for new options matching the given term
|
||||||
// Don't request until we have the primary display or default value has been fetched
|
async function searchOptions(searchTerm: string, primaryDisplay?: string) {
|
||||||
if (!primaryDisplay) {
|
if (!primaryDisplay) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we match all filters, rather than any
|
// Ensure we match all filters, rather than any
|
||||||
// @ts-expect-error this doesn't fit types, but don't want to change it yet
|
let newFilter: any = filter
|
||||||
const baseFilter: any = (filter || []).filter(x => x.operator !== "allOr")
|
if (searchTerm) {
|
||||||
|
// @ts-expect-error this doesn't fit types, but don't want to change it yet
|
||||||
|
newFilter = (newFilter || []).filter(x => x.operator !== "allOr")
|
||||||
|
newFilter.push({
|
||||||
|
// Use a big numeric prefix to avoid clashing with an existing filter
|
||||||
|
field: `999:${primaryDisplay}`,
|
||||||
|
operator: "string",
|
||||||
|
value: searchTerm,
|
||||||
|
})
|
||||||
|
}
|
||||||
await fetch?.update({
|
await fetch?.update({
|
||||||
filter: [
|
filter: newFilter,
|
||||||
...baseFilter,
|
|
||||||
{
|
|
||||||
// Use a big numeric prefix to avoid clashing with an existing filter
|
|
||||||
field: `999:${primaryDisplay}`,
|
|
||||||
operator: "string",
|
|
||||||
value: searchTerm,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const debouncedFetchRows = Utils.debounce(fetchRows, 250)
|
const debouncedSearchOptions = Utils.debounce(searchOptions, 250)
|
||||||
|
|
||||||
// Flattens an array of row-like objects into a simple array of row IDs
|
// Flattens an array of row-like objects into a simple array of row IDs
|
||||||
const flatten = (values: any | any[]): string[] => {
|
const flatten = (values: any | any[]): string[] => {
|
||||||
|
|
Loading…
Reference in New Issue