diff --git a/packages/server/src/sdk/app/rows/queryUtils.ts b/packages/server/src/sdk/app/rows/queryUtils.ts index 84fe05a948..9fa72e84d7 100644 --- a/packages/server/src/sdk/app/rows/queryUtils.ts +++ b/packages/server/src/sdk/app/rows/queryUtils.ts @@ -1,3 +1,4 @@ +import { db } from "@budibase/backend-core" import { isLogicalSearchOperator, SearchFilters } from "@budibase/types" import { cloneDeep } from "lodash/fp" @@ -31,7 +32,12 @@ export const removeInvalidFilters = ( const filter = result[filterKey] for (const columnKey of Object.keys(filter)) { if ( - !validFields.map(f => f.toLowerCase()).includes(columnKey.toLowerCase()) + !validFields + .map(f => f.toLowerCase()) + .includes(columnKey.toLowerCase()) && + !validFields + .map(f => f.toLowerCase()) + .includes(db.removeKeyNumbering(columnKey).toLowerCase()) ) { delete filter[columnKey] } diff --git a/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts b/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts index b3852da4c6..f249a8f91e 100644 --- a/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts +++ b/packages/server/src/sdk/app/rows/tests/queryUtils.spec.ts @@ -92,5 +92,58 @@ describe("query utils", () => { } expect(result).toEqual(expected) }) + + it("keeps filter key numering", () => { + const prefixedFilters: SearchFilters = { + equal: { "1:one": "foo" }, + $or: { + conditions: [ + { + equal: { "2:one": "foo2", "3:two": "bar" }, + notEmpty: { "4:one": null }, + $and: { + conditions: [ + { + equal: { "5:three": "baz", two: "bar2" }, + notEmpty: { forth: null }, + }, + ], + }, + }, + ], + }, + $and: { + conditions: [{ equal: { "6:one": "foo2" }, notEmpty: { one: null } }], + }, + } + + const result = removeInvalidFilters(prefixedFilters, [ + "one", + "three", + "forth", + ]) + expect(result).toEqual({ + equal: { "1:one": "foo" }, + $or: { + conditions: [ + { + equal: { "2:one": "foo2" }, + notEmpty: { "4:one": null }, + $and: { + conditions: [ + { + equal: { "5:three": "baz" }, + notEmpty: { forth: null }, + }, + ], + }, + }, + ], + }, + $and: { + conditions: [{ equal: { "6:one": "foo2" }, notEmpty: { one: null } }], + }, + }) + }) }) })