Allow different texts in links to actions
The texts were different for a few models, so the component needs to be updated.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,15 +21,10 @@
|
||||
<td><%= banner.post_started_at %></td>
|
||||
<td><%= banner.post_ended_at %></td>
|
||||
<td>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= link_to t("admin.banners.index.edit"), edit_admin_banner_path(banner),
|
||||
class: "button hollow expanded" %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= link_to t("admin.banners.index.delete"), admin_banner_path(banner),
|
||||
method: :delete,
|
||||
class: "button hollow alert expanded" %>
|
||||
</div>
|
||||
<%= render Admin::TableActionsComponent.new(banner,
|
||||
edit_text: t("admin.banners.index.edit"),
|
||||
destroy_text: t("admin.banners.index.delete")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<% 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 %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="small-2">
|
||||
<%= 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")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -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 %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
</td>
|
||||
<td>
|
||||
<% 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,
|
||||
|
||||
@@ -30,11 +30,10 @@
|
||||
</td>
|
||||
<td>
|
||||
<% 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,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<th><%= t("admin.poll_shifts.new.officer") %></th>
|
||||
<th><%= t("admin.poll_shifts.new.table_email") %></th>
|
||||
<th><%= Poll::Shift.human_attribute_name(:task) %></th>
|
||||
<th class="small-3"><%= t("admin.poll_shifts.new.shift") %></th>
|
||||
<th><%= t("admin.poll_shifts.new.shift") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -17,10 +17,10 @@
|
||||
<td><%= shift.officer_email %></td>
|
||||
<td><%= t("admin.poll_shifts.#{shift.task}") %></td>
|
||||
<td>
|
||||
<%= 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")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -34,9 +34,10 @@
|
||||
<td><%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_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_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")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -35,20 +35,17 @@
|
||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
||||
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
|
||||
<td>
|
||||
<div class="small-6 column">
|
||||
<% if page.status == "published" %>
|
||||
<%= link_to t("admin.site_customization.pages.index.see_page"),
|
||||
page.url,
|
||||
target: "_blank",
|
||||
class: "button hollow expanded" %>
|
||||
class: "button hollow" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="small-6 column end">
|
||||
<%= link_to t("admin.site_customization.pages.index.delete"),
|
||||
admin_site_customization_page_path(page),
|
||||
method: :delete,
|
||||
class: "button hollow alert expanded" %>
|
||||
</div>
|
||||
|
||||
<%= render Admin::TableActionsComponent.new(page,
|
||||
actions: [:destroy],
|
||||
destroy_text: t("admin.site_customization.pages.index.delete")
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td id="tag_<%= tag.id %>">
|
||||
<%= 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")) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user