PR comments.

This commit is contained in:
mike12345567 2024-10-01 11:31:41 +01:00
parent 119767a30e
commit 522941abf0
2 changed files with 10 additions and 18 deletions

View File

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

View File

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