Skip to content

Commit 24dc528

Browse files
authored
fix: accept null values in for each row data (#1128)
## Problem For each 'Check step' fails when row data contains `null` values. This was caused by zod validator only accepting `string` or `number`. ## Solution Update schema to accept `string`, `number`, `null` and defaults to `null` to be safe. ## How to test? - Existing functionalities work in for each - [ ] FormSG table field is still processed as intended - [ ] FormSG checkboxes are still processed as intended - [ ] Excel row data is processed as intended - Row data with `null` values work - Modify the _data_out_ of the find multiple rows: change one or more values to `null` - Use that as the input of the for each - [ ] Items are processed correctly when running 'Check step' at for each - [ ] Columns are displayed correctly
1 parent f2e3a24 commit 24dc528

File tree

3 files changed

+13
-3
lines changed
  • packages
    • backend/src/apps
    • frontend/src/components/VariablesList

3 files changed

+13
-3
lines changed

packages/backend/src/apps/tiles/actions/find-multiple-rows/schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { z } from 'zod'
22

3+
export const tableRowDataSchema = z.record(
4+
z.string(),
5+
z.union([z.string(), z.number(), z.null()]).default(null),
6+
)
7+
38
const tableRowOutputSchema = z.object({
49
rowId: z.string(),
510
// for tiles v1, empty cells is either an empty string or wont even have their key returned
611
// for tiles v2, empty cells return null
7-
data: z.record(z.string(), z.union([z.string(), z.number(), z.null()])),
12+
data: tableRowDataSchema,
813
})
914

1015
export const dataOutSchema = z.object({

packages/backend/src/apps/toolbox/actions/for-each/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { z } from 'zod'
22

3+
import { tableRowDataSchema } from '@/apps/tiles/actions/find-multiple-rows/schema'
4+
35
import {
46
FOR_EACH_INPUT_SOURCE,
57
FOR_EACH_TABLE_SOURCES,
@@ -15,7 +17,7 @@ const tableColumnsSchema = z.array(
1517

1618
const tableRowsSchema = z.array(
1719
z.object({
18-
data: z.record(z.string(), z.string().or(z.number())),
20+
data: tableRowDataSchema,
1921
rowId: z.string().optional(), // only for tiles
2022
}),
2123
)

packages/frontend/src/components/VariablesList/schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const RowDataSchema = z.object({
77
z.object({
88
// for tiles v1, empty cells is either an empty string or wont even have their key returned
99
// for tiles v2, empty cells return null
10-
data: z.record(z.string(), z.union([z.string(), z.number(), z.null()])),
10+
data: z.record(
11+
z.string(),
12+
z.union([z.string(), z.number(), z.null()]).default(null),
13+
),
1114
rowId: z.string().optional(), // only Tiles will have this
1215
}),
1316
),

0 commit comments

Comments
 (0)