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(app): Refactor intervention modal render behavior #15898

Merged

Conversation

mjhuff
Copy link
Contributor

@mjhuff mjhuff commented Aug 6, 2024

(Hopefully) closes RQA-2904

Overview

The logic for rendering InterventionModal on the ODD/Desktop is a little bit different when looking at the exact conditions, and this (likely) causes the InterventionModal to render on the ODD sometimes but not on the desktop app, and vice versa.

This is a good opportunity to refactor all of this logic into its own hook and use that hook where we render InterventionModal. After thinking through the render logic, there's room to simplify it a bit, too. We don't actually need stateful storage of an intervention command key. Also, I decided to separate showModal from modalProps (which lets us pass all the non-null props simply), even though we could technically just do a truthy check for modalProps for rendering InterventionModal, since this is maybe a bit more intuitive. Lastly, a few missing tests are added.

To help with bug testing intervention modals, I added a couple console.warns.

Test Plan and Hands on Testing

  • Smoke tested intervention modals during protocol runs. I didn't see any disparity between the app and ODD while testing, but this bug was a bit tricky to repro to begin with.

Changelog

  • Unified the InterventionModal render logic for the desktop app and ODD.

Risk assessment

low

@mjhuff mjhuff requested a review from a team August 6, 2024 15:05
@mjhuff mjhuff requested a review from a team as a code owner August 6, 2024 15:05
@mjhuff mjhuff requested review from TamarZanzouri and removed request for a team August 6, 2024 15:05
/* Props that must be truthy for the modal to render. Prevents multiple null checks while guaranteeing prop type safety. */
modalProps: Omit<InterventionModalProps, 'onResume'> | null
} {
return React.useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to cache this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing!

Yeah, good Q. We probably don't to be honest. I can't imagine there's any tangible, positive performance impact to be gained here.

Copy link
Contributor

@TamarZanzouri TamarZanzouri left a comment

Choose a reason for hiding this comment

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

changes LGTM! just a small question for my curiosity :-)

@mjhuff mjhuff force-pushed the app_refactor-intervention-modal-render-logic branch from 19c1e4b to 3bc6399 Compare August 6, 2024 15:25
Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

Very clean, but can improve the typing!

alignItems: ALIGN_CENTER,
justifyContent: JUSTIFY_SPACE_BETWEEN,
} as const
// If showModal is true, modalProps are guaranteed not to be null.
Copy link
Member

Choose a reason for hiding this comment

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

can tell typescript this by having it return { showModal: false, modalProps: null } | {showModal: true, modalProps: Omit<InterventionModalProps, 'onResume'>} right?

Copy link
Member

Choose a reason for hiding this comment

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

or if you mean that the elements won't be null, you'll have to go a little more in depth - it might be worth having those props be | undefined so you can use Partial and Required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhh, really good catch - I totally blanked on this. The former type is exactly what we need here.

@mjhuff mjhuff merged commit 4693d04 into chore_release-8.0.0 Aug 7, 2024
20 checks passed
@mjhuff mjhuff deleted the app_refactor-intervention-modal-render-logic branch August 7, 2024 15:14
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