diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 18ce4b6ed7..b10375acb0 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -163,9 +163,6 @@ export function recurseSearchFilters( * https://github.com/Budibase/budibase/issues/10118 */ export const cleanupQuery = (query: SearchFilters) => { - if (!query) { - return query - } for (let filterField of NoEmptyFilterStrings) { if (!query[filterField]) { continue @@ -599,7 +596,7 @@ export const buildQuery = ( const globalOperator: LogicalOperator = operatorMap[parsedFilter.logicalOperator as FilterGroupLogicalOperator] - const coreRequest: SearchFilters = { + return { ...(globalOnEmpty ? { onEmptyFilter: globalOnEmpty } : {}), [globalOperator]: { conditions: parsedFilter.groups?.map((group: SearchFilterGroup) => { @@ -613,16 +610,12 @@ export const buildQuery = ( }), }, } - return coreRequest } // The frontend can send single values for array fields sometimes, so to handle // this we convert them to arrays at the controller level so that nothing below // this has to worry about the non-array values. export function fixupFilterArrays(filters: SearchFilters) { - if (!filters) { - return filters - } for (const searchField of Object.values(ArrayOperator)) { const field = filters[searchField] if (field == null || !isPlainObject(field)) { diff --git a/packages/shared-core/src/utils.ts b/packages/shared-core/src/utils.ts index b441791751..14b3c84425 100644 --- a/packages/shared-core/src/utils.ts +++ b/packages/shared-core/src/utils.ts @@ -11,10 +11,7 @@ import { removeKeyNumbering } from "./filters" // an array of keys from filter type to properties that are in the type // this can then be converted using .fromEntries to an object -type WhitelistedFilters = [ - keyof LegacyFilter, - LegacyFilter[keyof LegacyFilter] -][] +type AllowedFilters = [keyof LegacyFilter, LegacyFilter[keyof LegacyFilter]][] export function unreachable( value: never, @@ -141,7 +138,7 @@ export const processSearchFilters = ( groups: [], } - const filterWhitelistKeys = [ + const filterAllowedKeys = [ "field", "operator", "value", @@ -181,10 +178,10 @@ export const processSearchFilters = ( return acc } - const whiteListedFilterSettings: WhitelistedFilters = - filterPropertyKeys.reduce((acc: WhitelistedFilters, key) => { + const allowedFilterSettings: AllowedFilters = filterPropertyKeys.reduce( + (acc: AllowedFilters, key) => { const value = filter[key] - if (filterWhitelistKeys.includes(key)) { + if (filterAllowedKeys.includes(key)) { if (key === "field") { acc.push([key, removeKeyNumbering(value)]) } else { @@ -192,10 +189,12 @@ export const processSearchFilters = ( } } return acc - }, []) + }, + [] + ) const migratedFilter: LegacyFilter = Object.fromEntries( - whiteListedFilterSettings + allowedFilterSettings ) as LegacyFilter baseGroup.filters!.push(migratedFilter)