Skip to content

Commit d3c2022

Browse files
authored
Render flash messages with UI::Alerts::FlashMessage (#4020)
The four layouts that rendered flash through `/layouts/revised_messages` now render the component instead, the way admin already did. The partial stays behind for `@page_errors` and the mustache template `BikeIndexAlerts` renders client-side alerts into, so the JS alerts on the bike-edit and payments pages keep working. - **`flash[:info]` becomes `flash[:notice]`.** `info` isn't one of `KINDS` — 24 call sites across 14 controllers set it directly, four more reach it by passing `flash_type: :info` to `authenticate_user`, and four views passed it as a kind, where it silently fell back. Renamed rather than aliased in the component, so the flash type and the kind it renders stay the same word. `KINDS` now derives from `TEXT_CLASSES`. - **The unknown-kind guard raises in dev and test, falls back to notice elsewhere.** Rails sweeps the flash after the layout renders, so a raise from the layout leaves the offending key in the session and raises again on the next request, and the next. - **Every flash value is a string now.** Six sites set an Array (`errors.full_messages`) or a `flash[:errors]` key; the component renders neither, and the old bootstrap partial rendered the Array's `inspect`. Five get `to_sentence`, and the theft alert plan forms get `UI::Alerts::ObjectError` above the form like the other admin forms. - **The impound multi-update's turbo_stream replaces `#flash-messages`** alongside the results frame, rather than rendering a second copy of the flash inside the frame. The component renders its container even when empty so there's something to target, and the replace only fires when there's a flash — otherwise every filter and sort would wipe an alert the rider hadn't dismissed. - **`UI::Alert` moves to `UI::Alerts::Base`**, so all three alert components share the namespace. The three `MARKUP_DIGEST` bumps are that rename reaching templates inside fragment caches. Flash now sits bottom-center instead of top, and success messages no longer auto-fade after 10s — the component's behavior, already what admin gets.
1 parent 2dd89f8 commit d3c2022

106 files changed

Lines changed: 357 additions & 327 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/components/admin/badges/bike_hidden_explanation/component.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def call
2424
def user_hidden_content
2525
return unless @bike.user_hidden?
2626

27-
content_tag(:small, "user hidden", class: UI::Alert::Component::TEXT_CLASSES[:notice])
27+
content_tag(:small, "user hidden", class: UI::Alerts::Base::Component::TEXT_CLASSES[:notice])
2828
end
2929

3030
# BikeVersion can't be example
@@ -47,11 +47,11 @@ def deleted_content
4747
content_tag(:small,
4848
content_tag(:span, "deleted: ") +
4949
content_tag(:span, l(@bike.deleted_at, format: :convert_time), class: "localizeTime"),
50-
class: UI::Alert::Component::TEXT_CLASSES[:warning])
50+
class: UI::Alerts::Base::Component::TEXT_CLASSES[:warning])
5151
end
5252

5353
def error_class
54-
UI::Alert::Component::TEXT_CLASSES[:error]
54+
UI::Alerts::Base::Component::TEXT_CLASSES[:error]
5555
end
5656
end
5757
end

app/components/admin/badges/marketplace_listing/component.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def humanize(str)
2929

3030
def status_class
3131
case @status
32-
when "for_sale" then UI::Alert::Component::TEXT_CLASSES[:notice]
33-
when "sold" then UI::Alert::Component::TEXT_CLASSES[:success]
34-
when "removed" then UI::Alert::Component::TEXT_CLASSES[:warning]
32+
when "for_sale" then UI::Alerts::Base::Component::TEXT_CLASSES[:notice]
33+
when "sold" then UI::Alerts::Base::Component::TEXT_CLASSES[:success]
34+
when "removed" then UI::Alerts::Base::Component::TEXT_CLASSES[:warning]
3535
else
3636
""
3737
end

app/components/admin/bike_cell/component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% if @bike.blank? %>
2-
<small class="<%= UI::Alert::Component::TEXT_CLASSES[:error] %>">
2+
<small class="<%= UI::Alerts::Base::Component::TEXT_CLASSES[:error] %>">
33
Missing bike
44
<% if @bike_id.present? %>
55
<code><%= @bike_id %></code>

