From 6a2c01b11907028cc07896fec429aed04085b6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 17 Aug 2021 22:21:38 +0200 Subject: [PATCH] Extract method to render an admin table action This way it will be easier to change the behavior of all table actions, like adding ARIA attributes. In the past, when we changed the behavior of the `link_to` method, we had to change all table action classes. --- .../admin/action_component.html.erb | 1 + app/components/admin/action_component.rb | 47 +++++++++++++++++++ .../budget_groups/groups_component.html.erb | 6 +-- .../admin/budget_groups/groups_component.rb | 5 +- .../budgets/table_actions_component.html.erb | 33 +++++++------ .../admin/budgets/table_actions_component.rb | 17 +++---- .../hidden_table_actions_component.html.erb | 18 +++---- .../table_actions_component.html.erb | 14 +++--- .../poll/officers/officers_component.html.erb | 10 ++-- .../roles/table_actions_component.html.erb | 4 +- .../admin/table_actions_component.html.erb | 4 +- .../admin/table_actions_component.rb | 22 ++++----- .../admin/admin_notifications/index.html.erb | 10 ++-- app/views/admin/audits/_audits.html.erb | 6 +-- .../actions/_default_actions.html.erb | 1 + app/views/admin/newsletters/index.html.erb | 4 +- app/views/admin/officials/index.html.erb | 1 + app/views/admin/officials/search.html.erb | 1 + .../_booth_assignment.html.erb | 12 ++--- app/views/admin/poll/booths/_booth.html.erb | 8 ++-- app/views/admin/poll/polls/_poll.html.erb | 4 +- .../admin/poll/polls/_questions.html.erb | 3 +- .../poll/polls/booth_assignments.html.erb | 8 ++-- .../admin/poll/questions/_questions.html.erb | 3 +- .../questions/_successful_proposals.html.erb | 10 ++-- .../poll/questions/answers/documents.html.erb | 10 ++-- .../shifts/_search_officers_results.html.erb | 1 + .../content_blocks/index.html.erb | 1 + .../documents/index.html.erb | 1 + .../site_customization/pages/index.html.erb | 14 +++--- app/views/admin/system_emails/index.html.erb | 22 ++++----- .../admin/valuators/_valuator_row.html.erb | 4 +- .../components/admin/action_component_spec.rb | 9 ++++ .../table_actions_component_spec.rb | 2 +- .../admin/table_actions_component_spec.rb | 2 +- 35 files changed, 184 insertions(+), 134 deletions(-) create mode 100644 app/components/admin/action_component.html.erb create mode 100644 app/components/admin/action_component.rb create mode 100644 spec/components/admin/action_component_spec.rb diff --git a/app/components/admin/action_component.html.erb b/app/components/admin/action_component.html.erb new file mode 100644 index 000000000..f31ab4bbd --- /dev/null +++ b/app/components/admin/action_component.html.erb @@ -0,0 +1 @@ +<%= link_to text, path, html_options %> diff --git a/app/components/admin/action_component.rb b/app/components/admin/action_component.rb new file mode 100644 index 000000000..ab499d8fb --- /dev/null +++ b/app/components/admin/action_component.rb @@ -0,0 +1,47 @@ +class Admin::ActionComponent < ApplicationComponent + include Admin::Namespace + attr_reader :action, :record, :options + + def initialize(action, record, **options) + @action = action + @record = record + @options = options + end + + private + + def text + options[:text] || t("admin.actions.#{action}") + end + + def path + options[:path] || default_path + end + + def html_options + { + class: html_class, + data: { confirm: confirmation_text } + }.merge(options.except(:confirm, :path, :text)) + end + + def html_class + "#{action.to_s.gsub("_", "-")}-link" + end + + def confirmation_text + if options[:confirm] == true + t("admin.actions.confirm") + else + options[:confirm] + end + end + + def default_path + if %i[answers configure destroy preview show].include?(action.to_sym) + namespaced_polymorphic_path(namespace, record) + else + namespaced_polymorphic_path(namespace, record, { action: action }.merge(request.query_parameters)) + end + end +end diff --git a/app/components/admin/budget_groups/groups_component.html.erb b/app/components/admin/budget_groups/groups_component.html.erb index 2b8f1d596..97ad95e01 100644 --- a/app/components/admin/budget_groups/groups_component.html.erb +++ b/app/components/admin/budget_groups/groups_component.html.erb @@ -17,9 +17,9 @@ <%= group.headings.count %> <%= render Admin::TableActionsComponent.new(group) do |actions| %> - <%= actions.link_to t("admin.budget_groups.headings_manage"), - headings_path(actions, group), - class: "headings-link" %> + <%= actions.action(:headings, + text: t("admin.budget_groups.headings_manage"), + path: headings_path(group)) %> <% end %> diff --git a/app/components/admin/budget_groups/groups_component.rb b/app/components/admin/budget_groups/groups_component.rb index 51bf60649..09ba87bbf 100644 --- a/app/components/admin/budget_groups/groups_component.rb +++ b/app/components/admin/budget_groups/groups_component.rb @@ -1,4 +1,5 @@ class Admin::BudgetGroups::GroupsComponent < ApplicationComponent + include Admin::Namespace attr_reader :groups def initialize(groups) @@ -11,7 +12,7 @@ class Admin::BudgetGroups::GroupsComponent < ApplicationComponent @budget ||= groups.first.budget end - def headings_path(table_actions_component, group) - send("#{table_actions_component.namespace}_budget_group_headings_path", group.budget, group) + def headings_path(group) + send("#{namespace}_budget_group_headings_path", group.budget, group) end end diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb index 90677909e..7a57c9134 100644 --- a/app/components/admin/budgets/table_actions_component.html.erb +++ b/app/components/admin/budgets/table_actions_component.html.erb @@ -1,22 +1,25 @@ <%= render Admin::TableActionsComponent.new(budget, destroy_confirmation: t("admin.actions.confirm_delete", resource_name: t("admin.budgets.shared.resource_name"), name: budget.name) - ) do %> - <%= link_to t("admin.budgets.index.budget_investments"), - admin_budget_budget_investments_path(budget_id: budget.id), - class: "investments-link" %> - <%= link_to t("admin.budgets.index.edit_groups"), - admin_budget_groups_path(budget), - class: "groups-link" %> + ) do |actions| %> + <%= actions.action(:investments, + text: t("admin.budgets.index.budget_investments"), + path: admin_budget_budget_investments_path(budget_id: budget.id)) %> + <%= actions.action(:groups, + text: t("admin.budgets.index.edit_groups"), + path: admin_budget_groups_path(budget)) %> <% if budget.poll.present? %> - <%= link_to t("admin.budgets.index.admin_ballots"), - admin_poll_booth_assignments_path(budget.poll), - class: "ballots-link" %> + <%= actions.action(:ballots, + text: t("admin.budgets.index.admin_ballots"), + path: admin_poll_booth_assignments_path(budget.poll)) %> <% else %> - <%= link_to_create_budget_poll %> + <%= actions.action(:ballots, + text: t("admin.budgets.index.admin_ballots"), + path: create_budget_poll_path, + method: :post) %> <% end %> - <%= link_to t("admin.budgets.actions.preview"), - budget_path(budget), - target: "_blank", - class: "preview-link" %> + <%= actions.action(:preview, + text: t("admin.budgets.actions.preview"), + path: budget_path(budget), + target: "_blank") %> <% end %> diff --git a/app/components/admin/budgets/table_actions_component.rb b/app/components/admin/budgets/table_actions_component.rb index 9a90a3799..0e0dfde97 100644 --- a/app/components/admin/budgets/table_actions_component.rb +++ b/app/components/admin/budgets/table_actions_component.rb @@ -7,17 +7,14 @@ class Admin::Budgets::TableActionsComponent < ApplicationComponent private - def link_to_create_budget_poll + def create_budget_poll_path balloting_phase = budget.phases.find_by(kind: "balloting") - link_to t("admin.budgets.index.admin_ballots"), - admin_polls_path(poll: { - name: budget.name, - budget_id: budget.id, - starts_at: balloting_phase.starts_at, - ends_at: balloting_phase.ends_at - }), - class: "ballots-link", - method: :post + admin_polls_path(poll: { + name: budget.name, + budget_id: budget.id, + starts_at: balloting_phase.starts_at, + ends_at: balloting_phase.ends_at + }) end end diff --git a/app/components/admin/hidden_table_actions_component.html.erb b/app/components/admin/hidden_table_actions_component.html.erb index dad308a78..e8a444900 100644 --- a/app/components/admin/hidden_table_actions_component.html.erb +++ b/app/components/admin/hidden_table_actions_component.html.erb @@ -1,12 +1,14 @@ -<%= render Admin::TableActionsComponent.new(actions: []) do %> - <%= link_to restore_text, restore_path, - method: :put, - data: { confirm: t("admin.actions.confirm") }, - class: "restore-link" %> +<%= render Admin::TableActionsComponent.new(record, actions: []) do |actions| %> + <%= actions.action(:restore, + text: restore_text, + path: restore_path, + method: :put, + confirm: true) %> <% unless record.confirmed_hide? %> - <%= link_to confirm_hide_text, confirm_hide_path, - method: :put, - class: "confirm-hide-link" %> + <%= actions.action(:confirm_hide, + text: confirm_hide_text, + path: confirm_hide_path, + method: :put) %> <% end %> <% end %> diff --git a/app/components/admin/organizations/table_actions_component.html.erb b/app/components/admin/organizations/table_actions_component.html.erb index dd9c521a1..ce93ebf14 100644 --- a/app/components/admin/organizations/table_actions_component.html.erb +++ b/app/components/admin/organizations/table_actions_component.html.erb @@ -1,13 +1,13 @@ -<%= render Admin::TableActionsComponent.new(actions: []) do %> +<%= render Admin::TableActionsComponent.new(organization, actions: []) do |actions| %> <% if can_verify? %> - <%= link_to t("admin.organizations.index.verify"), - verify_admin_organization_path(organization, request.query_parameters), - method: :put, class: "verify-link" %> + <%= actions.action(:verify, + text: t("admin.organizations.index.verify"), + method: :put) %> <% end %> <% if can_reject? %> - <%= link_to t("admin.organizations.index.reject"), - reject_admin_organization_path(organization, request.query_parameters), - method: :put, class: "reject-link" %> + <%= actions.action(:reject, + text: t("admin.organizations.index.reject"), + method: :put) %> <% end %> <% end %> diff --git a/app/components/admin/poll/officers/officers_component.html.erb b/app/components/admin/poll/officers/officers_component.html.erb index 3ef36fd13..f35ae2793 100644 --- a/app/components/admin/poll/officers/officers_component.html.erb +++ b/app/components/admin/poll/officers/officers_component.html.erb @@ -23,11 +23,11 @@ destroy_options: { class: "destroy-officer-link" } ) %> <% else %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.poll_officers.officer.add"), - add_user_path(officer), - method: :post, - class: "create-officer-link" %> + <%= render Admin::TableActionsComponent.new(officer, actions: []) do |actions| %> + <%= actions.action(:create_officer, + text: t("admin.poll_officers.officer.add"), + path: add_user_path(officer), + method: :post) %> <% end %> <% end %> diff --git a/app/components/admin/roles/table_actions_component.html.erb b/app/components/admin/roles/table_actions_component.html.erb index 59aed5763..305c18ed4 100644 --- a/app/components/admin/roles/table_actions_component.html.erb +++ b/app/components/admin/roles/table_actions_component.html.erb @@ -4,7 +4,7 @@ destroy_options: { class: "destroy-role-link" } ) %> <% else %> - <%= render Admin::TableActionsComponent.new(actions: []) do %> - <%= link_to add_user_text, add_user_path, method: :post, class: "create-role-link" %> + <%= render Admin::TableActionsComponent.new(record, actions: []) do |actions| %> + <%= actions.action(:create_role, text: add_user_text, path: add_user_path, method: :post) %> <% end %> <% end %> diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index b5430cf8a..0bc434bac 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -2,10 +2,10 @@ <%= content %> <% if actions.include?(:edit) %> - <%= link_to edit_text, edit_path, edit_options %> + <%= action(:edit, edit_options.merge(text: edit_text, path: edit_path)) %> <% end %> <% if actions.include?(:destroy) %> - <%= link_to destroy_text, destroy_path, destroy_options %> + <%= action(:destroy, destroy_options.merge(text: destroy_text, path: destroy_path)) %> <% end %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index f920447bc..9a159e8ab 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -1,12 +1,15 @@ class Admin::TableActionsComponent < ApplicationComponent - include Admin::Namespace attr_reader :record, :options - def initialize(record = nil, **options) + def initialize(record, **options) @record = record @options = options end + def action(action_name, **args) + render Admin::ActionComponent.new(action_name, record, **args) + end + private def actions @@ -14,15 +17,15 @@ class Admin::TableActionsComponent < ApplicationComponent end def edit_text - options[:edit_text] || t("admin.actions.edit") + options[:edit_text] end def edit_path - options[:edit_path] || namespaced_polymorphic_path(namespace, record, action: :edit) + options[:edit_path] end def edit_options - { class: "edit-link" }.merge(options[:edit_options] || {}) + options[:edit_options] || {} end def destroy_text @@ -30,18 +33,13 @@ class Admin::TableActionsComponent < ApplicationComponent end def destroy_path - options[:destroy_path] || namespaced_polymorphic_path(namespace, record) + options[:destroy_path] end def destroy_options { method: :delete, - class: "destroy-link", - data: { confirm: destroy_confirmation } + confirm: options[:destroy_confirmation] || true }.merge(options[:destroy_options] || {}) end - - def destroy_confirmation - options[:destroy_confirmation] || t("admin.actions.confirm") - end end diff --git a/app/views/admin/admin_notifications/index.html.erb b/app/views/admin/admin_notifications/index.html.erb index d51ac2c8b..c8fbe4900 100644 --- a/app/views/admin/admin_notifications/index.html.erb +++ b/app/views/admin/admin_notifications/index.html.erb @@ -31,15 +31,11 @@ <% if admin_notification.draft? %> <%= render Admin::TableActionsComponent.new(admin_notification) do |actions| %> - <%= actions.link_to t("admin.admin_notifications.index.preview"), - admin_admin_notification_path(admin_notification), - class: "preview-link" %> + <%= actions.action(:preview, text: t("admin.admin_notifications.index.preview")) %> <% end %> <% else %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.admin_notifications.index.view"), - admin_admin_notification_path(admin_notification), - class: "show-link" %> + <%= render Admin::TableActionsComponent.new(admin_notification, actions: []) do |actions| %> + <%= actions.action(:show, text: t("admin.admin_notifications.index.view")) %> <% end %> <% end %> diff --git a/app/views/admin/audits/_audits.html.erb b/app/views/admin/audits/_audits.html.erb index aa72d36b8..ff84c3c11 100644 --- a/app/views/admin/audits/_audits.html.erb +++ b/app/views/admin/audits/_audits.html.erb @@ -34,10 +34,8 @@ <%= audit.user&.name %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("shared.show"), - admin_polymorphic_path(audit), - class: "show-link" %> + <%= render Admin::TableActionsComponent.new(audit, actions: []) do |actions| %> + <%= actions.action(:show, text: t("shared.show")) %> <% end %> diff --git a/app/views/admin/dashboard/actions/_default_actions.html.erb b/app/views/admin/dashboard/actions/_default_actions.html.erb index 896c02a7e..94ec8b79f 100644 --- a/app/views/admin/dashboard/actions/_default_actions.html.erb +++ b/app/views/admin/dashboard/actions/_default_actions.html.erb @@ -6,6 +6,7 @@   <%= render Admin::TableActionsComponent.new( + action, actions: [:edit], edit_path: admin_settings_path(anchor: "tab-proposals"), ) %> diff --git a/app/views/admin/newsletters/index.html.erb b/app/views/admin/newsletters/index.html.erb index e5c0e2427..46270436b 100644 --- a/app/views/admin/newsletters/index.html.erb +++ b/app/views/admin/newsletters/index.html.erb @@ -30,9 +30,7 @@ <%= render Admin::TableActionsComponent.new(newsletter) do |actions| %> - <%= actions.link_to t("admin.newsletters.index.preview"), - admin_newsletter_path(newsletter), - class: "preview-link" %> + <%= actions.action :preview, text: t("admin.newsletters.index.preview") %> <% end %> diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index 6212778cc..7517b6e3d 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -27,6 +27,7 @@ <%= render Admin::TableActionsComponent.new( + official, actions: [:edit], edit_path: edit_admin_official_path(official) ) %> diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb index bf9706207..5e361d9e7 100644 --- a/app/views/admin/officials/search.html.erb +++ b/app/views/admin/officials/search.html.erb @@ -33,6 +33,7 @@ <%= render Admin::TableActionsComponent.new( + user, actions: [:edit], edit_path: edit_admin_official_path(user), edit_text: (t("admin.officials.search.make_official") unless user.official?) 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 a4060f8aa..3da870b1f 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -26,12 +26,12 @@ <% unless @poll.expired? %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.booth_assignments.manage.actions.assign"), - admin_poll_booth_assignments_path(@poll, booth_id: booth.id), - method: :post, - remote: true, - class: "assign-booth-link" %> + <%= render Admin::TableActionsComponent.new(booth, actions: []) do |actions| %> + <%= actions.action(:assign_booth, + text: t("admin.booth_assignments.manage.actions.assign"), + path: admin_poll_booth_assignments_path(@poll, booth_id: booth.id), + method: :post, + remote: true) %> <% end %> <% end %> diff --git a/app/views/admin/poll/booths/_booth.html.erb b/app/views/admin/poll/booths/_booth.html.erb index efa5a172c..7dfda2ae8 100644 --- a/app/views/admin/poll/booths/_booth.html.erb +++ b/app/views/admin/poll/booths/_booth.html.erb @@ -7,10 +7,10 @@ <% if controller_name == "shifts" || controller_name == "booths" && action_name == "available" %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.booths.booth.shifts"), - new_admin_booth_shift_path(booth), - class: "shifts-link" %> + <%= render Admin::TableActionsComponent.new(booth, actions: []) do |actions| %> + <%= actions.action(:shifts, + text: t("admin.booths.booth.shifts"), + path: new_admin_booth_shift_path(booth)) %> <% end %> <% else %> <%= render Admin::TableActionsComponent.new(booth, actions: [:edit]) %> diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb index 364cc24db..a578bfe60 100644 --- a/app/views/admin/poll/polls/_poll.html.erb +++ b/app/views/admin/poll/polls/_poll.html.erb @@ -10,9 +10,7 @@ <%= render Admin::TableActionsComponent.new(poll, destroy_confirmation: t("admin.polls.destroy.alert") ) do |actions| %> - <%= actions.link_to t("admin.actions.configure"), - admin_poll_path(poll), - class: "configure-link" %> + <%= actions.action(:configure) %> <% end %> diff --git a/app/views/admin/poll/polls/_questions.html.erb b/app/views/admin/poll/polls/_questions.html.erb index 2cde94099..b13a86be2 100644 --- a/app/views/admin/poll/polls/_questions.html.erb +++ b/app/views/admin/poll/polls/_questions.html.erb @@ -29,8 +29,7 @@ <%= render Admin::TableActionsComponent.new(question) do |actions| %> - <%= actions.link_to t("admin.polls.show.edit_answers"), admin_question_path(question), - class: "answers-link" %> + <%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %> <% end %> diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb index ece854d29..401ef0011 100644 --- a/app/views/admin/poll/polls/booth_assignments.html.erb +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -15,10 +15,10 @@ <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.booth_assignments.manage_assignments"), - manage_admin_poll_booth_assignments_path(poll), - class: "manage-link" %> + <%= render Admin::TableActionsComponent.new(poll, actions: []) do |actions| %> + <%= actions.action(:manage, + text: t("admin.booth_assignments.manage_assignments"), + path: manage_admin_poll_booth_assignments_path(poll)) %> <% end %> diff --git a/app/views/admin/poll/questions/_questions.html.erb b/app/views/admin/poll/questions/_questions.html.erb index e8ce0402e..100425478 100644 --- a/app/views/admin/poll/questions/_questions.html.erb +++ b/app/views/admin/poll/questions/_questions.html.erb @@ -26,8 +26,7 @@ <%= render Admin::TableActionsComponent.new(question) do |actions| %> - <%= actions.link_to t("admin.polls.show.edit_answers"), admin_question_path(question), - class: "answers-link" %> + <%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %> <% end %> diff --git a/app/views/admin/poll/questions/_successful_proposals.html.erb b/app/views/admin/poll/questions/_successful_proposals.html.erb index 1a4b06aad..669d76c94 100644 --- a/app/views/admin/poll/questions/_successful_proposals.html.erb +++ b/app/views/admin/poll/questions/_successful_proposals.html.erb @@ -15,11 +15,11 @@

