diff --git a/app/components/admin/table_actions_component.html.erb b/app/components/admin/table_actions_component.html.erb index dac471bc8..dbb3a93df 100644 --- a/app/components/admin/table_actions_component.html.erb +++ b/app/components/admin/table_actions_component.html.erb @@ -1,12 +1,10 @@ <% if actions.include?(:edit) %> - <%= link_to edit_text, - admin_polymorphic_path(record, action: :edit), - class: "button hollow" %> + <%= link_to edit_text, edit_path, class: "button hollow" %> <% end %> <% if actions.include?(:destroy) %> <%= link_to destroy_text, - admin_polymorphic_path(record), + destroy_path, method: :delete, class: "button hollow alert", data: { confirm: t("admin.actions.confirm") } %> diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb index b016cadc1..c2e078dee 100644 --- a/app/components/admin/table_actions_component.rb +++ b/app/components/admin/table_actions_component.rb @@ -1,7 +1,7 @@ class Admin::TableActionsComponent < ApplicationComponent attr_reader :record, :options - def initialize(record, **options) + def initialize(record = nil, **options) @record = record @options = options end @@ -16,7 +16,15 @@ class Admin::TableActionsComponent < ApplicationComponent options[:edit_text] || t("admin.actions.edit") end + def edit_path + options[:edit_path] || admin_polymorphic_path(record, action: :edit) + end + def destroy_text options[:destroy_text] || t("admin.actions.delete") end + + def destroy_path + options[:destroy_path] || admin_polymorphic_path(record) + end end diff --git a/app/views/admin/dashboard/actions/_default_actions.html.erb b/app/views/admin/dashboard/actions/_default_actions.html.erb index ea102bda5..05bff653e 100644 --- a/app/views/admin/dashboard/actions/_default_actions.html.erb +++ b/app/views/admin/dashboard/actions/_default_actions.html.erb @@ -5,9 +5,10 @@ <%= t("admin.dashboard.actions.index.active") %>   - <%= link_to t("admin.dashboard.actions.index.edit"), - admin_settings_path(anchor: "tab-proposals"), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: admin_settings_path(anchor: "tab-proposals"), + ) %> <% end %> diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index 3b1e2b7da..a9b76dcc1 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -28,8 +28,11 @@ <%= t("admin.officials.level_#{official.official_level}") %> - <%= link_to t("admin.officials.search.edit_official"), - edit_admin_official_path(official), class: "button hollow expanded" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: edit_admin_official_path(official), + edit_text: t("admin.officials.search.edit_official") + ) %> <% end %> diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb index 324c3f7fd..9aaf8c847 100644 --- a/app/views/admin/officials/search.html.erb +++ b/app/views/admin/officials/search.html.erb @@ -32,15 +32,11 @@ <%= t("admin.officials.level_#{user.official_level}") %> - <% if user.official? %> - <%= link_to t("admin.officials.search.edit_official"), - edit_admin_official_path(user), - class: "button hollow expanded" %> - <% else %> - <%= link_to t("admin.officials.search.make_official"), - edit_admin_official_path(user), - class: "button expanded" %> - <% end %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_path: edit_admin_official_path(user), + edit_text: user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official") + ) %> <% end %> diff --git a/app/views/admin/poll/questions/answers/documents.html.erb b/app/views/admin/poll/questions/answers/documents.html.erb index 6bef094c6..3f6ff5df7 100644 --- a/app/views/admin/poll/questions/answers/documents.html.erb +++ b/app/views/admin/poll/questions/answers/documents.html.erb @@ -42,11 +42,10 @@ rel: "nofollow", class: "button hollow" %> - <%= link_to t("admin.shared.delete"), - document_path(document), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render Admin::TableActionsComponent.new(document, + actions: [:destroy], + destroy_path: document_path(document) + ) %> <% 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 b19db5e79..ec8cfc3bd 100644 --- a/app/views/admin/poll/shifts/_search_officers_results.html.erb +++ b/app/views/admin/poll/shifts/_search_officers_results.html.erb @@ -25,9 +25,11 @@ <%= user.email %> - <%= link_to t("admin.poll_shifts.new.edit_shifts"), - new_admin_booth_shift_path(officer_id: user.poll_officer.id), - class: "button hollow" %> + <%= render Admin::TableActionsComponent.new( + actions: [:edit], + edit_text: t("admin.poll_shifts.new.edit_shifts"), + edit_path: new_admin_booth_shift_path(officer_id: user.poll_officer.id) + ) %> <% end %> diff --git a/app/views/admin/site_customization/cards/_card.html.erb b/app/views/admin/site_customization/cards/_card.html.erb index 44a49f989..578b3c01a 100644 --- a/app/views/admin/site_customization/cards/_card.html.erb +++ b/app/views/admin/site_customization/cards/_card.html.erb @@ -17,14 +17,8 @@ <% end %> - <%= link_to t("admin.actions.edit"), - edit_admin_widget_card_path(card, page_id: params[:page_id]), - class: "button hollow" %> - - <%= link_to t("admin.actions.delete"), - admin_widget_card_path(card, page_id: params[:page_id]), - method: :delete, - data: { confirm: t("admin.actions.confirm") }, - class: "button hollow alert" %> + <%= render Admin::TableActionsComponent.new(card, + edit_path: edit_admin_widget_card_path(card, page_id: params[:page_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 33bdcf756..ef069e448 100644 --- a/app/views/admin/site_customization/content_blocks/index.html.erb +++ b/app/views/admin/site_customization/content_blocks/index.html.erb @@ -46,9 +46,11 @@ <%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %> <%= raw content_block.body %> - <%= link_to t("admin.site_customization.content_blocks.index.delete"), - admin_site_customization_delete_heading_content_block_path(content_block.id), - method: :delete, class: "button hollow alert" %> + <%= render Admin::TableActionsComponent.new( + actions: [:destroy], + destroy_text: t("admin.site_customization.content_blocks.index.delete"), + destroy_path: admin_site_customization_delete_heading_content_block_path(content_block) + ) %> <% end %> diff --git a/app/views/admin/site_customization/documents/index.html.erb b/app/views/admin/site_customization/documents/index.html.erb index a4bc3de65..c92462cb9 100644 --- a/app/views/admin/site_customization/documents/index.html.erb +++ b/app/views/admin/site_customization/documents/index.html.erb @@ -26,11 +26,10 @@ <%= link_to document.title, document.attachment.url, target: :blank %>
- <%= link_to t("admin.shared.delete"), - admin_site_customization_document_path(document), - method: :delete, - class: "button hollow alert", - data: { confirm: t("admin.actions.confirm") } %> + <%= render Admin::TableActionsComponent.new( + actions: [:destroy], + destroy_path: admin_site_customization_document_path(document) + ) %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 6cbf33afe..cbe7f7a15 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -359,7 +359,6 @@ en: index: description: "When users create proposals they can access a dashboard of their proposal, where you can propose resources and recommendations to get support for their idea." create: Create resource or action - edit: Edit active: 'Yes' inactive: 'No' title: Resources and actions @@ -1289,7 +1288,6 @@ en: author: Author content: Content created_at: Created at - delete: Delete color_help: Hexadecimal format show_results_and_stats: "Show results and stats" results_and_stats_reminder: "Marking these checkboxes the results and/or stats will be publicly available and every user will see them." diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 575518f56..d6d3d1563 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -359,7 +359,6 @@ es: index: description: "Cuando los usuarios crean propuestas pueden acceder a un panel de progreso de su propuesta, donde se le puede proponer recursos y recomendaciones para conseguir apoyos a su idea." create: Crear recurso o acción - edit: Editar active: 'Si' inactive: 'No' title: Recursos y acciones @@ -1288,7 +1287,6 @@ es: author: Autor content: Contenido created_at: Fecha de creación - delete: Eliminar color_help: Formato hexadecimal show_results_and_stats: "Mostrar resultados y estadísticas" results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas serán públicos y podrán verlos todos los usuarios." diff --git a/spec/components/admin/table_actions_component_spec.rb b/spec/components/admin/table_actions_component_spec.rb index b6d7c43cf..490b858ba 100644 --- a/spec/components/admin/table_actions_component_spec.rb +++ b/spec/components/admin/table_actions_component_spec.rb @@ -35,4 +35,11 @@ describe Admin::TableActionsComponent, type: :component do expect(page).not_to have_link "Delete" expect(page).not_to have_link "Edit" end + + it "allows custom URLs" do + render_inline Admin::TableActionsComponent.new(edit_path: "/myedit", destroy_path: "/mydestroy") + + expect(page).to have_link "Edit", href: "/myedit" + expect(page).to have_link "Delete", href: "/mydestroy" + end end