Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rename to OpPrimer::FlashComponent / primerized_flash

Oliver Günther0923b625a8e4
diff --git a/app/components/op_primer/banner_message_component.html.erb b/app/components/op_primer/flash_component.erb
similarity index 96%
rename from app/components/op_primer/banner_message_component.html.erb
rename to app/components/op_primer/flash_component.erb
index 0f7373dba3c..63c0bcfec36 100644
--- a/app/components/op_primer/banner_message_component.html.erb
+++ b/app/components/op_primer/flash_component.erb
@@ -27,6 +27,6 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="op-primer-banner--item">
+<div class="op-primer-flash--item">
<%= render_parent %>
</div>
diff --git a/app/components/op_primer/banner_message_component.rb b/app/components/op_primer/flash_component.rb
similarity index 96%
rename from app/components/op_primer/banner_message_component.rb
rename to app/components/op_primer/flash_component.rb
index 82685bb4231..24fa22fcbb2 100644
--- a/app/components/op_primer/banner_message_component.rb
+++ b/app/components/op_primer/flash_component.rb
@@ -27,7 +27,7 @@
#++
module OpPrimer
- class BannerMessageComponent < Primer::Alpha::Banner
+ class FlashComponent < Primer::Alpha::Banner
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
diff --git a/app/controllers/concerns/op_turbo/component_stream.rb b/app/controllers/concerns/op_turbo/component_stream.rb
index 7e77a32c0c2..125a26975e8 100644
--- a/app/controllers/concerns/op_turbo/component_stream.rb
+++ b/app/controllers/concerns/op_turbo/component_stream.rb
@@ -77,7 +77,7 @@ module OpTurbo
update_flash_message_via_turbo_stream(**kwargs.merge(scheme: :danger, icon: :stop))
end
- def update_flash_message_via_turbo_stream(message:, component: OpPrimer::BannerMessageComponent, **)
+ def update_flash_message_via_turbo_stream(message:, component: OpPrimer::FlashComponent, **)
instance = component.new(**).with_content(message)
turbo_streams << instance.render_as_turbo_stream(view_context:, action: :flash)
end
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index f3faf5b83ae..e26217385d0 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -174,13 +174,13 @@ class MyController < ApplicationController
# rubocop:disable Rails/ActionControllerFlashBeforeRender
result.on_success do
- flash[:primer_banner] = { message: t("my.access_token.notice_api_token_revoked") }
+ flash[:op_primer_flash] = { message: t("my.access_token.notice_api_token_revoked") }
end
result.on_failure do |r|
error = r.errors.map(&:message).join("; ")
Rails.logger.error("Failed to revoke api token ##{current_user.id}: #{error}")
- flash[:primer_banner] = { message: t("my.access_token.failed_to_revoke_token", error:), scheme: :danger }
+ flash[:op_primer_flash] = { message: t("my.access_token.failed_to_revoke_token", error:), scheme: :danger }
end
# rubocop:enable Rails/ActionControllerFlashBeforeRender
diff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rb
index 71c86c969b6..0e8b668c935 100644
--- a/app/helpers/flash_messages_helper.rb
+++ b/app/helpers/flash_messages_helper.rb
@@ -37,7 +37,7 @@ module FlashMessagesHelper
# Renders flash messages
def render_flash_messages
messages = flash
- .reject { |k, _| k.to_s == "primer_banner" }
+ .reject { |k, _| k.to_s == "op_primer_flash" }
.reject { |k, _| k.start_with? "_" }
.map do |k, v|
if k.to_sym == :modal
diff --git a/app/helpers/banner_messages_helper.rb b/app/helpers/primerized_flash_helper.rb
similarity index 85%
rename from app/helpers/banner_messages_helper.rb
rename to app/helpers/primerized_flash_helper.rb
index 4e6aa0e3545..ffe46356ab3 100644
--- a/app/helpers/banner_messages_helper.rb
+++ b/app/helpers/primerized_flash_helper.rb
@@ -27,16 +27,16 @@
#++
#
-module BannerMessagesHelper
+module PrimerizedFlashHelper
extend ActiveSupport::Concern
- def render_primer_banner_message
- return if flash[:primer_banner].blank?
+ def render_primerized_flash
+ return if flash[:op_primer_flash].blank?
- system_arguments = flash[:primer_banner]
+ system_arguments = flash[:op_primer_flash]
message = system_arguments.delete(:message)
- render(OpPrimer::BannerMessageComponent.new(**system_arguments)) do
+ render(OpPrimer::FlashComponent.new(**system_arguments)) do
message
end
end
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 19c1006cd18..2e26596043a 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -117,12 +117,12 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<div class="content-overlay"></div>
<main id="content-wrapper" class="<%= initial_classes %>">
- <%# Banner messages are being rendered using primer %>
- <div id="banner-messages" class="op-primer-banner">
- <%= render_primer_banner_message %>
+ <%# Primerized flash messages are being rendered separately %>
+ <div id="primerized-flash-messages" class="op-primer-flash">
+ <%= render_primerized_flash %>
</div>
<%# Banner messages are being rendered using primer %>
- <div id="banner-messages" class="op-primer-banner"></div>
+ <div id="primerized-flash-messages" class="op-primer-flash"></div>
<%# Flash messages are being rendered using the old op-flash style %>
<turbo-frame id="flash-messages">
<%= render_flash_messages %>
diff --git a/frontend/src/global_styles/primer/_banners.sass b/frontend/src/global_styles/primer/_flash.sass
similarity index 93%
rename from frontend/src/global_styles/primer/_banners.sass
rename to frontend/src/global_styles/primer/_flash.sass
index 90dc71bb786..73ea1438690 100644
--- a/frontend/src/global_styles/primer/_banners.sass
+++ b/frontend/src/global_styles/primer/_flash.sass
@@ -26,12 +26,12 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-$op-primer-banner-toaster-width: 80%
+$op-primer-flash-toaster-width: 80%
-.op-primer-banner
+.op-primer-flash
z-index: 599
position: absolute
- max-width: $op-primer-banner-toaster-width
+ max-width: $op-primer-flash-toaster-width
margin: 0 auto
left: 10%
right: 10%
diff --git a/frontend/src/global_styles/primer/_index.sass b/frontend/src/global_styles/primer/_index.sass
index 05cc6f6ffcb..587dc8f8a00 100644
--- a/frontend/src/global_styles/primer/_index.sass
+++ b/frontend/src/global_styles/primer/_index.sass
@@ -1,3 +1,3 @@
@import icons
@import overrides
-@import banners
+@import flash
diff --git a/frontend/src/turbo/flash-stream-action.ts b/frontend/src/turbo/flash-stream-action.ts
index 725959bd31b..4a0ebe430b3 100644
--- a/frontend/src/turbo/flash-stream-action.ts
+++ b/frontend/src/turbo/flash-stream-action.ts
@@ -3,7 +3,7 @@ import { StreamActions, StreamElement } from '@hotwired/turbo';
export function registerFlashStreamAction() {
StreamActions.flash = function dialogStreamAction(this:StreamElement) {
const content = this.templateElement.content;
- const target = document.getElementById('banner-messages') as HTMLElement;
+ const target = document.getElementById('primerized-flash-messages') as HTMLElement;
target.innerHTML = '';
target.append(content);
};
diff --git a/lookbook/docs/patterns/08-flash-banner.md.erb b/lookbook/docs/patterns/08-flash-banner.md.erb
index 346e70ec5f2..a79cdd58fcf 100644
--- a/lookbook/docs/patterns/08-flash-banner.md.erb
+++ b/lookbook/docs/patterns/08-flash-banner.md.erb
@@ -2,12 +2,12 @@ This component defines a specific use case of the Primer `Banner` component, con
## Overview
-To use a Primerised flash, the `OpPrimer::BannerMessageComponent` was introduced.
+To use a Primerised flash, the `OpPrimer::FlashComponent` was introduced.
-<%= embed OpPrimer::BannerMessageComponentPreview, :default, panels: %i[source] %>
+<%= embed OpPrimer::FlashComponentPreview, :default, panels: %i[source] %>
Internally, this component uses the `Primer::BannerComponent` to render the flash message.
-The `OpPrimer::BannerMessageComponent` is a wrapper around the `Primer::BannerComponent` that adds a wrapper class to prepend the flash message to the `#banner-messages` div in the base layout.
+The `OpPrimer::FlashComponent` is a wrapper around the `Primer::BannerComponent` that adds a wrapper class to prepend the flash message to the `#primerized-flash-messages` div in the base layout.
Otherwise, you use the component as you would use `Primer::Alpha::Banner`.
See below for available arguments.
@@ -22,16 +22,16 @@ These are rendered using the previous `op-flash` styles, and are not yet primeri
So if you find yourself in need to render a primerized flash. You can use this pattern instead:
```ruby
-flash[:primer_banner] = { message: "Successful update", scheme: :success, icon: :check }
+flash[:op_primer_flash] = { message: "Successful update", scheme: :success, icon: :check }
```
Or for an error:
```ruby
-flash[:primer_banner] = { message: "Oh no! Something went wrong", scheme: :danger, icon: :alert }
+flash[:op_primer_flash] = { message: "Oh no! Something went wrong", scheme: :danger, icon: :alert }
```
-These are rendered in the layout through the `render_banner_messages` helper using the `OpPrimer::BannerMessageComponent`.
+These are rendered in the layout through the `render_banner_messages` helper using the `OpPrimer::FlashComponent`.
## Usage in turbo streams
@@ -53,7 +53,7 @@ update_flash_message_via_turbo_stream(
)
```
-The width of this banner is always configured through the `op-primer-banner` namespace.
+The width of this banner is always configured through the `op-primer-flash` namespace.
It is set to 80% of the available width
Note that using a turbo stream will always remove all previous flashes.
@@ -65,10 +65,10 @@ Please create a code maintenance ticket if you need to append/prepend messages i
As this is a common use case, the method `render_error_flash_message_via_turbo_stream()` is provided, generating a flash with `scheme: :danger` and `icon: :stop` by default.
-<%= embed OpPrimer::BannerMessageComponentPreview, :danger, panels: %i[source] %>
+<%= embed OpPrimer::FlashComponentPreview, :danger, panels: %i[source] %>
<% if false %>
### With optional button:
-<%= embed OpPrimer::BannerMessageComponentPreview , :button, panels: %i[source] %>
+<%= embed OpPrimer::FlashComponentPreview, :button, panels: %i[source] %>
<% end %>
diff --git a/lookbook/previews/op_primer/banner_message_component_preview.rb b/lookbook/previews/op_primer/flash_component_preview.rb
similarity index 57%
rename from lookbook/previews/op_primer/banner_message_component_preview.rb
rename to lookbook/previews/op_primer/flash_component_preview.rb
index 00e95c160a6..33be6e1143e 100644
--- a/lookbook/previews/op_primer/banner_message_component_preview.rb
+++ b/lookbook/previews/op_primer/flash_component_preview.rb
@@ -1,20 +1,20 @@
module OpPrimer
# @logical_path OpenProject/Primer
- class BannerMessageComponentPreview < Lookbook::Preview
+ class FlashComponentPreview < Lookbook::Preview
def default
- render(OpPrimer::BannerMessageComponent.new) do
+ render(OpPrimer::FlashComponent.new) do
I18n.t("notice_meeting_updated")
end
end
def danger
- render(OpPrimer::BannerMessageComponent.new(scheme: :danger, icon: :stop)) do |_component|
+ render(OpPrimer::FlashComponent.new(scheme: :danger, icon: :stop)) do |_component|
"Stop right there."
end
end
def button
- render(OpPrimer::BannerMessageComponent.new) do |component|
+ render(OpPrimer::FlashComponent.new) do |component|
component.with_action_button(
tag: :a,
href: "/"
diff --git a/modules/meeting/app/components/meetings/update_flash_component.rb b/modules/meeting/app/components/meetings/update_flash_component.rb
index 0bcc39bba27..3d5391352d4 100644
--- a/modules/meeting/app/components/meetings/update_flash_component.rb
+++ b/modules/meeting/app/components/meetings/update_flash_component.rb
@@ -33,7 +33,7 @@ module Meetings
alias_method :meeting, :model
def call
- render(::OpPrimer::BannerMessageComponent.new(icon: :info)) do |banner|
+ render(::OpPrimer::FlashComponent.new(icon: :info)) do |banner|
banner.with_action_button(
tag: :a,
href: helpers.meeting_path(meeting),
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
index a0c0e91314c..6d7e479a5ac 100644
--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe "Structured meetings CRUD",
end
it do
- flash_component = ".op-primer-banner--item"
+ flash_component = ".op-primer-flash--item"
## Add agenda item
show_page.visit!
diff --git a/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb b/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
index a68b972fc19..b11474c1eb1 100644
--- a/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/automatically_managed_project_folders_controller.rb
@@ -73,7 +73,7 @@ class Storages::Admin::AutomaticallyManagedProjectFoldersController < Applicatio
service_result = call_update_service
if service_result.success?
- flash[:primer_banner] = {
+ flash[:op_primer_flash] = {
message: I18n.t(:"storages.notice_successful_storage_connection"),
scheme: :success
}
diff --git a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
index c82a707e746..fbc7c485a41 100644
--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
@@ -125,7 +125,7 @@ class Storages::Admin::OAuthClientsController < ApplicationController
end
def finish_setup
- flash[:primer_banner] = { message: I18n.t(:"storages.notice_successful_storage_connection"), scheme: :success }
+ flash[:op_primer_flash] = { message: I18n.t(:"storages.notice_successful_storage_connection"), scheme: :success }
redirect_to edit_admin_settings_storage_path(@storage)
end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index fc79f08844a..c3368842839 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -191,7 +191,7 @@ class Storages::Admin::StoragesController < ApplicationController
update_via_turbo_stream(component: Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage))
respond_with_turbo_streams
else
- flash.now[:primer_banner] = {
+ flash.now[:op_primer_flash] = {
message: I18n.t("storages.health_email_notifications.error_could_not_be_saved"), scheme: :danger
}
render :edit
@@ -209,11 +209,11 @@ class Storages::Admin::StoragesController < ApplicationController
# rubocop:disable Rails/ActionControllerFlashBeforeRender
service_result.on_failure do
- flash[:primer_banner] = { message: join_flash_messages(service_result.errors.full_messages), scheme: :danger }
+ flash[:op_primer_flash] = { message: join_flash_messages(service_result.errors.full_messages), scheme: :danger }
end
service_result.on_success do
- flash[:primer_banner] = { message: I18n.t(:notice_successful_delete), scheme: :success }
+ flash[:op_primer_flash] = { message: I18n.t(:notice_successful_delete), scheme: :success }
end
# rubocop:enable Rails/ActionControllerFlashBeforeRender
@@ -265,7 +265,7 @@ class Storages::Admin::StoragesController < ApplicationController
def ensure_valid_provider_type_selected
short_provider_type = params[:provider]
if short_provider_type.blank? || (@provider_type = ::Storages::Storage::PROVIDER_TYPE_SHORT_NAMES[short_provider_type]).blank?
- flash[:primer_banner] = { message: I18n.t("storages.error_invalid_provider_type"), scheme: :danger }
+ flash[:op_primer_flash] = { message: I18n.t("storages.error_invalid_provider_type"), scheme: :danger }
redirect_to admin_settings_storages_path
end
end