Skip to content

Commit

Permalink
add rerun flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Sep 27, 2024
1 parent 6e268eb commit 6d5c288
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
37 changes: 37 additions & 0 deletions app/services/admin/actions/replay_flow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Admin
module Actions
class ReplayFlow < RailsAdmin::Config::Actions::Base
RailsAdmin::Config::Actions.register(ReplayFlow)

register_instance_option :member do
true
end

register_instance_option :visible? do
bindings[:object].is_a?(NotificationRequest)
end

register_instance_option :http_methods do
%i[get]
end

register_instance_option :link_icon do
# FontAwesome Icons
'icon-repeat'
end

register_instance_option :controller do
proc do
flash[:success] = "We're replaying this flow right now!"
if Rails.env.production?
HardWorker.perform_async(@object.id)
else
notification_request = NotificationRequest.find_by(id: @object.id)
MessageSender.call(notification_request)
end
redirect_to back_or_index
end
end
end
end
end
4 changes: 4 additions & 0 deletions config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'nested_form/engine'
require 'nested_form/builder_mixin'

require Rails.root.join('app/services/admin/actions/replay_flow.rb')

RailsAdmin.config do |config|
if Rails.env.production?
config.authorize_with do
Expand Down Expand Up @@ -46,6 +48,8 @@
edit
delete
show_in_app
replay_flow


## With an audit adapter, you can add:
# history_index
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
# available at https://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
admin:
actions:
replay_flow:
menu: "Rerun flow"

0 comments on commit 6d5c288

Please sign in to comment.