app/components/admin/bikes_table/component.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
<% if bike.claimed? %>
5555
<span
56-
class="tw:absolute tw:top-0 tw:right-0 <%= UI::Alert::Component::TEXT_CLASSES[:notice] %>"
56+
class="tw:absolute tw:top-0 tw:right-0 <%= UI::Alerts::Base::Component::TEXT_CLASSES[:notice] %>"
5757
title="<%= bike.type %> is claimed"
5858
style="cursor: default"
5959
>
@@ -65,7 +65,7 @@
6565

6666
<% table.column(sortable: "manufacturer_id") do |bike| %>
6767
<% if bike.manufacturer_other.present? %>
68-
<span class="<%= UI::Alert::Component::TEXT_CLASSES[:warning] %>">
68+
<span class="<%= UI::Alerts::Base::Component::TEXT_CLASSES[:warning] %>">
6969
<%= bike.manufacturer_other %>
7070
</span>
7171
<% else %>
@@ -85,7 +85,7 @@
8585

8686
<% if bike.stolen_recovery? %>
8787
<small>
88-
<%= link_to "recovery!", edit_admin_recovery_url(bike.recovered_records.first.id), class: "#{UI::Alert::Component::TEXT_CLASSES[:success]} tw:underline" %>
88+
<%= link_to "recovery!", edit_admin_recovery_url(bike.recovered_records.first.id), class: "#{UI::Alerts::Base::Component::TEXT_CLASSES[:success]} tw:underline" %>
8989
</small>
9090
<% end %>
9191

@@ -104,7 +104,7 @@
104104
<% end %>
105105

106106
<% if bike.status_stolen? %>
107-
<span class="tw:absolute tw:right-0 tw:bottom-0 tw:text-xs <%= UI::Alert::Component::TEXT_CLASSES[:error] %>">
107+
<span class="tw:absolute tw:right-0 tw:bottom-0 tw:text-xs <%= UI::Alerts::Base::Component::TEXT_CLASSES[:error] %>">
108108
stolen
109109
</span>
110110
<% end %>

app/components/admin/bikes_table/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module BikesTable
88
# checkboxes, and skip_user to drop the owner column.
99
class Component < ApplicationComponent
1010
# Digest of the markup inside the row cache — the cached_markup_digest spec keeps it current
11-
MARKUP_DIGEST = "55bd93d8018c"
11+
MARKUP_DIGEST = "864a82f880b3"
1212

1313
def initialize(bikes:, no_show_header: false, show_serial: false, render_sortable: false,
1414
skip_user: false, render_multi_check: false)

app/components/admin/current_header/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def primary_activity_subject
105105
end
106106

107107
def error_text_class
108-
UI::Alert::Component::TEXT_CLASSES[:error]
108+
UI::Alerts::Base::Component::TEXT_CLASSES[:error]
109109
end
110110
end
111111
end

app/components/admin/organization_cell/component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def organization_subject
2323
end
2424

2525
def error_text_class
26-
UI::Alert::Component::TEXT_CLASSES[:error]
26+
UI::Alerts::Base::Component::TEXT_CLASSES[:error]
2727
end
2828
end
2929
end

app/components/admin/strava_requests_rate_limit_details/component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
</div>
4141

4242
<% if StravaJobs::RequestRunner.new.skip_job? %>
43-
<%= render(UI::Alert::Component.new(text: "StravaJobs::RequestRunner is skipped", kind: :error)) %>
43+
<%= render(UI::Alerts::Base::Component.new(text: "StravaJobs::RequestRunner is skipped", kind: :error)) %>
4444
<% end %>
4545
</div>

app/components/admin/user_cell/component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<span class="tw:inline-flex tw:items-baseline tw:gap-x-2">
22
<% if show_missing_user? %>
33
<small
4-
class="<%= UI::Alert::Component::TEXT_CLASSES[:error] %>"
4+
class="<%= UI::Alerts::Base::Component::TEXT_CLASSES[:error] %>"
55
title="<%= @user_id %>"
66
>
77
Missing user

app/components/admin/users_table/component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<% end %>
2424

2525
<% table.column(sortable: "deleted_at", classes: "deleted-cell tw:text-xs") do |user| %>
26-
<span class="<%= UI::Alert::Component::TEXT_CLASSES[:error] %>">
26+
<span class="<%= UI::Alerts::Base::Component::TEXT_CLASSES[:error] %>">
2727
<%= render UI::Time::Component.new(time: user.deleted_at) %>
2828
</span>
2929
<% end %>

0 commit comments

Comments
 (0)