From 373e4878f799d3cbb992cb330d8530bbe02edcc0 Mon Sep 17 00:00:00 2001 From: Jasper Mayone Date: Thu, 12 Nov 2026 15:32:15 -0500 Subject: [PATCH 1/2] fix: show the sidebar section as a middle crumb in the admin top bar --- app/helpers/admin_nav_helper.rb | 11 +++++++++++ app/views/layouts/admin.html.erb | 4 ++++ spec/requests/admin_nav_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/app/helpers/admin_nav_helper.rb b/app/helpers/admin_nav_helper.rb index 89d5296..a6c2f49 100644 --- a/app/helpers/admin_nav_helper.rb +++ b/app/helpers/admin_nav_helper.rb @@ -83,6 +83,17 @@ def admin_nav_groups(user = current_user) def admin_nav_link_active?(link) = link.active?(controller_path, request.path) + # The middle crumb of the top bar: the sidebar link of the section this page + # is under, so a detail page leads back to its list. Nil on the section's + # own page and on the home page, where the crumb would repeat the title or + # the first crumb. + def admin_section_crumb + link = admin_nav_groups.flat_map(&:links).find { |entry| admin_nav_link_active?(entry) } + return if link.nil? || link.path == request.path || link.path == admin_home_path + + link + end + # The identity area entry for the top bar and the home page, as # [label, path, icon], or nil. def identity_home_link(user = current_user) diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 790fd85..45c66bc 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -25,6 +25,10 @@
<%= link_to (controller_path.start_with?("identity/") ? "Identity" : "Admin"), admin_home_path, class: "link-quiet" %> + <% if (section = admin_section_crumb) %> + / + <%= link_to section.label, section.path, class: "link-quiet" %> + <% end %> <% if content_for?(:title) %> / <%= content_for(:title) %> diff --git a/spec/requests/admin_nav_spec.rb b/spec/requests/admin_nav_spec.rb index 5eec19d..0e3b8a0 100644 --- a/spec/requests/admin_nav_spec.rb +++ b/spec/requests/admin_nav_spec.rb @@ -89,6 +89,27 @@ def current_link = Nokogiri::HTML(response.body).at_css('aside[aria-label="Admin expect(response.body).not_to include(identity_verifications_path, identity_governance_path) end + def crumbs = Nokogiri::HTML(response.body).css(".admin-topbar-crumb a, .admin-topbar-crumb strong").map { |node| node.text.strip } + + it "puts the section in the top bar crumbs of a page under it" do + sign_in_via_magic_link(create(:user, :admin, :verified)) + application = Doorkeeper::Application.create!(name: "Quilt Staging", redirect_uri: "https://quilt.example.com/cb", scopes: "profile") + + get admin_oauth_application_path(application) + + expect(crumbs).to eq(["Admin", "OAuth apps", "Quilt Staging"]) + expect(Nokogiri::HTML(response.body).at_css(".admin-topbar-crumb a[href='#{admin_oauth_applications_path}']")).to be_present + end + + it "leaves the section out of the crumbs on the section's own page" do + sign_in_via_magic_link(create(:user, :admin, :verified)) + + get admin_oauth_applications_path + + expect(crumbs).to eq(["Admin", "OAuth apps"]) + expect(Nokogiri::HTML(response.body).at_css(".admin-topbar-crumb a[href='#{admin_oauth_applications_path}']")).to be_nil + end + it "highlights the group link for a page under it" do sign_in_via_magic_link(create(:user, :identity_team, :verified)) From 4e95e6c0c3f568e09c3c39677ff25ac2f0f456c1 Mon Sep 17 00:00:00 2001 From: Jasper Mayone Date: Thu, 12 Nov 2026 15:33:58 -0500 Subject: [PATCH 2/2] fix: keep the section crumb on a failed form and build the admin nav once per request --- app/helpers/admin_nav_helper.rb | 12 ++++++++++-- spec/requests/admin_nav_spec.rb | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin_nav_helper.rb b/app/helpers/admin_nav_helper.rb index a6c2f49..e4f5895 100644 --- a/app/helpers/admin_nav_helper.rb +++ b/app/helpers/admin_nav_helper.rb @@ -21,6 +21,12 @@ def active?(controller_path, request_path) # The groups the user can see, each with at least one link. def admin_nav_groups(user = current_user) + # The sidebar, the command bar and the crumb all read the groups, so build + # them once per request and user. + (@admin_nav_groups ||= {})[user&.id] ||= build_admin_nav_groups(user) + end + + def build_admin_nav_groups(user) # An impersonating admin acts as the member, and the identity area # refuses impersonation, so the links would only refuse. return [] if user.nil? || impersonating? @@ -86,10 +92,12 @@ def admin_nav_link_active?(link) = link.active?(controller_path, request.path) # The middle crumb of the top bar: the sidebar link of the section this page # is under, so a detail page leads back to its list. Nil on the section's # own page and on the home page, where the crumb would repeat the title or - # the first crumb. + # the first crumb. A form that fails re-renders at the list URL by POST, so + # only a GET of the list URL counts as the section's own page. def admin_section_crumb link = admin_nav_groups.flat_map(&:links).find { |entry| admin_nav_link_active?(entry) } - return if link.nil? || link.path == request.path || link.path == admin_home_path + return if link.nil? || link.path == admin_home_path + return if request.get? && link.path == request.path link end diff --git a/spec/requests/admin_nav_spec.rb b/spec/requests/admin_nav_spec.rb index 0e3b8a0..3d7a6ed 100644 --- a/spec/requests/admin_nav_spec.rb +++ b/spec/requests/admin_nav_spec.rb @@ -110,6 +110,24 @@ def crumbs = Nokogiri::HTML(response.body).css(".admin-topbar-crumb a, .admin-to expect(Nokogiri::HTML(response.body).at_css(".admin-topbar-crumb a[href='#{admin_oauth_applications_path}']")).to be_nil end + it "keeps the section crumb when a failed form re-renders at the list URL" do + sign_in_via_magic_link(create(:user, :admin, :verified)) + + post admin_users_path, params: { user: { first_name: "", email: "" } } + + expect(response).to have_http_status(:unprocessable_content) + expect(crumbs).to include("Users") + end + + it "leaves out a section crumb that would repeat the home crumb" do + sign_in_via_magic_link(create(:user, :verified, identity_team: true)) + + get identity_verification_path(create(:verification)) + + expect(crumbs.first).to eq("Identity") + expect(crumbs).not_to include("Verification") + end + it "highlights the group link for a page under it" do sign_in_via_magic_link(create(:user, :identity_team, :verified))