Skip to content
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

Repeater pattern component #336

Merged
merged 65 commits into from
Jan 16, 2025
Merged

Repeater pattern component #336

merged 65 commits into from
Jan 16, 2025

Conversation

ethangardner
Copy link
Contributor

Added the repeater pattern with basic support for the available question types at the start of the sprint (short answer and radio group).

There is a bug in the form submission side where the thank you page flashes briefly, and then re-renders the form fields with the user input, so the summary table on the results page was turned off for now.

@ethangardner ethangardner self-assigned this Oct 14, 2024
Copy link

github-actions bot commented Oct 14, 2024

Terraform plan for tts-10x-atj-dev

Plan: 0 to add, 2 to change, 0 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
!~  update in-place

Terraform will perform the following actions:

  # cloudfoundry_app.tts-10x-atj-dev-server-doj_tts-10x-atj-dev-server-doj-app_380DB029 will be updated in-place
!~  resource "cloudfoundry_app" "tts-10x-atj-dev-server-doj_tts-10x-atj-dev-server-doj-app_380DB029" {
!~      docker_image                    = "ghcr.io/gsa-tts/atj-platform/server-doj:afbde7f1d70c4920d82fa504c9f73bf879af14ed" -> "ghcr.io/gsa-tts/atj-platform/server-doj:ba304df413a515b2a0522f0504b10e2825f59d2e"
        id                              = "6246c063-6cf4-423d-812a-4bfdeb62bcae"
        name                            = "tts-10x-atj-dev-server-doj-app"
#        (17 unchanged attributes hidden)

#        (3 unchanged blocks hidden)
    }

  # cloudfoundry_app.tts-10x-atj-dev-server-kansas_tts-10x-atj-dev-server-kansas-app_337A9CF1 will be updated in-place
!~  resource "cloudfoundry_app" "tts-10x-atj-dev-server-kansas_tts-10x-atj-dev-server-kansas-app_337A9CF1" {
!~      docker_image                    = "ghcr.io/gsa-tts/atj-platform/server-kansas:afbde7f1d70c4920d82fa504c9f73bf879af14ed" -> "ghcr.io/gsa-tts/atj-platform/server-kansas:ba304df413a515b2a0522f0504b10e2825f59d2e"
        id                              = "f7c60971-bffd-4a6e-a0bb-af1191079918"
        name                            = "tts-10x-atj-dev-server-kansas-app"
#        (17 unchanged attributes hidden)

#        (3 unchanged blocks hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

📝 Plan generated in Post Terraform plan to PR comment #346

<button
type="button"
className="usa-button usa-button--outline"
onClick={() => append({})}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it'd be possible to make these submit buttons, so we could support adding/removing fields when Javascript is disabled?

I'm not really sure how we'd do that server-side...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danielnaab - I think that sounds doable. I can add a value to the button that would distinguish between the submit events that were triggered by the add/delete actions vs. the one the user would press if they mean to submit and finalize the form. There would need to be a check for this on the backend. What kind of data would you want for this check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow, it'd need to be checked for in the submitForm service - forms/src/services/submit-form.ts. This might be something better done after plugin/pattern refactoring. Could we create a ticket to loop back and progressively enhance this later?

@ethangardner ethangardner marked this pull request as ready for review October 17, 2024 19:01
@ethangardner
Copy link
Contributor Author

Wrote some better tests for the repeater component to test the add/remove feature. Changed the button in that component to submit with a value so we can do the backend part to handle the JS disabled use case.

Copy link
Contributor

@danielnaab danielnaab left a comment

Choose a reason for hiding this comment

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

This is a great set-up that should serve us well! I have a couple comments on how the pattern wires the IDs and session data up.

<button
type="button"
className="usa-button usa-button--outline"
onClick={() => append({})}
Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow, it'd need to be checked for in the submitForm service - forms/src/services/submit-form.ts. This might be something better done after plugin/pattern refactoring. Could we create a ticket to loop back and progressively enhance this later?

packages/design/src/Form/components/Repeater/index.tsx Outdated Show resolved Hide resolved
@@ -10,6 +10,7 @@ import { type FormSession, nullSession, sessionIsComplete } from './session.js';
export type TextInputProps = PatternProps<{
type: 'input';
inputId: string;
idSuffix?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little uncomfortable passing this detail into the UI components. Is there a way we could have the repeater pattern append the suffix directly to the ID in its createPrompt function?

const children = pattern.data.patterns.map((patternId: string) => {
const childPattern = getPattern(session.form, patternId);
return createPromptForPattern(config, session, childPattern, options);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If the idSuffix were appended to the child IDs here, would that remove the need for the cloneElement logic in the repeater component?

Copy link
Contributor

Choose a reason for hiding this comment

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

One more question. As I understand, the value of each child pattern is stored as a repeater attribute on the child pattern's session data. Is that right?

If so, I'm wondering if altering the structure of the child pattern's user data might be confusing down the road, and if it would be more clear to store user session data on the repeater pattern's session object. So essentially, the repeater's value might be something like:

[
  {"patternIdA": "first row a", "patternIdB": "first row b"},
  {"patternIdA": "second row a", "patternIdB": "second row b"},
  {"patternIdA": "third row a", "patternIdB": "third row b"},
]

@jimmoffet jimmoffet mentioned this pull request Nov 19, 2024
21 tasks
@ethangardner ethangardner force-pushed the feature/310-repeater-component branch from 6eeea85 to e959ed3 Compare December 5, 2024 22:06
Copy link

github-actions bot commented Dec 5, 2024

Terraform plan for tts-10x-atj-dev

Error: reading SSM Parameter (/tts-10x-atj-dev/cloudfoundry/password): couldn't find resource
Error: reading SSM Parameter (/tts-10x-atj-dev/cloudfoundry/password): couldn't find resource

  with data.aws_ssm_parameter.tts-10x-atj-dev-cloudfoundry-password,
  on cdk.tf.json line 21, in data.aws_ssm_parameter.tts-10x-atj-dev-cloudfoundry-password:
  21:       },


Error: reading SSM Parameter (/tts-10x-atj-dev/cloudfoundry/username): couldn't find resource

  with data.aws_ssm_parameter.tts-10x-atj-dev-cloudfoundry-username,
  on cdk.tf.json line 30, in data.aws_ssm_parameter.tts-10x-atj-dev-cloudfoundry-username:
  30:       },


Error: reading SSM Parameter (/tts-10x-atj-dev/server-doj/login.gov/private-key): couldn't find resource

  with data.aws_ssm_parameter.tts-10x-atj-dev_--tts-10x-atj-dev--server-doj--logingov--private-key_AB53082F,
  on cdk.tf.json line 39, in data.aws_ssm_parameter.tts-10x-atj-dev_--tts-10x-atj-dev--server-doj--logingov--private-key_AB53082F:
  39:       },


Error: reading SSM Parameter (/tts-10x-atj-dev/server-kansas/login.gov/private-key): couldn't find resource

  with data.aws_ssm_parameter.tts-10x-atj-dev_--tts-10x-atj-dev--server-kansas--logingov--private-key_510CC52A,
  on cdk.tf.json line 48, in data.aws_ssm_parameter.tts-10x-atj-dev_--tts-10x-atj-dev--server-kansas--logingov--private-key_510CC52A:
  48:       }

❌ Failed to generate plan in Post Terraform plan to PR comment #605

@kalasgarov kalasgarov force-pushed the feature/310-repeater-component branch 2 times, most recently from 8bb9283 to 14b55ad Compare January 6, 2025 23:40
@kalasgarov kalasgarov self-assigned this Jan 6, 2025
@kalasgarov kalasgarov force-pushed the feature/310-repeater-component branch 2 times, most recently from 3a86d84 to 435beaa Compare January 8, 2025 17:56
@kalasgarov kalasgarov force-pushed the feature/310-repeater-component branch from 435beaa to d2a2581 Compare January 10, 2025 18:51
@kalasgarov kalasgarov force-pushed the feature/310-repeater-component branch 2 times, most recently from b32846a to cc07eb7 Compare January 13, 2025 22:51
@danielnaab danielnaab force-pushed the feature/310-repeater-component branch from cc07eb7 to 74c3300 Compare January 14, 2025 15:32
Copy link

github-actions bot commented Jan 15, 2025

Terraform plan for tts-10x-forms-dev

Plan: 0 to add, 1 to change, 0 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
!~  update in-place

Terraform will perform the following actions:

  # cloudfoundry_app.tts-10x-forms-dev-server-doj_tts-10x-forms-dev-server-doj-app_22D74DC4 will be updated in-place
!~  resource "cloudfoundry_app" "tts-10x-forms-dev-server-doj_tts-10x-forms-dev-server-doj-app_22D74DC4" {
!~      docker_image                    = "ghcr.io/gsa-tts/forms/server-doj:7b27866b5e7b71194f3c00ea3e958dd9e42f0bca" -> "ghcr.io/gsa-tts/forms/server-doj:7873012fab862fe76f76b23efc258b7fa208141f"
        id                              = "29c93a0a-519c-454a-847e-cc603395c2da"
        name                            = "tts-10x-forms-dev-server-doj-app"
#        (17 unchanged attributes hidden)

#        (3 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

📝 Plan generated in Post Terraform plan to PR comment #622

@kalasgarov kalasgarov force-pushed the feature/310-repeater-component branch from f9ffd39 to ae95dba Compare January 15, 2025 23:09
Copy link
Contributor

@danielnaab danielnaab left a comment

Choose a reason for hiding this comment

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

Great work, let's merge!

For reference, we'll follow-up with some underlying refactors, including #442 and #441

@kalasgarov kalasgarov merged commit 7c2e9c5 into main Jan 16, 2025
4 checks passed
@kalasgarov kalasgarov deleted the feature/310-repeater-component branch January 16, 2025 18:17
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