From 721b3ab6107aa628398b2aa4bf07e4e4330a3631 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 12:56:41 +0000 Subject: [PATCH 1/3] Account for logicalOperator inside UISearchFilter groups --- packages/shared-core/src/filters.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 003e6b5082..7720fe2b8d 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -488,7 +488,13 @@ export function buildQuery( if (onEmptyFilter) { query.onEmptyFilter = onEmptyFilter } - const operator = allOr ? LogicalOperator.OR : LogicalOperator.AND + + // logicalOperator takes precendence over allOr + let operator = allOr ? LogicalOperator.OR : LogicalOperator.AND + if (group.logicalOperator) { + operator = logicalOperatorFromUI(group.logicalOperator) + } + return { [operator]: { conditions: filters.map(buildCondition).filter(f => f) }, } From 765b3d2f9796e83ad44262b01b03a6e59bff27c9 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 15:10:02 +0000 Subject: [PATCH 2/3] Add tests for handling logical operators in UISearchFilter --- .../src/api/routes/tests/viewV2.spec.ts | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 44e5875b7e..1f7000fe43 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -4298,6 +4298,97 @@ describe.each([ }, ], }, + { + name: "can handle logical operator any", + insert: [{ string: "bar" }, { string: "foo" }], + query: { + groups: [ + { + logicalOperator: UILogicalOperator.ANY, + filters: [ + { + operator: BasicOperator.EQUAL, + field: "string", + value: "foo", + }, + { + operator: BasicOperator.EQUAL, + field: "string", + value: "bar", + }, + ], + }, + ], + }, + searchOpts: { + sort: "string", + sortOrder: SortOrder.ASCENDING, + }, + expected: [{ string: "bar" }, { string: "foo" }], + }, + { + name: "can handle logical operator all", + insert: [ + { string: "bar", num: 1 }, + { string: "foo", num: 2 }, + ], + query: { + groups: [ + { + logicalOperator: UILogicalOperator.ALL, + filters: [ + { + operator: BasicOperator.EQUAL, + field: "string", + value: "foo", + }, + { + operator: BasicOperator.EQUAL, + field: "num", + value: 2, + }, + ], + }, + ], + }, + searchOpts: { + sort: "string", + sortOrder: SortOrder.ASCENDING, + }, + expected: [{ string: "foo", num: 2 }], + }, + { + name: "overrides allOr with logical operators", + insert: [ + { string: "bar", num: 1 }, + { string: "foo", num: 1 }, + ], + query: { + groups: [ + { + logicalOperator: UILogicalOperator.ALL, + filters: [ + { operator: "allOr" }, + { + operator: BasicOperator.EQUAL, + field: "string", + value: "foo", + }, + { + operator: BasicOperator.EQUAL, + field: "num", + value: 1, + }, + ], + }, + ], + }, + searchOpts: { + sort: "string", + sortOrder: SortOrder.ASCENDING, + }, + expected: [{ string: "foo", num: 1 }], + }, ] it.each(testCases)( From 599370b6ed85f6d8c25257f7e6ab4d50e153f97d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 15:19:32 +0000 Subject: [PATCH 3/3] Update tests --- .../server/src/api/routes/tests/viewV2.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 1f7000fe43..15b9a29e11 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -4329,8 +4329,8 @@ describe.each([ { name: "can handle logical operator all", insert: [ - { string: "bar", num: 1 }, - { string: "foo", num: 2 }, + { string: "bar", number: 1 }, + { string: "foo", number: 2 }, ], query: { groups: [ @@ -4344,7 +4344,7 @@ describe.each([ }, { operator: BasicOperator.EQUAL, - field: "num", + field: "number", value: 2, }, ], @@ -4355,13 +4355,13 @@ describe.each([ sort: "string", sortOrder: SortOrder.ASCENDING, }, - expected: [{ string: "foo", num: 2 }], + expected: [{ string: "foo", number: 2 }], }, { name: "overrides allOr with logical operators", insert: [ - { string: "bar", num: 1 }, - { string: "foo", num: 1 }, + { string: "bar", number: 1 }, + { string: "foo", number: 1 }, ], query: { groups: [ @@ -4376,7 +4376,7 @@ describe.each([ }, { operator: BasicOperator.EQUAL, - field: "num", + field: "number", value: 1, }, ], @@ -4387,7 +4387,7 @@ describe.each([ sort: "string", sortOrder: SortOrder.ASCENDING, }, - expected: [{ string: "foo", num: 1 }], + expected: [{ string: "foo", number: 1 }], }, ]