Skip to content

fix(case): child at risk checkbox being set to array [CHI-3321] #2957

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GPaoloni
Copy link
Collaborator

@GPaoloni GPaoloni commented May 7, 2025

TODO:

  • On top of the fixes of this PR, we need to "patch" the existing broken cases. @stephenhand could you review this query and let me know if you think it's good to go?
    UPDATE public."Cases"
    SET "info" = jsonb_set("info", '{childIsAtRisk}', '"true"', false)
    WHERE "accountSid" = 'ACxxx' AND "info"->>'childIsAtRisk' = '["on"]';
    

Description

This PR fixes the bug described in the ticket linked below, where checkin the "child at risk" checkbox might end setting it's value as ['on'] or [ ], rather than the expected true/fase values.

The root cause seems to be how react hooks forms registers a component: if multiple checkbox components are registered under the same name, it's internal value will be set to an array. The exact cause of why this is being registered multiple times is not clear to me, but the changes I've made in this PR fix the issue since the initial values are set only once to the working copy, when the form component mounts. On top of this, I think the internal form using workingCopy as the initial value could cause some issues, as the first mount won't have a working copy at all.

To replicate the bug:

  • Create a new case.
  • Edit the overview, by setting "child at risk" to true. Save.
  • Edit the overview, by setting "child at risk" to false. Save.
  • If you open the edit overview page again, you'll notice that, even when the checkbox should be unchecked, it will be checked this time.
    • The internal rhf state will contain a broken array value when it should be false.
  • Save without any further changes. Now your case will be in the broken ['on'] state.

You should be able to replicate this bug in master but not in this branch.

Checklist

Other Related Issues

None

Verification steps

AFTER YOU MERGE

  1. Cut a release tag using the Github workflow. Wait for it to complete and notify in the #aselo-deploys Slack channel.
  2. Comment on the ticket with the release tag version AND any additional instructions required to configure an environment to test the changes.
  3. Only then move the ticket into the QA column in JIRA

You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P

@GPaoloni GPaoloni requested review from stephenhand and mythilytm and removed request for stephenhand May 7, 2025 21:14
@GPaoloni GPaoloni marked this pull request as ready for review May 7, 2025 21:21
@GPaoloni GPaoloni requested a review from stephenhand May 8, 2025 18:50
Copy link
Collaborator

@mythilytm mythilytm left a comment

Choose a reason for hiding this comment

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

Neat, was able to replicate the bug and see the fix works

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.

2 participants