Skip to content

Commit

Permalink
Merge pull request #3726 from alphagov/2761-refactor-browsehelper-in-…
Browse files Browse the repository at this point in the history
…preparation-for-ab-test-m

Do not force analytics labels for popular links to be in English and refactor browse helper
  • Loading branch information
unoduetre authored Aug 15, 2024
2 parents 626a481 + b40ea66 commit 052b269
Show file tree
Hide file tree
Showing 70 changed files with 811 additions and 314 deletions.
43 changes: 21 additions & 22 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
module BrowseHelper
ACTION_LINK_DATA = {
benefits: [
{ lang: "browse.check_benefits_and_financial_support", href: "/check-benefits-financial-support" },
],
business: [
{ lang: "browse.hmrc_online_services", href: "/log-in-register-hmrc-online-services" },
{ lang: "browse.self_assessment_tax_returns", href: "/self-assessment-tax-returns" },
{ lang: "browse.pay_employers_paye", href: "/pay-paye-tax" },
],
}.freeze

def display_action_links_for_slug?(slug)
ACTION_LINK_DATA.key?(slug.to_sym)
def display_popular_links_for_slug?(slug)
I18n.exists?(slug.to_s, scope: "browse.popular_links")
end

def action_link_data(slug)
links = ACTION_LINK_DATA[slug.to_sym]
return [] unless links

links.each_with_index do |link, index|
link[:text] = I18n.t(link[:lang])
link[:ga4_text] = I18n.t(link[:lang], locale: :en)
link[:index_link] = index + 1
link[:index_total] = links.length
def popular_links_for_slug(slug)
links = I18n.t(slug.to_s, scope: "browse.popular_links")
count = links.length
links.map.with_index(1) do |link, index|
{
text: link[:title],
href: link[:url],
data_attributes: {
module: "ga4-link-tracker",
ga4_track_links_only: "",
ga4_link: {
event_name: "navigation",
type: "action",
index_link: index,
index_total: count,
text: link[:title],
},
},
}
end
end
end
10 changes: 5 additions & 5 deletions app/views/browse/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
} %>
<% end %>
<% if display_action_links_for_slug?(page.slug) %>
<% if display_popular_links_for_slug?(page.slug) %>
<div class="govuk-width-container">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
Expand All @@ -45,9 +45,9 @@
font_size: "m"
} %>
<ul class="govuk-list govuk-!-margin-bottom-7">
<% action_link_data(page.slug).each do |link| %>
<% popular_links_for_slug(page.slug).each do |link| %>
<li>
<%= render "shared/browse_action_link", locals: link %>
<%= render partial: "shared/browse_action_link", locals: {link:} %>
</li>
<% end %>
</ul>
Expand All @@ -60,7 +60,7 @@
<% total_links = page.second_level_browse_pages.count.to_s %>
<%= render "shared/browse_cards_container" do %>
<%= render "govuk_publishing_components/components/cards", {
heading: display_action_links_for_slug?(page.slug) ? t("browse.topics") : nil,
heading: display_popular_links_for_slug?(page.slug) ? t("browse.topics") : nil,
items: page.second_level_browse_pages.map.with_index do |second_level_browse_page, index|
{
link: {
Expand All @@ -78,6 +78,6 @@
description: second_level_browse_page.description,
}
end,
sub_heading_level: display_action_links_for_slug?(page.slug) ? 3 : 2,
sub_heading_level: display_popular_links_for_slug?(page.slug) ? 3 : 2,
} %>
<% end %>
14 changes: 1 addition & 13 deletions app/views/shared/_browse_action_link.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<%= render "govuk_publishing_components/components/action_link", {
text: locals[:text],
href: locals[:href],
dark_large_icon: true,
margin_bottom: 3,
data_attributes: {
module: "ga4-link-tracker",
ga4_track_links_only: "",
ga4_link: {
event_name: "navigation",
type: "action",
index_link: locals[:index_link],
index_total: locals[:index_total],
text: locals[:ga4_text]
}
}
**link,
} %>
15 changes: 11 additions & 4 deletions config/locales/ar/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
ar:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: جميع الفئات
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/az/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
az:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Bütün kateqoriyalar
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/be/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
be:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Усе катэгорыі
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/bg/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
bg:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Всички категории
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/bn/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
bn:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: সকল শ্রেণিবিভাগ
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/cs/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
cs:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Všechny kategorie
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/cy/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
cy:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Pob categori
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/da/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
da:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Alle kategorier
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/de/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
de:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Alle Kategorien
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/dr/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
dr:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: تمام کتگوری ها
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/el/browse.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
---
el:
browse:
popular_links:
benefits:
- title:
url:
business:
- title:
url:
- title:
url:
- title:
url:
all_categories: Όλες οι κατηγορίες
check_benefits_and_financial_support:
description:
hmrc_online_services:
pay_employers_paye:
popular_tasks:
self_assessment_tax_returns:
title:
topics:
15 changes: 11 additions & 4 deletions config/locales/en/browse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ en:
all_categories: All categories
popular_tasks: Popular tasks
topics: Topics
check_benefits_and_financial_support: Check benefits and financial support you can get
hmrc_online_services: "HMRC online services: sign in or set up an account"
self_assessment_tax_returns: Self Assessment tax returns
pay_employers_paye: "Pay employers' PAYE"
description: Find the government services, forms and accounts you need to use
title: Services and information
popular_links:
benefits:
- title: Check benefits and financial support you can get
url: /check-benefits-financial-support
business:
- title: "HMRC online services: sign in or set up an account"
url: /log-in-register-hmrc-online-services
- title: Self Assessment tax returns
url: /self-assessment-tax-returns
- title: "Pay employers' PAYE"
url: /pay-paye-tax
Loading

0 comments on commit 052b269

Please sign in to comment.