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:
Javi Martín
2020-06-09 16:51:02 +02:00
parent 10c095d821
commit 738646a565
13 changed files with 73 additions and 56 deletions

View File

@@ -1,11 +1,11 @@
<% if actions.include?(:edit) %> <% if actions.include?(:edit) %>
<%= link_to t("admin.actions.edit"), <%= link_to edit_text,
admin_polymorphic_path(record, action: :edit), admin_polymorphic_path(record, action: :edit),
class: "button hollow" %> class: "button hollow" %>
<% end %> <% end %>
<% if actions.include?(:destroy) %> <% if actions.include?(:destroy) %>
<%= link_to t("admin.actions.delete"), <%= link_to destroy_text,
admin_polymorphic_path(record), admin_polymorphic_path(record),
method: :delete, method: :delete,
class: "button hollow alert", class: "button hollow alert",

View File

@@ -1,8 +1,22 @@
class Admin::TableActionsComponent < ApplicationComponent class Admin::TableActionsComponent < ApplicationComponent
attr_reader :record, :actions attr_reader :record, :options
def initialize(record, actions: [:edit, :destroy]) def initialize(record, **options)
@record = record @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
end end

View File

@@ -21,15 +21,10 @@
<td><%= banner.post_started_at %></td> <td><%= banner.post_started_at %></td>
<td><%= banner.post_ended_at %></td> <td><%= banner.post_ended_at %></td>
<td> <td>
<div class="small-12 medium-6 column"> <%= render Admin::TableActionsComponent.new(banner,
<%= link_to t("admin.banners.index.edit"), edit_admin_banner_path(banner), edit_text: t("admin.banners.index.edit"),
class: "button hollow expanded" %> destroy_text: t("admin.banners.index.delete")
</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>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -25,9 +25,10 @@
</td> </td>
<td class="text-right"> <td class="text-right">
<% unless task.executed_at? %> <% unless task.executed_at? %>
<%= link_to t("admin.dashboard.administrator_tasks.index.solve"), <%= render Admin::TableActionsComponent.new(task,
edit_admin_dashboard_administrator_task_path(task), actions: [:edit],
class: "button hollow" %> edit_text: t("admin.dashboard.administrator_tasks.index.solve")
) %>
<% end %> <% end %>
</td> </td>
</tr> </tr>

View File

@@ -56,10 +56,10 @@
<% end %> <% end %>
</td> </td>
<td class="small-2"> <td class="small-2">
<%= link_to t("admin.milestones.index.delete"), <%= render Admin::TableActionsComponent.new(milestone,
admin_polymorphic_path(milestone), actions: [:destroy],
method: :delete, destroy_text: t("admin.milestones.index.delete")
class: "button hollow alert expanded" %> ) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -11,9 +11,10 @@
new_admin_booth_shift_path(booth), new_admin_booth_shift_path(booth),
class: "button hollow" %> class: "button hollow" %>
<% else %> <% else %>
<%= link_to t("admin.booths.booth.edit"), <%= render Admin::TableActionsComponent.new(booth,
edit_admin_booth_path(booth), actions: [:edit],
class: "button hollow" %> edit_text: t("admin.booths.booth.edit")
) %>
<% end %> <% end %>
</td> </td>
</tr> </tr>

View File

@@ -16,10 +16,10 @@
</td> </td>
<td> <td>
<% if officer.persisted? %> <% if officer.persisted? %>
<%= link_to t("admin.poll_officers.officer.delete"), <%= render Admin::TableActionsComponent.new(officer,
admin_officer_path(officer), actions: [:destroy],
method: :delete, destroy_text: t("admin.poll_officers.officer.delete")
class: "button hollow alert expanded" %> ) %>
<% else %> <% else %>
<%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id }, <%= link_to t("admin.poll_officers.officer.add"), { controller: "admin/poll/officers", action: :create, user_id: officer.user_id },
method: :post, method: :post,

View File

@@ -30,11 +30,10 @@
</td> </td>
<td> <td>
<% if officer.persisted? %> <% if officer.persisted? %>
<%= link_to t("admin.poll_officers.officer.delete"), <%= render Admin::TableActionsComponent.new(officer,
admin_officer_path(officer), actions: [:destroy],
method: :delete, destroy_text: t("admin.poll_officers.officer.delete")
class: "button hollow alert expanded" ) %>
%>
<% else %> <% else %>
<%= link_to t("admin.poll_officers.officer.add"), <%= link_to t("admin.poll_officers.officer.add"),
{ controller: "admin/poll/officers", action: :create, { controller: "admin/poll/officers", action: :create,

View File

@@ -6,7 +6,7 @@
<th><%= t("admin.poll_shifts.new.officer") %></th> <th><%= t("admin.poll_shifts.new.officer") %></th>
<th><%= t("admin.poll_shifts.new.table_email") %></th> <th><%= t("admin.poll_shifts.new.table_email") %></th>
<th><%= Poll::Shift.human_attribute_name(:task) %></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> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -17,10 +17,10 @@
<td><%= shift.officer_email %></td> <td><%= shift.officer_email %></td>
<td><%= t("admin.poll_shifts.#{shift.task}") %></td> <td><%= t("admin.poll_shifts.#{shift.task}") %></td>
<td> <td>
<%= link_to t("admin.poll_shifts.new.remove_shift"), <%= render Admin::TableActionsComponent.new(shift,
admin_booth_shift_path(@booth, shift), actions: [:destroy],
method: :delete, destroy_text: t("admin.poll_shifts.new.remove_shift")
class: "button hollow alert expanded" %> ) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -34,9 +34,10 @@
<td><%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %></td> <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><%= raw content_block.body %></td>
<td> <td>
<%= link_to t("admin.site_customization.content_blocks.index.delete"), <%= render Admin::TableActionsComponent.new(content_block,
admin_site_customization_content_block_path(content_block), actions: [:destroy],
method: :delete, class: "button hollow alert" %> destroy_text: t("admin.site_customization.content_blocks.index.delete")
) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -35,20 +35,17 @@
<td><%= I18n.l page.created_at, format: :short %></td> <td><%= I18n.l page.created_at, format: :short %></td>
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td> <td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
<td> <td>
<div class="small-6 column">
<% if page.status == "published" %> <% if page.status == "published" %>
<%= link_to t("admin.site_customization.pages.index.see_page"), <%= link_to t("admin.site_customization.pages.index.see_page"),
page.url, page.url,
target: "_blank", target: "_blank",
class: "button hollow expanded" %> class: "button hollow" %>
<% end %> <% end %>
</div>
<div class="small-6 column end"> <%= render Admin::TableActionsComponent.new(page,
<%= link_to t("admin.site_customization.pages.index.delete"), actions: [:destroy],
admin_site_customization_page_path(page), destroy_text: t("admin.site_customization.pages.index.delete")
method: :delete, ) %>
class: "button hollow alert expanded" %>
</div>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -30,7 +30,7 @@
<% end %> <% end %>
</td> </td>
<td id="tag_<%= tag.id %>"> <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> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -26,4 +26,13 @@ describe Admin::TableActionsComponent, type: :component do
expect(page).not_to have_link "Edit" expect(page).not_to have_link "Edit"
end end
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 end