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

feat[Op#50985] Add Primer Flash

Kabiru Mwenja75f4179a6769
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 353511180a8..d15e7ee1df3 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -115,8 +115,20 @@ module ApplicationHelper
end
end
+ def render_primer_flash_message?
+ flash[:primer_flash].present?
+ end
+
+ def render_primer_flash_message
+ return unless render_primer_flash_message?
+
+ render(FlashMessageComponent.new(**flash[:primer_flash].to_hash))
+ end
+
# Renders flash messages
- def render_flash_messages
+ def render_legacy_flash_messages
+ return if render_primer_flash_message?
+
messages = flash
.reject { |k, _| k.start_with? '_' }
.map do |k, v|
@@ -139,20 +151,24 @@ module ApplicationHelper
end
end
- def render_flash_message(type, message, html_options = {})
+ def render_legacy_flash_message(type, message, html_options = {}) # rubocop:disable Metrics/AbcSize
if type.to_s == 'notice'
type = 'success'
end
+
toast_css_classes = ["op-toast -#{type}", html_options.delete(:class)]
+
# Add autohide class to notice flashes if configured
if type.to_s == 'success' && User.current.pref.auto_hide_popups?
toast_css_classes << 'autohide-toaster'
end
+
html_options = { class: toast_css_classes.join(' '), role: 'alert' }.merge(html_options)
close_button = content_tag :a, '', class: 'op-toast--close icon-context icon-close',
title: I18n.t('js.close_popup_title'),
tabindex: '0'
toast = content_tag(:div, join_flash_messages(message), class: 'op-toast--content')
+
content_tag :div, '', class: 'op-toast--wrapper' do
content_tag :div, '', class: 'op-toast--casing' do
content_tag :div, html_options do
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index b5030dc7904..1c8889d18de 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -115,6 +115,7 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<div class="content-overlay"></div>
<main id="content-wrapper" class="<%= initial_classes %>">
+ <%= render_primer_flash_message %>
<% if show_decoration %>
<div id="breadcrumb" class="<%= initial_classes %><%= show_breadcrumb ? ' -show' : '' %>">
<%= you_are_here_info %>
@@ -124,7 +125,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= call_hook :view_layouts_base_breadcrumb %>
</div>
<% end %>
- <%= render_flash_messages %>
+ <%= render_legacy_flash_messages %>
<% if show_onboarding_modal? %>
<section data-augmented-model-wrapper
data-modal-initialize-now="true"