-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Admin] Flashes helper and reorganization #6280
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6280 +/- ##
==========================================
+ Coverage 87.99% 89.23% +1.23%
==========================================
Files 796 955 +159
Lines 16645 20079 +3434
==========================================
+ Hits 14647 17917 +3270
- Misses 1998 2162 +164 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fcb6fde
to
30f7c7a
Compare
fdb205d
to
85ab367
Compare
85ab367
to
4f313e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very happy with mis-using the Rails flash hash like this, but I this is a very pragmatic and useful way of implementing the UI guidelines (which make sense).
I have a non-block suggesting for making the naming a bit more neutral. We should/could amend tests to the commits introducing the tested code.
attr_reader :alerts | ||
|
||
# Construct alert flashes like: | ||
# flash[:alert] = { <alert_type>: { title: "", description: "" } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description
seems to be non-intuitive, since the text is not always necessarily descriptive. What about more neutral message
?
4f313e5
to
d0a7973
Compare
Since we now have a dedicated UI component for Alerts, we should be able to distinguish which flash type goes where (toast or alert). This helper adds two methods: #toasts will collect any flash key other than `:alert`, ideally we use "notice" and "error" but it's not forced; #alerts will return everything in `flash[:alert]`; `:alert` flash key should be used to construct flashes that are displayed by Alert component.
`flash[:notice]` is what is commonly used in other controllers to display a regular success/notice toast, so to be consistent let's use it everywhere. `:success` would also work, but to avoid confusion with Alerts of "success" type (see "ui/alert" component) it's better to use correct naming everywhere.
This should allow to target them with turbo stream responses when needed
Passing strings as messages to `flash[]` is more common than using other primitives, and users deciding to set flash[:alert] might not be aware of the Hash structure that is required to correctly construct and display a UI alert from flash[:alert]. So instead of letting it fail because of the type mismatch (when calling #slice on a string instead of a hash), we can add a fallback option to treat given string as a body of the alert message and construct a `danger` type alert with default title.
d0a7973
to
27adf3d
Compare
Note
Split from #6228 and #6236
Summary
Since we now have a dedicated UI component for Alerts, we should be able to distinguish which flash type goes where (toast or alert). FlashHelper adds two methods:
#toasts
will collect any flash key other than:alert
, ideally we use "notice" and "error" but it's not forced;#alerts
will return everything inflash[:alert]
.:alert
flash key should be used to construct flashes that are displayed by Alert component. It requires a Hash structure of sortflash[:alert] = { <alert_type>: { title: String, description: String } }
to be displayed correctly, but if user passes just a string e.g.flash[:alert] = "Things went horribly wrong"
we take the string and create a structure to pass to Alert component:{ danger: { description: "Things went horribly wrong" } }
, so that the user is not left with an exception saying that#slice
method received an incorrect number of arguments to figure it out on their own.Updates Alert component to account for default title to be used in such cases.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed: