diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index e2d859a9b..2648f99dc 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,11 +1,7 @@ <% if actions.include?(:edit) %> - <%= link_to edit_text, edit_path, class: "button hollow" %> + <%= link_to edit_text, edit_path, edit_options %> <% end %> <% if actions.include?(:destroy) %> - <%= link_to destroy_text, - destroy_path, - method: :delete, - class: "button hollow alert", - data: { confirm: destroy_confirmation } %> + <%= link_to destroy_text, destroy_path, destroy_options %> <% end %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index 740538ab0..339dc4c6c 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -20,6 +20,10 @@ class Admin::TableActionsComponent < ApplicationComponent options[:edit_path] || admin_polymorphic_path(record, action: :edit) end + def edit_options + { class: "button hollow" }.merge(options[:edit_options] || {}) + end + def destroy_text options[:destroy_text] || t("admin.actions.delete") end @@ -28,6 +32,14 @@ class Admin::TableActionsComponent < ApplicationComponent options[:destroy_path] || admin_polymorphic_path(record) end + def destroy_options + { + method: :delete, + class: "button hollow alert", + data: { confirm: destroy_confirmation } + }.merge(options[:destroy_options] || {}) + end + def destroy_confirmation options[:destroy_confirmation] || t("admin.actions.confirm") end diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb index 8f159a264..1663ac00f 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -11,13 +11,14 @@ - <%= link_to t("admin.booth_assignments.manage.actions.unassign"), - admin_poll_booth_assignment_path(@poll, booth_assignment), - method: :delete, - remote: true, - title: t("admin.booth_assignments.manage.actions.unassign"), - class: "button hollow alert expanded", - data: (booth_assignment.shifts? ? { confirm: "#{t("admin.poll_booth_assignments.alert.shifts")}" } : nil) if !@poll.expired? %> + <% unless @poll.expired? %> + <%= render Admin::TableActionsComponent.new(booth_assignment, + actions: [:destroy], + destroy_text: t("admin.booth_assignments.manage.actions.unassign"), + destroy_confirmation: (booth_assignment.shifts? ? "#{t("admin.poll_booth_assignments.alert.shifts")}" : ""), + destroy_options: { remote: true } + ) %> + <% end %> <% else %> diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index 7ccbf950f..eba078a57 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -48,4 +48,10 @@ describe Admin::TableActionsComponent, type: :component do expect(page).to have_css "a[data-confirm='Are you mad? Be careful!']" end + + it "allows custom options" do + render_inline Admin::TableActionsComponent.new(record, edit_options: { id: "edit_me" }) + + expect(page).to have_css "a#edit_me" + end end