PR comments.
This commit is contained in:
parent
119767a30e
commit
522941abf0
|
@ -163,9 +163,6 @@ export function recurseSearchFilters(
|
||||||
* https://github.com/Budibase/budibase/issues/10118
|
* https://github.com/Budibase/budibase/issues/10118
|
||||||
*/
|
*/
|
||||||
export const cleanupQuery = (query: SearchFilters) => {
|
export const cleanupQuery = (query: SearchFilters) => {
|
||||||
if (!query) {
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
for (let filterField of NoEmptyFilterStrings) {
|
for (let filterField of NoEmptyFilterStrings) {
|
||||||
if (!query[filterField]) {
|
if (!query[filterField]) {
|
||||||
continue
|
continue
|
||||||
|
@ -599,7 +596,7 @@ export const buildQuery = (
|
||||||
const globalOperator: LogicalOperator =
|
const globalOperator: LogicalOperator =
|
||||||
operatorMap[parsedFilter.logicalOperator as FilterGroupLogicalOperator]
|
operatorMap[parsedFilter.logicalOperator as FilterGroupLogicalOperator]
|
||||||
|
|
||||||
const coreRequest: SearchFilters = {
|
return {
|
||||||
...(globalOnEmpty ? { onEmptyFilter: globalOnEmpty } : {}),
|
...(globalOnEmpty ? { onEmptyFilter: globalOnEmpty } : {}),
|
||||||
[globalOperator]: {
|
[globalOperator]: {
|
||||||
conditions: parsedFilter.groups?.map((group: SearchFilterGroup) => {
|
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
|
// 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 we convert them to arrays at the controller level so that nothing below
|
||||||
// this has to worry about the non-array values.
|
// this has to worry about the non-array values.
|
||||||
export function fixupFilterArrays(filters: SearchFilters) {
|
export function fixupFilterArrays(filters: SearchFilters) {
|
||||||
if (!filters) {
|
|
||||||
return filters
|
|
||||||
}
|
|
||||||
for (const searchField of Object.values(ArrayOperator)) {
|
for (const searchField of Object.values(ArrayOperator)) {
|
||||||
const field = filters[searchField]
|
const field = filters[searchField]
|
||||||
if (field == null || !isPlainObject(field)) {
|
if (field == null || !isPlainObject(field)) {
|
||||||
|
|
|
@ -11,10 +11,7 @@ import { removeKeyNumbering } from "./filters"
|
||||||
|
|
||||||
// an array of keys from filter type to properties that are in the type
|
// an array of keys from filter type to properties that are in the type
|
||||||
// this can then be converted using .fromEntries to an object
|
// this can then be converted using .fromEntries to an object
|
||||||
type WhitelistedFilters = [
|
type AllowedFilters = [keyof LegacyFilter, LegacyFilter[keyof LegacyFilter]][]
|
||||||
keyof LegacyFilter,
|
|
||||||
LegacyFilter[keyof LegacyFilter]
|
|
||||||
][]
|
|
||||||
|
|
||||||
export function unreachable(
|
export function unreachable(
|
||||||
value: never,
|
value: never,
|
||||||
|
@ -141,7 +138,7 @@ export const processSearchFilters = (
|
||||||
groups: [],
|
groups: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const filterWhitelistKeys = [
|
const filterAllowedKeys = [
|
||||||
"field",
|
"field",
|
||||||
"operator",
|
"operator",
|
||||||
"value",
|
"value",
|
||||||
|
@ -181,10 +178,10 @@ export const processSearchFilters = (
|
||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
|
||||||
const whiteListedFilterSettings: WhitelistedFilters =
|
const allowedFilterSettings: AllowedFilters = filterPropertyKeys.reduce(
|
||||||
filterPropertyKeys.reduce((acc: WhitelistedFilters, key) => {
|
(acc: AllowedFilters, key) => {
|
||||||
const value = filter[key]
|
const value = filter[key]
|
||||||
if (filterWhitelistKeys.includes(key)) {
|
if (filterAllowedKeys.includes(key)) {
|
||||||
if (key === "field") {
|
if (key === "field") {
|
||||||
acc.push([key, removeKeyNumbering(value)])
|
acc.push([key, removeKeyNumbering(value)])
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,10 +189,12 @@ export const processSearchFilters = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return acc
|
return acc
|
||||||
}, [])
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
const migratedFilter: LegacyFilter = Object.fromEntries(
|
const migratedFilter: LegacyFilter = Object.fromEntries(
|
||||||
whiteListedFilterSettings
|
allowedFilterSettings
|
||||||
) as LegacyFilter
|
) as LegacyFilter
|
||||||
|
|
||||||
baseGroup.filters!.push(migratedFilter)
|
baseGroup.filters!.push(migratedFilter)
|
||||||
|
|
Loading…
Reference in New Issue