Remove duplication in group switcher component
We can extract a method to reduce the amount of ERB code and remove the duplication in the link texts. We also make the list consistent; now we always use a <strong> tag in the group name, no matter whether there are many groups or only one.
This commit is contained in:
@@ -2,21 +2,10 @@
|
||||
<% if other_groups.one? %>
|
||||
<p>
|
||||
<%= currently_showing_text %>
|
||||
<%= link_to t("admin.budget_headings.group_switcher.the_other_group", group: other_groups.first.name),
|
||||
headings_path(other_groups.first) %>
|
||||
<%= link_to_group(other_groups.first) %>
|
||||
</p>
|
||||
<% else %>
|
||||
<p><%= currently_showing_text %></p>
|
||||
<ul>
|
||||
<% other_groups.each do |other_group| %>
|
||||
<li>
|
||||
<%= link_to sanitize(t(
|
||||
"admin.budget_headings.group_switcher.the_other_group",
|
||||
group: tag.strong(other_group.name)
|
||||
)),
|
||||
headings_path(other_group) %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= link_list(*other_groups.map { |group| link_to_group(group) }) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Admin::BudgetsWizard::Headings::GroupSwitcherComponent < ApplicationComponent
|
||||
attr_reader :group
|
||||
use_helpers :link_list
|
||||
|
||||
def initialize(group)
|
||||
@group = group
|
||||
@@ -26,4 +27,12 @@ class Admin::BudgetsWizard::Headings::GroupSwitcherComponent < ApplicationCompon
|
||||
def currently_showing_text
|
||||
sanitize(t("admin.budget_headings.group_switcher.currently_showing", group: group.name))
|
||||
end
|
||||
|
||||
def link_to_group(group)
|
||||
link_to(link_to_group_text(group), headings_path(group))
|
||||
end
|
||||
|
||||
def link_to_group_text(group)
|
||||
sanitize(t("admin.budget_headings.group_switcher.the_other_group", group: tag.strong(group.name)))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user