Allow custom URLs in links to actions
There were a couple of cases where these links didn't point to the default actions.
This commit is contained in:
@@ -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") } %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
<td class="text-center"><%= t("admin.dashboard.actions.index.active") %></td>
|
||||
<td colspan="4"> </td>
|
||||
<td class="text-right">
|
||||
<%= 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"),
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -28,8 +28,11 @@
|
||||
<%= t("admin.officials.level_#{official.official_level}") %>
|
||||
</td>
|
||||
<td>
|
||||
<%= 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")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -32,15 +32,11 @@
|
||||
<%= t("admin.officials.level_#{user.official_level}") %>
|
||||
</td>
|
||||
<td>
|
||||
<% 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")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -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)
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -25,9 +25,11 @@
|
||||
<%= user.email %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= 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)
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -17,14 +17,8 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= 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])
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -46,9 +46,11 @@
|
||||
<td><%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %></td>
|
||||
<td><%= raw content_block.body %></td>
|
||||
<td>
|
||||
<%= 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)
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -26,11 +26,10 @@
|
||||
<td><%= link_to document.title, document.attachment.url, target: :blank %></td>
|
||||
<td>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= 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)
|
||||
) %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user