- <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> - <%= actions.link_to t("admin.shared.view"), proposal_path(proposal), class: "show-link" %> - <%= actions.link_to t("admin.questions.index.create_question"), - new_admin_question_path(proposal_id: proposal.id), - class: "new-link" %> + <%= render Admin::TableActionsComponent.new(proposal, actions: []) do |actions| %> + <%= actions.action(:show, text: t("admin.shared.view"), path: proposal_path(proposal)) %> + <%= actions.action(:new, + text: t("admin.questions.index.create_question"), + path: new_admin_question_path(proposal_id: proposal.id)) %> <% end %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 71d6baeb5..53d78996a 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -40,11 +40,11 @@ actions: [:destroy], destroy_path: document_path(document) ) do |actions| %> - <%= actions.link_to t("documents.buttons.download_document"), - document.attachment.url, - target: "_blank", - rel: "nofollow", - class: "download-link" %> + <%= actions.action(:download, + text: t("documents.buttons.download_document"), + path: document.attachment.url, + target: "_blank", + rel: "nofollow") %> <% end %> diff --git a/app/views/admin/poll/shifts/_search_officers_results.html.erb b/app/views/admin/poll/shifts/_search_officers_results.html.erb index 27280e2c9..8e2eed699 100644 --- a/app/views/admin/poll/shifts/_search_officers_results.html.erb +++ b/app/views/admin/poll/shifts/_search_officers_results.html.erb @@ -24,6 +24,7 @@ <%= render Admin::TableActionsComponent.new( + user, actions: [:edit], edit_text: t("admin.poll_shifts.new.edit_shifts"), edit_path: new_admin_booth_shift_path(officer_id: user.poll_officer.id) 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 79a6f44f2..11c3a8493 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -44,6 +44,7 @@ <%= raw content_block.body %> <%= render Admin::TableActionsComponent.new( + content_block, actions: [:destroy], destroy_path: admin_site_customization_delete_heading_content_block_path(content_block) ) %> diff --git a/app/views/admin/site_customization/documents/index.html.erb b/app/views/admin/site_customization/documents/index.html.erb index c92462cb9..491d9e069 100644 --- a/app/views/admin/site_customization/documents/index.html.erb +++ b/app/views/admin/site_customization/documents/index.html.erb @@ -27,6 +27,7 @@
<%= render Admin::TableActionsComponent.new( + document, actions: [:destroy], destroy_path: admin_site_customization_document_path(document) ) %> diff --git a/app/views/admin/site_customization/pages/index.html.erb b/app/views/admin/site_customization/pages/index.html.erb index 08a7956f8..8be93c234 100644 --- a/app/views/admin/site_customization/pages/index.html.erb +++ b/app/views/admin/site_customization/pages/index.html.erb @@ -29,15 +29,15 @@ <%= t("admin.site_customization.pages.page.status_#{page.status}") %> <%= render Admin::TableActionsComponent.new(page) do |actions| %> - <%= actions.link_to t("admin.site_customization.pages.page.see_cards"), - admin_site_customization_page_widget_cards_path(page), - class: "cards-link" %> + <%= actions.action(:cards, + text: t("admin.site_customization.pages.page.see_cards"), + path: admin_site_customization_page_widget_cards_path(page)) %> <% if page.status == "published" %> - <%= actions.link_to t("admin.site_customization.pages.index.see_page"), - page.url, - target: "_blank", - class: "show-link" %> + <%= actions.action(:show, + text: t("admin.site_customization.pages.index.see_page"), + path: page.url, + options: { target: "_blank" }) %> <% end %> <% end %> diff --git a/app/views/admin/system_emails/index.html.erb b/app/views/admin/system_emails/index.html.erb index bcbca17c2..beddb8f7d 100644 --- a/app/views/admin/system_emails/index.html.erb +++ b/app/views/admin/system_emails/index.html.erb @@ -18,21 +18,21 @@ <%= t("admin.system_emails.#{system_email_title}.description") %> - <%= render Admin::TableActionsComponent.new(actions: []) do |actions| %> + <%= render Admin::TableActionsComponent.new(system_email_title, actions: []) do |actions| %> <% if system_email_actions.include?("view") %> - <%= actions.link_to t("admin.shared.view"), - admin_system_email_view_path(system_email_title), - class: "show-link" %> + <%= actions.action(:show, + text: t("admin.shared.view"), + path: admin_system_email_view_path(system_email_title)) %> <% end %> <% if system_email_actions.include?("preview_pending") %> - <%= actions.link_to t("admin.system_emails.preview_pending.action"), - admin_system_email_preview_pending_path(system_email_title), - class: "preview-pending-link" %> - <%= actions.link_to t("admin.system_emails.preview_pending.send_pending"), - admin_system_email_send_pending_path(system_email_title), - class: "send-pending-link", - method: :put %> + <%= actions.action(:preview_pending, + text: t("admin.system_emails.preview_pending.action"), + path: admin_system_email_preview_pending_path(system_email_title)) %> + <%= actions.action(:send_pending, + text: t("admin.system_emails.preview_pending.send_pending"), + path: admin_system_email_send_pending_path(system_email_title), + method: :put) %> <% end %> <% if system_email_actions.include?("edit_info") %> diff --git a/app/views/admin/valuators/_valuator_row.html.erb b/app/views/admin/valuators/_valuator_row.html.erb index 47ff21947..04c53bb28 100644 --- a/app/views/admin/valuators/_valuator_row.html.erb +++ b/app/views/admin/valuators/_valuator_row.html.erb @@ -20,9 +20,7 @@ <%= render Admin::TableActionsComponent.new(valuator) do |actions| %> - <%= actions.link_to t("admin.shared.view"), - admin_valuator_path(valuator), - class: "show-link" %> + <%= actions.action(:show, text: t("admin.shared.view")) %> <% end %> diff --git a/spec/components/admin/action_component_spec.rb b/spec/components/admin/action_component_spec.rb new file mode 100644 index 000000000..901571f73 --- /dev/null +++ b/spec/components/admin/action_component_spec.rb @@ -0,0 +1,9 @@ +require "rails_helper" + +describe Admin::ActionComponent do + it "includes an HTML class for the action" do + render_inline Admin::ActionComponent.new(:edit, double, path: "/") + + expect(page).to have_css "a.edit-link" + end +end diff --git a/spec/components/admin/organizations/table_actions_component_spec.rb b/spec/components/admin/organizations/table_actions_component_spec.rb index 7f2204b52..c4d807748 100644 --- a/spec/components/admin/organizations/table_actions_component_spec.rb +++ b/spec/components/admin/organizations/table_actions_component_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Admin::Organizations::TableActionsComponent do +describe Admin::Organizations::TableActionsComponent, controller: Admin::OrganizationsController do let(:organization) { create(:organization) } let(:component) { Admin::Organizations::TableActionsComponent.new(organization) } diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index a859c3fe2..89d20a7d6 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -37,7 +37,7 @@ describe Admin::TableActionsComponent, controller: Admin::BaseController do end it "allows custom URLs" do - render_inline Admin::TableActionsComponent.new(edit_path: "/myedit", destroy_path: "/mydestroy") + render_inline Admin::TableActionsComponent.new(nil, edit_path: "/myedit", destroy_path: "/mydestroy") expect(page).to have_link "Edit", href: "/myedit" expect(page).to have_link "Delete", href: "/mydestroy"