Browse Source

Compare partial URLs to highlight navigation items

pull/493/head
Kat 3 years ago
parent
commit
123d16903c
  1. 2
      app/components/primary_navigation_component.html.erb
  2. 12
      app/views/layouts/application.html.erb

2
app/components/primary_navigation_component.html.erb

@ -2,7 +2,7 @@
<div class="govuk-width-container">
<ul class="app-primary-navigation__list">
<% items.each do |item| %>
<% if item.fetch(:current, false) || current_page?(item.fetch(:url)) || current_page?("#{item.fetch(:url)}/details") %>
<% if item.fetch(:current, false) || item.fetch(:comparable_urls).any? { |url| request.fullpath.include?(url) } %>
<li class="app-primary-navigation__item app-primary-navigation__item--current">
<%= govuk_link_to item[:name], item[:url], class: "app-primary-navigation__link", aria: { current: "page" } %>
</li>

12
app/views/layouts/application.html.erb

@ -65,15 +65,15 @@
<% if !current_user.nil? %>
<% if current_user.support? %>
<% items = [
{ name: "Organisations", url: "/organisations" },
{ name: "Users", url: "/users" },
{ name: "Logs", url: case_logs_path },
{ name: "Organisations", url: "/organisations", comparable_urls: ["/details", "/organisations"] },
{ name: "Users", url: "/users", comparable_urls: ["/users", "/account"] },
{ name: "Logs", url: case_logs_path, comparable_urls: ["/logs"] },
] %>
<% else %>
<% items = [
{ name: "Logs", url: case_logs_path },
{ name: "Users", url: users_organisation_path(current_user.organisation) },
{ name: "About your organisation", url: "/organisations/#{current_user.organisation.id}" },
{ name: "Logs", url: case_logs_path, comparable_urls: ["/logs"] },
{ name: "Users", url: users_organisation_path(current_user.organisation), comparable_urls: ["/users", "/account"] },
{ name: "About your organisation", url: "/organisations/#{current_user.organisation.id}", comparable_urls: ["/details"] },
] %>
<% end %>
<%= render PrimaryNavigationComponent.new(items:) %>

Loading…
Cancel
Save