ValueIsSet criteria mode (#9815)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-09-09 22:52:16 +07:00
committed by GitHub
parent cb3ef3401a
commit eb9150541b
20 changed files with 96 additions and 72 deletions
+13 -1
View File
@@ -20,6 +20,7 @@ export interface Mode {
label: IntlString
query: QuerySelector<any> | string
parse?: (value: any) => any
withoutEditor?: boolean
}
const Equal: Mode = {
@@ -46,6 +47,13 @@ const LT: Mode = {
query: { $lt: '$val' as any }
}
const Exists: Mode = {
id: 'exists',
label: view.string.ValueIsSet,
query: { $exists: true },
withoutEditor: true
}
const StringContains: Mode = {
id: 'contains',
label: view.string.Contains,
@@ -105,6 +113,7 @@ const ArraySizeLte: Mode = {
}
export const Modes: Record<string, Mode> = {
Exists,
Equal,
NotEqual,
StringContains,
@@ -133,7 +142,10 @@ export function parseValue (modes: Mode[], value: any): [any, Mode] {
while (typeof obj1 === 'object' && typeof obj2 === 'object' && Object.keys(obj1)[0] === Object.keys(obj2)[0]) {
const key1 = Object.keys(obj1)[0]
const key2 = Object.keys(obj2)[0]
if (typeof obj1[key1] === 'string' && (typeof obj2[key2] !== 'object' || Array.isArray(obj2[key2]))) {
if (
['string', 'boolean'].includes(typeof obj1[key1]) &&
(typeof obj2[key2] !== 'object' || Array.isArray(obj2[key2]))
) {
if (mode.parse !== undefined) {
return [mode.parse(obj2[key2]), mode]
}