Skip to content

refactor(site): Refactor alerts #7587

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

Merged
merged 13 commits into from
May 18, 2023
Merged

refactor(site): Refactor alerts #7587

merged 13 commits into from
May 18, 2023

Conversation

BrunoQuaresma
Copy link
Collaborator

Motivation:
Our alerts were inconsistent when displaying messages with details or actions, looking a bit ugly and unprofessional.

Changes:

  • Change AlertBanner to Alert. Alert is our custom component with a few standard features we usually need when displaying errors and warnings.
  • Use the MUI Alert component as a base
  • Create a custom component to deal with errors ErrorAlert. It extends the Alert component and uses the getErrorMessage and getErrorDetail to mount the text that will be displayed
  • Do not hide the error details anymore. It was making the component a bit more complex and I don't see a good case for it, but let me know if you think it is essential and what is the use case
  • Added a few error color tweaks
  • Changed the button sizes to improve its usage range

Preview:

Before:
Screen Shot 2023-05-17 at 15 33 37

After:
Screen Shot 2023-05-17 at 15 33 46

Before:
Screen Shot 2023-05-17 at 15 32 51

After:
Screen Shot 2023-05-17 at 15 32 57

@BrunoQuaresma BrunoQuaresma self-assigned this May 17, 2023
- name: "@mui/material/Alert"
message:
"You should use the Alert component provided on
components/Alert/Alert"
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@Kira-Pilot
Copy link
Member

Feels like the icon on the "info" severity alert doesn't have enough contrast:
Screenshot 2023-05-17 at 4 11 36 PM

@Kira-Pilot
Copy link
Member

Kira-Pilot commented May 17, 2023

I think I was under the mistaken impression that we were going to be using the snackbar from this PR as the new alert widget going forward. Is that just for version updates? When do you think we should use an alert vs a toast vs a snackbar? Asking so I can get it right in my upcoming PR :)

import Button from "@mui/material/Button"

export interface AlertProps extends PropsWithChildren {
severity: MuiAlertProps["severity"]
Copy link
Member

Choose a reason for hiding this comment

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

If ErrorAlert is going to be a separate component, should we omit the severity error from this prop type? At first glance, it's hard to tell if I should be using ErrorAlert for errors, or Alert with severity="error" or both in different ways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alert is the generic one with extra things and it should still be usable for errors if you need some customization. The advantage of using the ErrorAlert component is, you can pass the error and get the message and detail displayed without having to do it yourself.

severity="error"
text="No authentication methods configured!"
/>
<Alert severity="error">No authentication methods configured!</Alert>
Copy link
Member

Choose a reason for hiding this comment

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

Related to my comment above, what is the difference between these two ways of displaying errors?

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 answered in the previous comment.

setOpen(false)
onDismiss && onDismiss()
}}
data-testid="dismiss-banner-btn"
Copy link
Member

Choose a reason for hiding this comment

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

Should we stick an aria-label on here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since it has a text, I think we don't need it 🤔 but I'm not sure if I understood your point

Copy link
Member

Choose a reason for hiding this comment

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

No, you're right! I had to google it but I think since we have the text we can forget the label.

@BrunoQuaresma
Copy link
Collaborator Author

I think I was under the mistaken impression that we were going to be using the snackbar from this PR as the new alert widget going forward. Is that just for version updates? When do you think we should use an alert vs a toast vs a snackbar? Asking so I can get it right in my upcoming PR :)

This is a REALLY good question and I'm not sure if I have a good answer for that, but I think snack bars are good for displaying errors or warnings that need to be displayed after a certain action as feedback like an update or delete error after a user clicked on a button.

Alerts are good for static warnings where the users didn't trigger any action like deprecation notices and errors during initial loading but any of these are "written in stone" and we may find situations where display alerts for actions feedback or display snack bars for static warnings can be better, the PR that you mentioned is one of these cases. We didn't have a good place to place the "global alert" so it was just better and easy to make it a snack bar.

@Kira-Pilot
Copy link
Member

Alerts are good for static warnings where the users didn't trigger any action like deprecation notices and errors during initial loading

This seems like a good distinction to me!

@BrunoQuaresma BrunoQuaresma merged commit 8e31ed4 into main May 18, 2023
@BrunoQuaresma BrunoQuaresma deleted the bq/refactor-alerts branch May 18, 2023 16:17
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants