Date filter freeze fix (#9635)
* Filter with enrichedSchemaFields * Handle empty object values in date range
This commit is contained in:
parent
8c55cafbd8
commit
fb74956c93
|
@ -101,7 +101,7 @@
|
|||
}
|
||||
|
||||
const getSchema = filter => {
|
||||
return schemaFields.find(field => field.name === filter.field)
|
||||
return enrichedSchemaFields.find(field => field.name === filter.field)
|
||||
}
|
||||
|
||||
const santizeTypes = filter => {
|
||||
|
|
|
@ -243,6 +243,19 @@ class InternalBuilder {
|
|||
}
|
||||
if (filters.range) {
|
||||
iterate(filters.range, (key, value) => {
|
||||
const isEmptyObject = (val: any) => {
|
||||
return (
|
||||
val &&
|
||||
Object.keys(val).length === 0 &&
|
||||
Object.getPrototypeOf(val) === Object.prototype
|
||||
)
|
||||
}
|
||||
if (isEmptyObject(value.low)) {
|
||||
value.low = ""
|
||||
}
|
||||
if (isEmptyObject(value.high)) {
|
||||
value.high = ""
|
||||
}
|
||||
if (value.low && value.high) {
|
||||
// Use a between operator if we have 2 valid range values
|
||||
const fnc = allOr ? "orWhereBetween" : "whereBetween"
|
||||
|
|
|
@ -553,4 +553,42 @@ describe("SQL query builder", () => {
|
|||
sql: `select * from (select top (@p0) * from [${tableName}] where LOWER([${tableName}].[name]) LIKE @p1) as [${tableName}]`,
|
||||
})
|
||||
})
|
||||
|
||||
it("should ignore high range value if it is an empty object", () => {
|
||||
const query = sql._query(
|
||||
generateReadJson({
|
||||
filters: {
|
||||
range: {
|
||||
dob: {
|
||||
low: "2000-01-01 00:00:00",
|
||||
high: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
expect(query).toEqual({
|
||||
bindings: ["2000-01-01 00:00:00", 500],
|
||||
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" > $1 limit $2) as \"${TABLE_NAME}\"`,
|
||||
})
|
||||
})
|
||||
|
||||
it("should ignore low range value if it is an empty object", () => {
|
||||
const query = sql._query(
|
||||
generateReadJson({
|
||||
filters: {
|
||||
range: {
|
||||
dob: {
|
||||
low: {},
|
||||
high: "2010-01-01 00:00:00",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
expect(query).toEqual({
|
||||
bindings: ["2010-01-01 00:00:00", 500],
|
||||
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"dob\" < $1 limit $2) as \"${TABLE_NAME}\"`,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue