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

Refactor test card #6653

Merged
merged 80 commits into from
Oct 23, 2023
Merged

Refactor test card #6653

merged 80 commits into from
Oct 23, 2023

Conversation

mpbrown
Copy link
Collaborator

@mpbrown mpbrown commented Sep 28, 2023

FRONTEND PULL REQUEST

Related Issue

Changes Proposed

  • Adds a new TestCard component used instead of the existing QueueItem if the testCardRefactorEnabled feature flag is active.
  • TestCard uses a collapisble design which will display the TestCardForm as a child component when the card is expanded. TestCardForm is where the majority of the conduct tests business logic is used while TestCard primarily serves as the header and overall form container.
  • Currently the test cards are expanded by default to make it an easier transition for users unfamiliar with the new collapsible design, but this should be updated in the future.

AOE

  • Test questionnaire modal will no longer appear when starting a patient test from either the search bar or the patients page.
  • AOE questions will now be shown directly on the TestCardForm. The COVID AOE questions are used by default, but other disease specific AOE form components can be swapped when additional supported diseases are added.
  • Test result delivery preferences will no longer be included when saving AOE responses. The backend defaults to using whatever preferences the patient already has saved on their profile.

Test Results

  • The input groups for marking test results no longer use their own internal submit button.
  • The radio button options for results will now show as asterisk if it is required, such as when either some or all multiplex results are reburied for submission.
  • Error messages for missing test results are shown after the user attempts to submit the form. The submit button is no longer disabled for this reason.

Timer

  • Test timer design has been updated which will be present on both the new TestCard and existing QueueItem.

Additional Information

  • TestCardForm uses useReducer to manage the form state instead of multiple useState hooks. This was chosen because some state properties depend on each other or on the previous state and encapsulating this state management in a reducer with discrete dispatch actions improves the testability and readability of the main TestCardForm.
  • TestCardForm.utils contains some custom hooks and helper functions with the goal of balancing just enough abstraction to improve readability and understanding of how the test card works overall.

Testing

  • Test out the new changes on dev7.
  • Please specifically test out different states of the test card and try making fast changes or unexpected inputs to test the behavior of the form saving live changes and receiving any updates from the server.
    • Keep in mind that if someone else is testing on the same patient at the same time that may lead to unexpected but intentional behavior where an update from the server might overwrite a change you previously made.
  • Unit test suite for the new TestCard and TestCardForm is still in progress.

Screenshots / Demos

Multiplex with all results
image

Multiplex missing results
image

Flu only device and custom backdate
image

Incomplete AOE questions confirmation modal before submitting
image

Invalid test date
image

Collapsed view
image

@mpbrown mpbrown changed the title Mike/6079 refactor test card Refactor test card frontend changes Sep 28, 2023
@mpbrown mpbrown temporarily deployed to dev7 September 28, 2023 19:43 — with GitHub Actions Inactive
@mpbrown mpbrown temporarily deployed to dev7 September 28, 2023 19:46 — with GitHub Actions Inactive
@mpbrown mpbrown temporarily deployed to dev7 September 28, 2023 19:55 — with GitHub Actions Inactive
@mpbrown mpbrown changed the title Refactor test card frontend changes Refactor test card Sep 28, 2023
@mpbrown
Copy link
Collaborator Author

mpbrown commented Sep 29, 2023

FYI on dev7 I'm experiencing an unexpected 403 forbidden error when I try answering an AOE question, but this might just be related to needing to update my user permissions for my logged in organization on dev7 since answering and saving AOE works on local deployment.

@zdeveloper zdeveloper force-pushed the mike/6079-refactor-test-card branch from c31ac0f to bb43a29 Compare October 2, 2023 19:01
@zdeveloper zdeveloper force-pushed the mike/6079-refactor-test-card branch 4 times, most recently from 8fcf902 to 42c812e Compare October 11, 2023 19:57
@zdeveloper zdeveloper temporarily deployed to dev7 October 11, 2023 20:26 — with GitHub Actions Inactive
@zdeveloper zdeveloper temporarily deployed to dev7 October 11, 2023 20:37 — with GitHub Actions Inactive
@nathancrtr
Copy link
Contributor

I didn't see the ticket or design specify whether the test cards should default to the collapsed state or the expanded one. It looks like they're expanded by default? Just wanting to call this out to confirm 👍

Comment on lines +139 to +140
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [testOrder]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know I've had to disable this linting error before, but with how consistently we're ignoring it - is there a more correct way of doing this? Or can we update the linter to not complain about this if its not actually an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for mentioning this! After I looked into it a bit more, the React team strongly recommends keeping the rule and reworking the code to handle it properly. I'm experimenting with the code and we may be able to remove some of these useEffects entirely, so I'll create a follow up PR for this.

Some of this effect code will benefit significantly when React officially releases the new useEffectEvent hook on a stable version. For example, we need to control for race conditions between the frontend saving edits and the periodic live sync with any updates from the backend.

