Skip to content

Commit 263ca75

Browse files
authored
HOTFIX: tile dynamodb isEmpty filter not respecting NULL values (#1249)
## Problem Our current isEmpty filter for Tiles v1 only checks for empty string and missing values (undefined). However, when manually updating rows on the Tile frontend, it sets the empty cells to NULL which is not satisfied by our filter. ## Solution Add NULL check to isEmpty filter
1 parent 6980d4d commit 263ca75

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/backend/src/models/tiles/dynamodb/__tests__/table-row/functions.itest.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,34 @@ describe('dynamodb table row functions', () => {
258258
expect(rows8.length).toEqual(1000)
259259
})
260260

261+
it('empty filter should work with empty string, null and undefined', async () => {
262+
const dataArray: any[] = []
263+
;['', null, 123, 'abc'].forEach((value, index) => {
264+
dataArray.push({
265+
a: `${index}`,
266+
b: value,
267+
})
268+
})
269+
dataArray.push({
270+
a: `undefined value`,
271+
})
272+
await createTableRows({ tableId: dummyTable.id, dataArray })
273+
274+
// Empty
275+
const { rows } = await getTableRows({
276+
tableId: dummyTable.id,
277+
columnIds: ['a', 'b'],
278+
filters: [
279+
{
280+
columnId: 'b',
281+
operator: TableRowFilterOperator.IsEmpty,
282+
value: '',
283+
},
284+
],
285+
})
286+
expect(rows.length).toEqual(3)
287+
})
288+
261289
it('should get relevant rows based on composite filters', async () => {
262290
const dataArray = []
263291
for (let i = 0; i < 1000; i++) {

packages/backend/src/models/tiles/dynamodb/table-row/functions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ const addFiltersToQuery = (
121121
): void => {
122122
if (filters?.length) {
123123
query.where(
124-
({ data }, { eq, begins, contains, gt, gte, lt, lte, notExists }) => {
124+
(
125+
{ data },
126+
{ eq, begins, contains, gt, gte, lt, lte, notExists, type },
127+
) => {
125128
const whereExpressions: string[] = []
126129
for (const filter of filters) {
127130
const { columnId, operator, value } = filter
@@ -150,7 +153,9 @@ const addFiltersToQuery = (
150153
break
151154
case TableRowFilterOperator.IsEmpty:
152155
whereExpressions.push(
153-
`(${eq(data[columnId], '')} OR ${notExists(data[columnId])})`,
156+
`(${eq(data[columnId], '')} OR ${notExists(
157+
data[columnId],
158+
)} OR ${type(data[columnId], 'NULL')})`,
154159
)
155160
break
156161
}

0 commit comments

Comments
 (0)