Skip to content

Conversation

@kevinkim-ogp
Copy link
Contributor

@kevinkim-ogp kevinkim-ogp commented Jun 24, 2025

NOTE: this is not a blocker for beta; intent is to release this while beta is happening

TL;DR

This PR adds support for FormSG table fields in the For-Each action, enabling users to iterate through table data from FormSG submissions.

What changed?

  • Added functionality to convert FormSG table field into table object to enable preview of row data and to use in for-each actions
  • Added a new input source type FORMSG_TABLE to the For-Each action
  • Updated the For-Each action to handle FormSG table fields, allowing iteration through table rows
  • Added test cases for the new table field functionality
  • Hide form cell values if there are no rows

How to test?

  1. Create a FormSG form with a table field
  2. Set up a workflow that uses the FormSG trigger
  • Mock data

    • Should still show the individual cell values as "Response X, Row 1 Column 1" etc
    • Should have preview in test result
    • Modal should show all columns in the table
    • Modal should show 2 rows of mock data with each column filled
  • Actual submission

    • Should show the individual cell values with column headers if headers do not contain commas, otherwise resort to default (Column 1, Column 2, etc.)
    • Should have preview in test result
      • Preview should column headers if headers do not contain commas, otherwise default column names
    • Modal should show all columns in the table
    • Modal should show correct rows of mock data with each column filled
  • Actual submission with no data

    • Should NOT show individual cell values
    • Should NOT be able to preview

Why make this change?

FormSG table fields contain structured data that users often need to process row by row. This change enables users to iterate through table rows in a FormSG submission, making it possible to perform actions on each row of data separately.

Screenshots

FormSG table preview
(can ignore the form connection issue, happens on local dev)

Preview with mock data

image.png

image.png

image.png

FormSG variable in for-each

image.png

Copy link
Contributor Author

kevinkim-ogp commented Jun 24, 2025

@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Jun 24, 2025

Datadog Report

Branch report: feat/for-each/formsg-table-support
Commit report: 587247e
Test service: plumber

✅ 0 Failed, 1011 Passed, 0 Skipped, 2m 57.99s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+0.07%)

@kevinkim-ogp kevinkim-ogp force-pushed the feat/for-each/formsg-table-support branch 2 times, most recently from ebecbae to 81ef243 Compare July 1, 2025 09:10
@kevinkim-ogp kevinkim-ogp force-pushed the chore/use-step-names-in-suggestions branch from 45bc702 to 73b11bd Compare July 1, 2025 09:10
@kevinkim-ogp kevinkim-ogp changed the title feat: enable for-each support for formsg table [FOR-EACH-12]: FormSG table field Jul 2, 2025
@kevinkim-ogp kevinkim-ogp changed the base branch from chore/use-step-names-in-suggestions to graphite-base/1069 July 7, 2025 07:46
@kevinkim-ogp kevinkim-ogp changed the title [FOR-EACH-12]: FormSG table field feat: FormSG table field Jul 8, 2025
@kevinkim-ogp kevinkim-ogp force-pushed the feat/for-each/formsg-table-support branch from f6e23ee to ef7a1db Compare July 10, 2025 05:55
@kevinkim-ogp kevinkim-ogp changed the base branch from graphite-base/1069 to fix/variable-replacement-single-selection July 10, 2025 05:55
@kevinkim-ogp kevinkim-ogp force-pushed the fix/variable-replacement-single-selection branch from e0d7696 to 1c9f16f Compare July 11, 2025 01:35
@kevinkim-ogp kevinkim-ogp marked this pull request as ready for review July 17, 2025 08:30
@kevinkim-ogp kevinkim-ogp requested a review from a team as a code owner July 17, 2025 08:30
Base automatically changed from trunk/for-each to develop-v2 July 17, 2025 08:53
@kevinkim-ogp kevinkim-ogp changed the base branch from develop-v2 to graphite-base/1069 July 18, 2025 02:00
@kevinkim-ogp kevinkim-ogp changed the base branch from graphite-base/1069 to trunk/for-each July 18, 2025 02:00
@kevinkim-ogp kevinkim-ogp force-pushed the feat/for-each/formsg-table-support branch 2 times, most recently from e3d9f86 to 0b57665 Compare July 22, 2025 03:21
@pregnantboy pregnantboy requested a review from Copilot July 23, 2025 07:14

This comment was marked as outdated.

Copy link
Contributor

@pregnantboy pregnantboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. works with 0 rows, deleted columns.

maybe refactor the isformtable check. too many if else cases

@kevinkim-ogp kevinkim-ogp requested a review from Copilot July 23, 2025 13:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for FormSG table fields in the For-Each action, enabling users to iterate through table data from FormSG submissions. The implementation converts FormSG table fields into structured table objects compatible with the existing For-Each functionality.

  • Adds FormSG table field processing to convert table data into a standardized format
  • Extends For-Each action to support FormSG table input source
  • Updates frontend to properly handle FormSG table field previews and empty table states

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/frontend/src/components/VariablesList/schema.ts Added FormSG table data parsing and schema validation
packages/frontend/src/components/VariablesList/TableVariableItem.tsx Added conditional modal opening for empty tables
packages/frontend/src/components/FlowStepTestController/utils.tsx Added FormSG table input source handling and parameter matching logic
packages/backend/src/apps/toolbox/common/constants.ts Added FORMSG_TABLE constant and table sources array
packages/backend/src/apps/toolbox/actions/for-each/schema.ts Extended schema to support FormSG table input source
packages/backend/src/apps/toolbox/actions/for-each/index.ts Updated action logic to handle FormSG table sources
packages/backend/src/apps/toolbox/actions/for-each/get-data-out-metadata.ts Updated metadata generation for FormSG table sources
packages/backend/src/apps/formsg/triggers/new-submission/get-mock-data.ts Added table object conversion for mock data
packages/backend/src/apps/formsg/triggers/new-submission/get-data-out-metadata.ts Added table metadata building and visibility logic
packages/backend/src/apps/formsg/common/process-table-field.ts New utility to convert FormSG table fields to structured format
packages/backend/src/apps/formsg/auth/decrypt-form-response.ts Added table field processing during response decryption

@datadog-opengovsg
Copy link

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 315d263 | Was this helpful? Give us feedback!

@kevinkim-ogp kevinkim-ogp merged commit e0d44a2 into trunk/for-each Jul 28, 2025
3 checks passed
@kevinkim-ogp kevinkim-ogp deleted the feat/for-each/formsg-table-support branch July 28, 2025 03:47
kevinkim-ogp added a commit that referenced this pull request Jul 28, 2025
*NOTE: this is not a blocker for beta; intent is to release this while
beta is happening*

### TL;DR
This PR adds support for FormSG table fields in the For-Each action,
enabling users to iterate through table data from FormSG submissions.

### What changed?
- Added functionality to convert FormSG table field into `table` object
to enable preview of row data and to use in for-each actions
- Added a new input source type `FORMSG_TABLE` to the For-Each action
- Updated the For-Each action to handle FormSG table fields, allowing
iteration through table rows
- Added test cases for the new table field functionality
- Hide form cell values if there are no rows

### How to test?

1. Create a FormSG form with a table field
2. Set up a workflow that uses the FormSG trigger

- [ ] Mock data
- [ ] Should still show the individual cell values as "Response X, Row 1
Column 1" etc
  - [ ] Should have preview in test result
  - [ ] Modal should show all columns in the table
  - [ ] Modal should show 2 rows of mock data with each column filled

- [ ] Actual submission
- [ ] Should show the individual cell values with column headers if
headers do not contain commas, otherwise resort to default (Column 1,
Column 2, etc.)
  - [ ] Should have preview in test result
- [ ] Preview should column headers if headers do not contain commas,
otherwise default column names
  - [ ] Modal should show all columns in the table
- [ ] Modal should show correct rows of mock data with each column
filled

- [ ] Actual submission with no data
  - [ ] Should NOT show individual cell values
  - [ ] Should NOT be able to preview

### Why make this change?
FormSG table fields contain structured data that users often need to
process row by row. This change enables users to iterate through table
rows in a FormSG submission, making it possible to perform actions on
each row of data separately.


### Screenshots
**FormSG table preview**
(can ignore the form connection issue, happens on local dev)


Preview with mock data



![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/Wrwhm8Mmhv1Z2GwlSb7V/227e3811-3030-4ff6-90a1-5e1e17007e25.png)



![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/Wrwhm8Mmhv1Z2GwlSb7V/809b1e6e-e972-4e28-96db-90ea44fa376f.png)



![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/Wrwhm8Mmhv1Z2GwlSb7V/2c0b6360-809d-4a7b-9119-e95fdb1c4e47.png)

**FormSG variable in for-each**



![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/Wrwhm8Mmhv1Z2GwlSb7V/50f98fc2-1bf4-4aa9-bd46-9d3ab478d7f7.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants