diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb
index d12beda51..dac471bc8 100644
--- a/app/components/admin/table_actions_component.html.erb
+++ b/app/components/admin/table_actions_component.html.erb
@@ -1,11 +1,11 @@
<% if actions.include?(:edit) %>
- <%= link_to t("admin.actions.edit"),
+ <%= link_to edit_text,
admin_polymorphic_path(record, action: :edit),
class: "button hollow" %>
<% end %>
<% if actions.include?(:destroy) %>
- <%= link_to t("admin.actions.delete"),
+ <%= link_to destroy_text,
admin_polymorphic_path(record),
method: :delete,
class: "button hollow alert",
diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb
index c1a95dff7..b016cadc1 100644
--- a/app/components/admin/table_actions_component.rb
+++ b/app/components/admin/table_actions_component.rb
@@ -1,8 +1,22 @@
class Admin::TableActionsComponent < ApplicationComponent
- attr_reader :record, :actions
+ attr_reader :record, :options
- def initialize(record, actions: [:edit, :destroy])
+ def initialize(record, **options)
@record = record
- @actions = actions
+ @options = options
end
+
+ private
+
+ def actions
+ options[:actions] || [:edit, :destroy]
+ end
+
+ def edit_text
+ options[:edit_text] || t("admin.actions.edit")
+ end
+
+ def destroy_text
+ options[:destroy_text] || t("admin.actions.delete")
+ end
end
diff --git a/app/views/admin/banners/index.html.erb b/app/views/admin/banners/index.html.erb
index 4b3e97230..1a0783c2a 100644
--- a/app/views/admin/banners/index.html.erb
+++ b/app/views/admin/banners/index.html.erb
@@ -21,15 +21,10 @@
<%= banner.post_started_at %> |
<%= banner.post_ended_at %> |
-
- <%= link_to t("admin.banners.index.edit"), edit_admin_banner_path(banner),
- class: "button hollow expanded" %>
-
-
- <%= link_to t("admin.banners.index.delete"), admin_banner_path(banner),
- method: :delete,
- class: "button hollow alert expanded" %>
-
+ <%= render Admin::TableActionsComponent.new(banner,
+ edit_text: t("admin.banners.index.edit"),
+ destroy_text: t("admin.banners.index.delete")
+ ) %>
|
diff --git a/app/views/admin/dashboard/administrator_tasks/index.html.erb b/app/views/admin/dashboard/administrator_tasks/index.html.erb
index 748272a34..93cebb001 100644
--- a/app/views/admin/dashboard/administrator_tasks/index.html.erb
+++ b/app/views/admin/dashboard/administrator_tasks/index.html.erb
@@ -25,9 +25,10 @@
|
<% unless task.executed_at? %>
- <%= link_to t("admin.dashboard.administrator_tasks.index.solve"),
- edit_admin_dashboard_administrator_task_path(task),
- class: "button hollow" %>
+ <%= render Admin::TableActionsComponent.new(task,
+ actions: [:edit],
+ edit_text: t("admin.dashboard.administrator_tasks.index.solve")
+ ) %>
<% end %>
|
diff --git a/app/views/admin/milestones/_milestones.html.erb b/app/views/admin/milestones/_milestones.html.erb
index 84f4a65ab..f3c1e1991 100644
--- a/app/views/admin/milestones/_milestones.html.erb
+++ b/app/views/admin/milestones/_milestones.html.erb
@@ -56,10 +56,10 @@
<% end %>
- <%= link_to t("admin.milestones.index.delete"),
- admin_polymorphic_path(milestone),
- method: :delete,
- class: "button hollow alert expanded" %>
+ <%= render Admin::TableActionsComponent.new(milestone,
+ actions: [:destroy],
+ destroy_text: t("admin.milestones.index.delete")
+ ) %>
|
<% end %>
diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb
index 6bef50aae..bca880e5d 100644
--- a/app/views/admin/poll/booths/_booth.html.erb
+++ b/app/views/admin/poll/booths/_booth.html.erb
@@ -11,9 +11,10 @@
new_admin_booth_shift_path(booth),
class: "button hollow" %>
<% else %>
- <%= link_to t("admin.booths.booth.edit"),
- edit_admin_booth_path(booth),
- class: "button hollow" %>
+ <%= render Admin::TableActionsComponent.new(booth,
+ actions: [:edit],
+ edit_text: t("admin.booths.booth.edit")
+ ) %>
<% end %>
diff --git a/app/views/admin/poll/officers/_officer.html.erb b/app/views/admin/poll/officers/_officer.html.erb
index 70fc18ec1..45e516594 100644
--- a/app/views/admin/poll/officers/_officer.html.erb
+++ b/app/views/admin/poll/officers/_officer.html.erb
@@ -16,10 +16,10 @@
<% if officer.persisted? %>
- <%= link_to t("admin.poll_officers.officer.delete"),
- admin_officer_path(officer),
- method: :delete,
- class: "button hollow alert expanded" %>
+ <%= render Admin::TableActionsComponent.new(officer,
+ actions: [:destroy],
+ destroy_text: t("admin.poll_officers.officer.delete")
+ ) %>
<% else %>
<%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id },
method: :post,
diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb
index 640369feb..02b67492f 100644
--- a/app/views/admin/poll/officers/index.html.erb
+++ b/app/views/admin/poll/officers/index.html.erb
@@ -30,11 +30,10 @@
|
<% if officer.persisted? %>
- <%= link_to t("admin.poll_officers.officer.delete"),
- admin_officer_path(officer),
- method: :delete,
- class: "button hollow alert expanded"
- %>
+ <%= render Admin::TableActionsComponent.new(officer,
+ actions: [:destroy],
+ destroy_text: t("admin.poll_officers.officer.delete")
+ ) %>
<% else %>
<%= link_to t("admin.poll_officers.officer.add"),
{ controller: "admin/poll/officers", action: :create,
diff --git a/app/views/admin/poll/shifts/_shifts.html.erb b/app/views/admin/poll/shifts/_shifts.html.erb
index 140ae43c9..af3c0e662 100644
--- a/app/views/admin/poll/shifts/_shifts.html.erb
+++ b/app/views/admin/poll/shifts/_shifts.html.erb
@@ -6,7 +6,7 @@
| <%= t("admin.poll_shifts.new.officer") %> |
<%= t("admin.poll_shifts.new.table_email") %> |
<%= Poll::Shift.human_attribute_name(:task) %> |
- <%= t("admin.poll_shifts.new.shift") %> |
+ <%= t("admin.poll_shifts.new.shift") %> |
@@ -17,10 +17,10 @@
<%= shift.officer_email %> |
<%= t("admin.poll_shifts.#{shift.task}") %> |
- <%= link_to t("admin.poll_shifts.new.remove_shift"),
- admin_booth_shift_path(@booth, shift),
- method: :delete,
- class: "button hollow alert expanded" %>
+ <%= render Admin::TableActionsComponent.new(shift,
+ actions: [:destroy],
+ destroy_text: t("admin.poll_shifts.new.remove_shift")
+ ) %>
|
<% end %>
diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb
index 17328f8a2..33bdcf756 100644
--- a/app/views/admin/site_customization/content_blocks/index.html.erb
+++ b/app/views/admin/site_customization/content_blocks/index.html.erb
@@ -34,9 +34,10 @@
<%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %> |
<%= raw content_block.body %> |
- <%= link_to t("admin.site_customization.content_blocks.index.delete"),
- admin_site_customization_content_block_path(content_block),
- method: :delete, class: "button hollow alert" %>
+ <%= render Admin::TableActionsComponent.new(content_block,
+ actions: [:destroy],
+ destroy_text: t("admin.site_customization.content_blocks.index.delete")
+ ) %>
|
<% end %>
diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb
index d902086fc..d22efec9b 100644
--- a/app/views/admin/site_customization/pages/index.html.erb
+++ b/app/views/admin/site_customization/pages/index.html.erb
@@ -35,20 +35,17 @@
<%= I18n.l page.created_at, format: :short %> |
<%= t("admin.site_customization.pages.page.status_#{page.status}") %> |
-
- <% if page.status == "published" %>
- <%= link_to t("admin.site_customization.pages.index.see_page"),
- page.url,
- target: "_blank",
- class: "button hollow expanded" %>
- <% end %>
-
-
- <%= link_to t("admin.site_customization.pages.index.delete"),
- admin_site_customization_page_path(page),
- method: :delete,
- class: "button hollow alert expanded" %>
-
+ <% if page.status == "published" %>
+ <%= link_to t("admin.site_customization.pages.index.see_page"),
+ page.url,
+ target: "_blank",
+ class: "button hollow" %>
+ <% end %>
+
+ <%= render Admin::TableActionsComponent.new(page,
+ actions: [:destroy],
+ destroy_text: t("admin.site_customization.pages.index.delete")
+ ) %>
|
<% end %>
diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb
index 26e58e040..d50d4283b 100644
--- a/app/views/admin/tags/index.html.erb
+++ b/app/views/admin/tags/index.html.erb
@@ -30,7 +30,7 @@
<% end %>
- <%= link_to t("admin.tags.destroy"), admin_tag_path(tag), method: :delete, class: "button hollow alert" %>
+ <%= render Admin::TableActionsComponent.new(tag, actions: [:destroy], destroy_text: t("admin.tags.destroy")) %>
|
<% end %>
diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb
index d4161b2d2..b6d7c43cf 100644
--- a/spec/components/admin/table_actions_component_spec.rb
+++ b/spec/components/admin/table_actions_component_spec.rb
@@ -26,4 +26,13 @@ describe Admin::TableActionsComponent, type: :component do
expect(page).not_to have_link "Edit"
end
end
+
+ it "allows custom texts for actions" do
+ render_inline Admin::TableActionsComponent.new(record, edit_text: "change", destroy_text: "annihilate")
+
+ expect(page).to have_link "annihilate"
+ expect(page).to have_link "change"
+ expect(page).not_to have_link "Delete"
+ expect(page).not_to have_link "Edit"
+ end
end