Change query defaulting behaviour

This commit is contained in:
Dean 2024-09-16 15:28:49 +01:00
parent 19609434f7
commit 6b610bd982
3 changed files with 9 additions and 18 deletions

View File

@ -177,16 +177,11 @@ export default class DataFetch {
}
}
let defaultQuery = {
logicalOperator: FilterGroupLogicalOperator.ALL,
groups: [],
}
// Build the query
let query = this.options.query
if (!query && this.features.supportsSearch) {
query = buildQuery(filter || defaultQuery)
query = buildQuery(filter)
}
// Update store

View File

@ -574,12 +574,7 @@ export const buildQueryLegacy = (
export const buildQuery = (
filter?: SearchFilterGroup | SearchFilter[]
): SearchFilters | undefined => {
const parsedFilter: SearchFilterGroup | undefined =
processSearchFilters(filter)
if (!parsedFilter) {
return
}
const parsedFilter: SearchFilterGroup = processSearchFilters(filter)
const operatorMap: { [key in FilterGroupLogicalOperator]: LogicalOperator } =
{

View File

@ -98,16 +98,17 @@ export function trimOtherProps(object: any, allowedProps: string[]) {
*/
export const processSearchFilters = (
filters: SearchFilter[] | SearchFilterGroup | undefined
): SearchFilterGroup | undefined => {
if (!filters) {
return
}
): SearchFilterGroup => {
// Base search config.
const defaultCfg: SearchFilterGroup = {
logicalOperator: FilterGroupLogicalOperator.ALL,
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
groups: [],
}
if (!filters) {
return defaultCfg
}
const filterWhitelistKeys = [
"field",
"operator",
@ -182,7 +183,7 @@ export const processSearchFilters = (
return migratedSetting
} else if (!filters?.groups) {
return
return defaultCfg
}
return filters
}