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): trigger UpdateAppModal based on state.alerts #6708

Merged
merged 3 commits into from Oct 9, 2020

Conversation

mcous
Copy link
Contributor

@mcous mcous commented Oct 8, 2020

Overview

This PR switches the app update notification from a custom system to the more generic app/src/alerts system. This work unblocks #6684, and also means that when the <UpdateAppModal> pops up, it doesn't shunt you automatically to a different part of the app; it just opens up over whatever page you're already on.

Old and busted:

  • <UpdateAppModal> is displayed based on navigating to the /more/app/update route
  • To pop up the notification, the multiple places in the UI check state.shell.update.available and state.shell.update.seen and return a react-router <Redirect> if the notification needs to be seen
  • To open the modal in other parts of the UI (robot update flow and directly from the /more/app page), a react-router <Link> points to `/more/app/update

New hotness:

  • An epic watches for changes in state.shell.update and if it sees an update become available, it sends a alerts:ALERT_TRIGGERED action with alertId: 'appUpdateAvailable' in the payload
  • The top level <Alerts> component renders an <UpdateAppModal> component if the appUpdateAvailable alert is active
    • Closing the modal dismisses the alert until the next time the app is opened
  • To open the modal in other parts of the UI, React state is used to render a self-contained <UpdateAppModal> in a <Portal>

Changelog

  • refactor(app): trigger UpdateAppModal based on state.alerts
  • fix(deps): updated react-redux to 7.2.1 for this fix
    • Prior to the fix, if the reference to the function in useSelector doesn't change and the store never emits a change notification, useSelector will always return the cached value
    • This is bad for us, because our mocked store never emits anything (also this is a real race condition that can apparently happen in production)
    • After this fix, we can force a selector re-computation by returning a new value via store.getState.mockReturnValue
    • This meant that our "check for updates on update channel change" test wasn't doing anything

Review requests

To test this on a dev app, mess with the version in app and app-shell's package.json so the app thinks it's behind 3.21.0. The following logic was touched:

  • Automatic notification pop up on app launch
  • Manually open release notes by clicking on "View Available Update" in More > App
  • View app update from first page of robot update flow if you try to update your robot while an app update is available
  • Check for app updates if the update channel changes

Risk assessment

This is an important part of the UI, so medium risk here. Everything looks good in my click around smoke testing, all new components were TDD'd, and I added some tests to existing (testless) components to ensure new functionality around modal display was covered.

@mcous mcous requested review from a team as code owners October 8, 2020 21:46
@mcous mcous requested review from a team, b-cooper, Kadee80 and shlokamin and removed request for a team October 8, 2020 21:46
@mcous mcous added robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience). ready for review refactor labels Oct 8, 2020
@mcous mcous changed the title App update available alert refactor(app): trigger UpdateAppModal based on state.alerts Oct 8, 2020
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.

Went through the test steps and LGTM!

Copy link
Contributor Author

@mcous mcous left a comment

Choose a reason for hiding this comment

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

self review

<a className={styles.sync_link} onClick={props.onClick} disabled>
click here
</a>
<Link href="#" color={C_BLUE} onClick={props.onClick}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: <a href="#" ... misbehaves, in that it will trigger react-router routing. I've replaced this with a more semantically correct <button> in #6715 that is styled like a link

@@ -51,7 +56,9 @@ export function AdvancedSettingsCard(props: Props): React.Node {
const handleChannel = event =>
dispatch(Config.updateConfigValue('update.channel', event.target.value))

React.useEffect(props.checkUpdate, [channel])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic moved to an epic

@@ -51,7 +56,9 @@ export function AdvancedSettingsCard(props: Props): React.Node {
const handleChannel = event =>
dispatch(Config.updateConfigValue('update.channel', event.target.value))

React.useEffect(props.checkUpdate, [channel])
useMountEffect(() => {
dispatch(checkShellUpdate())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait actually this whole thing can go away; a sibling component is already doing this. Will address in #6715

Copy link
Contributor

@Kadee80 Kadee80 left a comment

Choose a reason for hiding this comment

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

🧀

@mcous mcous merged commit 9432111 into hotfix_3.21.1 Oct 9, 2020
@mcous mcous deleted the app_update-available-alert branch October 9, 2020 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants