diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index e26217385d0b..129cccccdf50 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -174,13 +174,13 @@ def revoke_api_key # rubocop:disable Rails/ActionControllerFlashBeforeRender result.on_success do - flash[:op_primer_flash] = { message: t("my.access_token.notice_api_token_revoked") } + flash[:notice] = 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[:op_primer_flash] = { message: t("my.access_token.failed_to_revoke_token", error:), scheme: :danger } + flash[:error] = t("my.access_token.failed_to_revoke_token", error:) end # rubocop:enable Rails/ActionControllerFlashBeforeRender diff --git a/app/helpers/errors_helper.rb b/app/helpers/errors_helper.rb index 507828b3fc99..561164407eeb 100644 --- a/app/helpers/errors_helper.rb +++ b/app/helpers/errors_helper.rb @@ -95,7 +95,7 @@ def render_error(arg) # rubocop:disable Metrics/AbcSize respond_to do |format| format.html do error_message = "[#{I18n.t(:error_code, code: status)}] #{message}\n#{message_details}" - flash.now[:op_primer_flash] = { scheme: :danger, message: error_message, dismiss_scheme: :none } + flash.now[:error] = { message: error_message, dismiss_scheme: :none } render template: "common/error", layout: use_layout, status:, diff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rb index 4f74da65c59a..fa02f49912c5 100644 --- a/app/helpers/flash_messages_helper.rb +++ b/app/helpers/flash_messages_helper.rb @@ -45,11 +45,11 @@ def render_flash_messages end def render_flash_content(key, content) - case key - when :op_primer_flash - render_flash_message(content[:scheme] || :default, content[:message], **content.except(:message)) + case content + when Hash + render_flash_message(key, **content) else - render_flash_message(key, content) + render_flash_message(key, message: content) end end @@ -74,8 +74,8 @@ def mapped_flash_type(type) end end - def render_flash_message(type, message, **args) - render(OpPrimer::FlashComponent.new(scheme: mapped_flash_type(type), **args.except(:scheme))) do + def render_flash_message(type, message:, **args) + render(OpPrimer::FlashComponent.new(scheme: mapped_flash_type(type), **args)) do join_flash_messages(message) end end diff --git a/lookbook/docs/patterns/08-flash-banner.md.erb b/lookbook/docs/patterns/08-flash-banner.md.erb index 29cd2c232490..667a37ab5915 100644 --- a/lookbook/docs/patterns/08-flash-banner.md.erb +++ b/lookbook/docs/patterns/08-flash-banner.md.erb @@ -17,21 +17,31 @@ See below for available arguments. ## Render primer banner / flash from controllers In many views in OpenProject, you will find `flash[:notice], flash[:alert], flash[:error]` messages. -These are rendered using the previous `op-flash` styles, and are not yet primerized. +All of these are now rendered with primer banners by default. -So if you find yourself in need to render a primerized flash. You can use this pattern instead: +If you find the need to customize the rendering of the flash, you can also pass a hash to the flash: ```ruby -flash[:op_primer_flash] = { message: "Successful update", scheme: :success, icon: :check } +flash[:notice] = { message: "Successful update", icon: :check } ``` Or for an error: ```ruby -flash[:op_primer_flash] = { message: "Oh no! Something went wrong", scheme: :danger, icon: :alert } +flash[:error] = { message: "Oh no! Something went wrong", icon: :alert } ``` -These are rendered in the layout through the `render_banner_messages` helper using the `OpPrimer::FlashComponent`. +If you want to render multiple lines, `message` can also be an array that will be joined by breaklines for rendering: + +```ruby +flash[:error] = { message: ["Oh no! Something went wrong", "Some more details here"], icon: :alert } +``` + +If you want to make the flash non-dismissable, you can pass `dismiss_scheme: :none`: + +```ruby +flash[:error] = { message: "Oh noes!"], icon: :alert, dismiss_scheme: :none } +``` ## Usage in turbo streams 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 b11474c1eb12..3b1ec1ab1c3e 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,10 +73,7 @@ def create service_result = call_update_service if service_result.success? - flash[:op_primer_flash] = { - message: I18n.t(:"storages.notice_successful_storage_connection"), - scheme: :success - } + flash[:notice] = I18n.t(:"storages.notice_successful_storage_connection") redirect_to edit_admin_settings_storage_path(@storage) else respond_with_ampf_form_turbo_stream_or_edit_html 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 fbc7c485a412..9424e717d572 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 @@ def show_redirect_uri end def finish_setup - flash[:op_primer_flash] = { message: I18n.t(:"storages.notice_successful_storage_connection"), scheme: :success } + flash[:notice] = I18n.t(:"storages.notice_successful_storage_connection") 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 c33688428393..4891d9b81197 100644 --- a/modules/storages/app/controllers/storages/admin/storages_controller.rb +++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb @@ -191,9 +191,7 @@ def change_health_notifications_enabled update_via_turbo_stream(component: Storages::Admin::SidePanel::HealthNotificationsComponent.new(storage: @storage)) respond_with_turbo_streams else - flash.now[:op_primer_flash] = { - message: I18n.t("storages.health_email_notifications.error_could_not_be_saved"), scheme: :danger - } + flash.now[:error] = I18n.t("storages.health_email_notifications.error_could_not_be_saved") render :edit end end @@ -209,11 +207,11 @@ def destroy # rubocop:disable Rails/ActionControllerFlashBeforeRender service_result.on_failure do - flash[:op_primer_flash] = { message: join_flash_messages(service_result.errors.full_messages), scheme: :danger } + flash[:error] = service_result.errors.full_messages end service_result.on_success do - flash[:op_primer_flash] = { message: I18n.t(:notice_successful_delete), scheme: :success } + flash[:notice] = I18n.t(:notice_successful_delete) end # rubocop:enable Rails/ActionControllerFlashBeforeRender @@ -265,7 +263,7 @@ def prepare_storage_for_access_management_form 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[:op_primer_flash] = { message: I18n.t("storages.error_invalid_provider_type"), scheme: :danger } + flash[:error] = I18n.t("storages.error_invalid_provider_type") redirect_to admin_settings_storages_path end end