Merge pull request #14904 from Budibase/fix-filter-query-conversion

Account for logicalOperator inside UISearchFilter groups
This commit is contained in:
Andrew Kingston 2024-10-29 16:14:06 +00:00 committed by GitHub
commit 7d7dd31241
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 98 additions and 1 deletions

View File

@ -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", number: 1 },
{ string: "foo", number: 2 },
],
query: {
groups: [
{
logicalOperator: UILogicalOperator.ALL,
filters: [
{
operator: BasicOperator.EQUAL,
field: "string",
value: "foo",
},
{
operator: BasicOperator.EQUAL,
field: "number",
value: 2,
},
],
},
],
},
searchOpts: {
sort: "string",
sortOrder: SortOrder.ASCENDING,
},
expected: [{ string: "foo", number: 2 }],
},
{
name: "overrides allOr with logical operators",
insert: [
{ string: "bar", number: 1 },
{ string: "foo", number: 1 },
],
query: {
groups: [
{
logicalOperator: UILogicalOperator.ALL,
filters: [
{ operator: "allOr" },
{
operator: BasicOperator.EQUAL,
field: "string",
value: "foo",
},
{
operator: BasicOperator.EQUAL,
field: "number",
value: 1,
},
],
},
],
},
searchOpts: {
sort: "string",
sortOrder: SortOrder.ASCENDING,
},
expected: [{ string: "foo", number: 1 }],
},
]
it.each(testCases)(

View File

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