mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Flatten arrays after parsing filters (#9697)
Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
12
packages/shared/src/utils/flatten-arrays.ts
Normal file
12
packages/shared/src/utils/flatten-arrays.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { isObjectLike, flattenDeep } from 'lodash';
|
||||
|
||||
export function flattenArrays(obj: any) {
|
||||
for (const key in obj) {
|
||||
if (Array.isArray(obj[key])) {
|
||||
obj[key] = flattenDeep(obj[key]);
|
||||
} else if (isObjectLike(obj[key])) {
|
||||
obj[key] = flattenArrays(obj[key]);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { toArray } from './to-array';
|
||||
import { adjustDate } from './adjust-date';
|
||||
import { deepMap } from './deep-map';
|
||||
import { isDynamicVariable } from './is-dynamic-variable';
|
||||
import { flattenArrays } from './flatten-arrays';
|
||||
|
||||
type ParseFilterContext = {
|
||||
// The user can add any custom fields to user
|
||||
@@ -18,7 +19,7 @@ export function parseFilter(
|
||||
): any {
|
||||
if (!filter) return filter;
|
||||
|
||||
return deepMap(filter, applyFilter);
|
||||
return flattenArrays(deepMap(filter, applyFilter));
|
||||
|
||||
function applyFilter(val: any, key: string | number) {
|
||||
if (val === 'true') return true;
|
||||
|
||||
Reference in New Issue
Block a user