When we get new values from the backend, we have to check whether the mutations are still loading and although those loading booleans are reactive values that React says should be included in the dependency array, we don't want those in the array because then the effect will be triggered whenever those change and potentially cause sync issues.

useEffect(() => {
    // don't update if there are unsaved dirty changes or if still awaiting saved edits
    if (state.dirty || editQueueItemMutationLoading || updateAoeMutationLoading)
      return;
    dispatch({
      type: TestFormActionCase.UPDATE_WITH_CHANGES_FROM_SERVER,
      payload: testOrder,
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [testOrder]);

So once useEffectEvent is officially added, we'll be able to separate reactive values that are actual effect dependencies from ones that are only used for conditional logic.

@nathancrtr
Copy link
Contributor

nathancrtr commented Oct 20, 2023

It doesn't feel important to correct this under this particular ticket, but just calling out a little wonky layout behavior:

Screen Shot 2023-10-20 at 2 21 35 PM

This is in the case where a facility has its "default" device removed while a test card is open. And ditto, I guess, for doing the same with a device's default specimen type:

Screen Shot 2023-10-20 at 2 24 08 PM

Again, really nitpicky and best looked at elsewhere, IMO, just shouting it out for now.

DanielSass
DanielSass previously approved these changes Oct 20, 2023
@zdeveloper
Copy link
Contributor

It doesn't feel important to correct this under this particular ticket, but just calling out a little wonky layout behavior:

Screen Shot 2023-10-20 at 2 21 35 PM This is in the case where a facility has its "default" device removed while a test card is open. And ditto, I guess, for doing the same with a device's default specimen type: Screen Shot 2023-10-20 at 2 24 08 PM Again, really nitpicky and best looked at elsewhere, IMO, just shouting it out for now.

Yeah I agree, but this is a super edge case, especially with relying on automatic livdsync, I can see us never really deleting a device or specimen since we already corrected all of our devices info.

DanielSass
DanielSass previously approved these changes Oct 23, 2023
Copy link
Collaborator

@emyl3 emyl3 left a comment

Choose a reason for hiding this comment

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

Nice work, Mike! Left my first bunch of comments.

Do you have access to Deque's axe dev tool? I think it will be helpful to run particularly against multiple test cards in the conduct test page.

frontend/src/app/testQueue/TestCard/TestCard.tsx Outdated Show resolved Hide resolved
@@ -240,8 +242,10 @@ export const TestTimerWidget = ({ timer, context }: Props) => {
data-testid="timer"
aria-label="Start timer"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we pass in the patient's name so if there are multiple test timer buttons on a conduct page we know which person's test the timer is for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree this should be added on the aria label, although I think we should create a separate ticket for it since it'll also affect the existing queue item component which will still be used in prod until the new test card feature flag is enabled

frontend/src/app/testQueue/TestTimer.tsx Show resolved Hide resolved
@mpbrown mpbrown temporarily deployed to dev7 October 23, 2023 15:34 — with GitHub Actions Inactive
@mpbrown mpbrown temporarily deployed to dev7 October 23, 2023 15:46 — with GitHub Actions Inactive
@mpbrown
Copy link
Collaborator Author

mpbrown commented Oct 23, 2023

@emyl3 thanks for the reminder about the axe devtools extension! I pushed some updates that improve accessibility. Once the PR is approved, the design team will be conducting usability testing using the demo environment. The new test card feature flag will remain disabled in the prod environment

@mpbrown mpbrown requested a review from emyl3 October 23, 2023 19:06
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

81.0% 81.0% Coverage
2.8% 2.8% Duplication

const areAllResultsRequired =
isSomeFluFilled || !deviceSupportsCovidOnlyResult;

return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Screenshot 2023-10-23 at 15 26 27 Something we can also flag for design is marking the labels as required when we select "Mark test as inconclusive" is misleading

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's a good catch 🔍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're likely going to remove that inconclusive checkbox altogether in favor of simplifying the result validation rules for multiplex devices. That change should be in the upcoming PR for supporting HIV on the test card

name={patientFullName}
removeTestFromQueue={removeTestFromQueue}
/>
<Card className={"list-style-none margin-bottom-1em test-card-container"}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Screenshot 2023-10-23 at 15 20 24

Looks like the <Card> element is a <li> and needs to be nested under <ul>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noticed this on the axe scan, but holding off on changing it until the follow-up PR because a few issues popped up with nesting the queue under a single ul so additional refactor and updating some tests would be needed

Copy link
Collaborator

@emyl3 emyl3 left a comment

Choose a reason for hiding this comment

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

flagged a couple more things but am approving since it sounds like we'll be doing more work on this later and we need to get this out for design/research soon! functionality-wise looks good

@mpbrown mpbrown added this pull request to the merge queue Oct 23, 2023
Merged via the queue into main with commit 9275f36 Oct 23, 2023
33 checks passed
@mpbrown mpbrown deleted the mike/6079-refactor-test-card branch October 23, 2023 21:28
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.

6 participants