Skip to content

Conversation

chaimann
Copy link
Contributor

@chaimann chaimann commented Jun 5, 2025

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 in flash[:alert].

:alert flash key should be used to construct flashes that are displayed by Alert component. It requires a Hash structure of sort flash[: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:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.23%. Comparing base (b67dbb7) to head (27adf3d).
Report is 9 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chaimann chaimann force-pushed the admin-flash-helper branch from fcb6fde to 30f7c7a Compare June 6, 2025 15:54
@chaimann chaimann force-pushed the admin-flash-helper branch 3 times, most recently from fdb205d to 85ab367 Compare June 11, 2025 11:23
@chaimann chaimann marked this pull request as ready for review June 11, 2025 16:40
@chaimann chaimann requested a review from a team as a code owner June 11, 2025 16:40
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 16, 2025
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 16, 2025
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 16, 2025
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 16, 2025
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 17, 2025
chaimann added a commit to chaimann/solidus that referenced this pull request Jun 17, 2025
@tvdeyen tvdeyen force-pushed the admin-flash-helper branch from 85ab367 to 4f313e5 Compare June 27, 2025 05:43
Copy link
Member

@tvdeyen tvdeyen left a 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: "" } }
Copy link
Member

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?

@tvdeyen tvdeyen moved this to Review in Solidus Admin Jun 27, 2025
@tvdeyen tvdeyen added this to the 4.6 milestone Jun 27, 2025
@chaimann chaimann force-pushed the admin-flash-helper branch from 4f313e5 to d0a7973 Compare June 27, 2025 13:55
chaimann added 6 commits July 23, 2025 19:22
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
chaimann added 2 commits July 23, 2025 19:22
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.
@tvdeyen tvdeyen force-pushed the admin-flash-helper branch from d0a7973 to 27adf3d Compare July 23, 2025 17:22
@tvdeyen tvdeyen enabled auto-merge July 23, 2025 17:22
@tvdeyen tvdeyen merged commit 008ef4d into solidusio:main Jul 23, 2025
39 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in Solidus Admin Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants