-
Notifications
You must be signed in to change notification settings - Fork 8
PLU-345: FormSG table field #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevinkim-ogp
merged 12 commits into
trunk/for-each
from
feat/for-each/formsg-table-support
Jul 28, 2025
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
96c098b
feat: enable for-each support for formsg table
kevinkim-ogp fae468a
refactor and fix bug showing for-each item value
kevinkim-ogp f6d7a71
chore: do not open modal on 0 rows
kevinkim-ogp 94588ec
chore: get table object for mock data, refactor function to create ta…
kevinkim-ogp deea0a0
chore: add inputSource to form table field object
kevinkim-ogp 61d475b
fix: test result check for no table rows
kevinkim-ogp 0b57665
fix: handle missing fieldData.answer in old forms
kevinkim-ogp 587247e
chore: use column names in preview if no commas
kevinkim-ogp fa132cc
chore: refactor for each table sources to constant
kevinkim-ogp 5a8a377
chore: refactor table data check
kevinkim-ogp 6013083
fix failing tests
kevinkim-ogp 315d263
chore: address copilot suggestions
kevinkim-ogp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/backend/src/apps/formsg/common/process-table-field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { FOR_EACH_INPUT_SOURCE } from '@/apps/toolbox/common/constants' | ||
|
|
||
| import { extractLastTopLevelBracketContent } from '../triggers/new-submission/get-data-out-metadata' | ||
|
|
||
| type TableColumn = { | ||
| id: string | ||
| label: string | ||
| name: string | ||
| value: string | ||
| } | ||
|
|
||
| const createColumn = (label: string): TableColumn => { | ||
| const id = Buffer.from(label).toString('hex') | ||
| return { | ||
| id, | ||
| label, | ||
| name: label, | ||
| value: `data.rows.*.data.${id}`, | ||
| } | ||
| } | ||
|
|
||
| export default function convertTableAnswerArrayToTableObject( | ||
| question: string, | ||
| answerArray: string[][], | ||
| ) { | ||
| const { content: columnNames } = extractLastTopLevelBracketContent(question) | ||
| const columnNamesArray = columnNames.split(',').map((name) => name.trim()) | ||
|
|
||
| const columns = | ||
| // make sure that column names do not contain commas | ||
| columnNamesArray.length === answerArray[0].length | ||
| ? columnNamesArray.map(createColumn) | ||
| : answerArray[0].map((_, index) => createColumn(`Col ${index + 1}`)) | ||
|
|
||
| /** | ||
| * NOTE: we do not show table rows that do not have any data | ||
| */ | ||
| const rows = (answerArray as string[][]) | ||
| .filter((row) => !row.every((v) => v === '')) | ||
| .map((row) => { | ||
| const rowData: Record<string, string | number> = {} | ||
| row.forEach((v: string, i: number) => { | ||
| rowData[columns[i].id] = v.replaceAll('\u0000', '') | ||
kevinkim-ogp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| return { data: rowData } | ||
| }) | ||
|
|
||
| return JSON.stringify({ | ||
| rows, | ||
| columns, | ||
| inputSource: FOR_EACH_INPUT_SOURCE.FORMSG_TABLE, | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.