Skip to content

refactor: [M3-7397] - Clean up App.tsx#9897

Merged
bnussman-akamai merged 9 commits intolinode:developfrom
bnussman-akamai:clean-up-app-entry-points
Nov 14, 2023
Merged

refactor: [M3-7397] - Clean up App.tsx#9897
bnussman-akamai merged 9 commits intolinode:developfrom
bnussman-akamai:clean-up-app-entry-points

Conversation

@bnussman-akamai
Copy link
Member

@bnussman-akamai bnussman-akamai commented Nov 13, 2023

Description 📝

App.tsx has gotten very messy and generally hard to consume. This PR cleans up App.tsx and related pieces. Most changes are just moving code. The largest refactoring happens in useToastNotifications.

Changes 🔄

  • Cleans up and improves ToastNotifications and makes it useToastNotifications (inspired by refactor: [M3-5181] - RQ-ify Events #9416)
  • Created useAdobeAnalytics, useNewRelic, useEventHandlers, and useGlobalKeyboardListener to separate out logic

How to test 🧪

Verification steps

  • Perform a general check of Cloud Manager
  • Verify global toast notifications still work (creating or deleting a volume for example)
  • Verify that both Adobe Analytics and New Relic initialize
    • This can be verified by looking at the preview link and inspecting the network requests. Verify you see requests to both adobe and New Relic
  • Verify keyboard shortcuts like Control + Shift + D still work
  • Verify e2es pass

As an Author I have considered 🤔

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@bnussman-akamai bnussman-akamai self-assigned this Nov 13, 2023
@bnussman-akamai bnussman-akamai requested a review from a team as a code owner November 13, 2023 18:24
@bnussman-akamai bnussman-akamai requested review from jaalah-akamai and tyler-akamai and removed request for a team November 13, 2023 18:24
};
}, [handleMigrationEvent]);
useAdobeAnalytics();
useNewRelic();
Copy link
Member Author

@bnussman-akamai bnussman-akamai Nov 13, 2023

Choose a reason for hiding this comment

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

It feels kind of wrong to have hooks that don't return anything, but I think it accomplishes what we need.

In fact, useNewRelic probably doesn't even need to be a hook, but for the sake of not making a breaking change, I made it one for now.

Comment on lines +42 to +50
const toasts: Toasts = {
backups_restore: {
failure: (e) => `Backup restoration failed for ${getLabel(e)}.`,
link: formatLink(
'Learn more about limits and considerations.',
'https://www.linode.com/docs/products/storage/backups/#limits-and-considerations'
),
persistFailureMessage: true,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

I rewrote ToastNotifications.tsx to be cleaner and more extendable. The messages, links, and stuff are all the same.

Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Great cleanup! Nice to see those entry points getting some love 👍

Left a few comments for clarification and/or cleanup

}
})
.catch(() => {
// Do nothing; a user may have analytics script requests blocked.
Copy link
Contributor

Choose a reason for hiding this comment

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

Am wondering if anyone would care to see events for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. I personally don't mind the silent failure

Copy link
Contributor

Choose a reason for hiding this comment

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

Silent for the user for sure. Just wondering about collecting this info on our end so we have a better idea of the sample for those events but it would be a product decision and I doubt anyone would be interested 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

We could capture a sentry exception, but I worry we'd just flood sentry with useless messages. I have a feeling lots of browsers with privacy features enabled will block Adobe Analytics

Copy link
Contributor

@mjac0bs mjac0bs Nov 14, 2023

Choose a reason for hiding this comment

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

^^ Yes, that was the problem before, though I think the error handling was at a slightly different spot in the code at the time. We don't want to flood Sentry, and before we were creating a new Sentry alert for every user and every event they clicked where analytics were disabled. Where the catch is now, I think we'd just be triggering sentry alerts for every user blocking extensions every time they load the app (rather than every time they fire a trackable event), but that's still a lot.

filter: ({ event }) => event.action.startsWith('disk') && !event._initial,
handler: diskEventHandler,
},
];
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not seem to be a 1/1 with the legacy code. Can you explain what happened to the linode_migrate events? They were previously a dependency for the hook below.

Copy link
Member Author

Choose a reason for hiding this comment

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

handleMigrationEvent was duplicated logic that also was in ToastNotifications. It now lives in useToastNotifications where it belongs

export const getLabel = (event: Event) => event.entity?.label ?? '';
export const getSecondaryLabel = (event: Event) =>
event.secondary_entity?.label ?? '';
const formatLink = (text: string, link: string, handleClick?: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we type this better? also, we are not testing any hooks in the codebase, so in general return types would be nice to have in those new hooks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, didn't see the any when I copied this code over!

Copy link
Member Author

Choose a reason for hiding this comment

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

I made the hooks explicitly return null. I don't see too much value in adding an explicit return type to the function signatures. Do you think it makes sense to be explicit here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh was commenting with my personal GH account. Yeah, agreed - not much value. I'll give it more thoughts!

@tyler-akamai
Copy link
Contributor

tyler-akamai commented Nov 14, 2023

  • Performed general check of Cloud Manager
  • Verified global toast notifications still work (creating or deleting a volume for example)
  • Verified that both Adobe Analytics and New Relic initialize
  • Verified keyboard shortcuts like Control + Shift + D still work
  • Verify e2es pass

@linode linode deleted a comment from alioso Nov 14, 2023
@linode linode deleted a comment from alioso Nov 14, 2023
Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Second pass: everything seems stable when testing in the browser. Tested a bunch of actions and notifications came through as expected. No regression spotted ✅

*/
const toasts: Toasts = {
backups_restore: {
failure: (e) => `Backup restoration failed for ${getLabel(e)}.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Very small nitpick: should we end notifications with a period. For the toast notifications ive added, they have just been a statement without a period, but I can update them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm gonna leave the periods but put an item on a cafe agenda. It seems pretty inconstant throughout the app when I search for instances of enqueueSnackbar

@bnussman-akamai bnussman-akamai merged commit 7a62480 into linode:develop Nov 14, 2023
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.

5 participants