Merge pull request #14904 from Budibase/fix-filter-query-conversion
Account for logicalOperator inside UISearchFilter groups
This commit is contained in:
commit
7d7dd31241
|
@ -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)(
|
||||
|
|
|
@ -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) },
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue