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

Allow flash to receive action_button

Oliver Güntherfc6a986bd86d
diff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rb
index afcb847a709..705db0cbe02 100644
--- a/app/helpers/flash_messages_helper.rb
+++ b/app/helpers/flash_messages_helper.rb
@@ -85,7 +85,16 @@ module FlashMessagesHelper
def build_flash_component(type, *args)
options = args.extract_options!
content = args.first || options[:message]
- OpPrimer::FlashComponent.new(scheme: mapped_flash_type(type), **options)
- .with_content(join_flash_messages(content))
+
+ action_button_arguments = options.delete(:action_button_arguments)
+ action_button_content = options.delete(:action_button_content)
+
+ OpPrimer::FlashComponent.new(scheme: mapped_flash_type(type), **options).tap do |component|
+ component.with_content(join_flash_messages(content))
+
+ if action_button_arguments.present?
+ component.with_action_button(**action_button_arguments) { action_button_content }
+ end
+ end
end
end
diff --git a/lookbook/docs/patterns/08-flash-banner.md.erb b/lookbook/docs/patterns/08-flash-banner.md.erb
index d3055300f6d..bd1327e2717 100644
--- a/lookbook/docs/patterns/08-flash-banner.md.erb
+++ b/lookbook/docs/patterns/08-flash-banner.md.erb
@@ -43,6 +43,20 @@ If you want to make the flash non-dismissable, you can pass `dismiss_scheme: :no
flash[:error] = { message: "Oh no!", icon: :alert, dismiss_scheme: :none }
```
+### Adding an action button
+
+You can add an action button by passing that to the hash:
+
+```ruby
+flash[:error] = {
+ message: "Oh no!",
+ action_button_content: "Button label",
+ action_button_arguments: { tag: :a, href: "/foo" }
+}
+```
+
+For more information on inputs, see the Banner with-action_button slot
+
## Usage in turbo streams
The interesting part is having a flash message responded from within a turbo stream response