Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(ui): use stored concept tree for pages parented to repo root (#1081) (#1085)

Akshat malik1dff06c598ca
diff --git a/packages/ui/__tests__/docs/doc-nav.test.ts b/packages/ui/__tests__/docs/doc-nav.test.ts
index dafe49133..ba8b5a865 100644
--- a/packages/ui/__tests__/docs/doc-nav.test.ts
+++ b/packages/ui/__tests__/docs/doc-nav.test.ts
@@ -123,9 +123,9 @@ describe("computeDocNav", () => {
expect(nav.breadcrumbs[0]?.pageId).toBe(mod.id);
});
- it("keeps the directory trail for a page hanging off the repo root", () => {
- // The tree places files no module claimed directly under the overview. A
- // lone basename crumb would say less than the path the page still carries.
+ it("uses the stored tree for pages parented to the repo root", () => {
+ // Pages parented to the repo root use the stored tree (omitting the root crumb,
+ // which the caller prepends).
const loose = makePage({
id: "file_page:docs/design/contrast_check.py",
title: "contrast_check.py",
@@ -133,11 +133,7 @@ describe("computeDocNav", () => {
parent_page_id: ROOT.id,
});
const nav = computeDocNav(loose, [ROOT, loose]);
- expect(nav.breadcrumbs.map((b) => b.label)).toEqual([
- "docs",
- "design",
- "contrast_check.py",
- ]);
+ expect(nav.breadcrumbs.map((b) => b.label)).toEqual(["contrast_check.py"]);
});
it("labels ancestors with their page type so callers need not guess", () => {
@@ -173,4 +169,49 @@ describe("computeDocNav", () => {
});
expect(computeDocNav(overview, [overview]).breadcrumbs).toEqual([{ label: "Overview" }]);
});
+
+ it("shows prev/next sibling links for root-level pages using display_order", () => {
+ const tour = makePage({
+ id: "onboarding:tour",
+ page_type: "onboarding",
+ title: "Guided Tour",
+ target_path: "docs/guided_tour.md",
+ parent_page_id: ROOT.id,
+ display_order: 1,
+ });
+ const map = makePage({
+ id: "onboarding:map",
+ page_type: "onboarding",
+ title: "Codebase Map",
+ target_path: "docs/codebase_map.md",
+ parent_page_id: ROOT.id,
+ display_order: 2,
+ });
+ const nav = computeDocNav(tour, [ROOT, tour, map]);
+ expect(nav.prev).toBeUndefined();
+ expect(nav.next?.pageId).toBe(map.id);
+ expect(nav.next?.title).toBe("Codebase Map");
+ });
+
+ it("provides prev/next navigation between root-level layer pages", () => {
+ const layer1 = makePage({
+ id: "layer_page:layer:ui",
+ page_type: "layer_page",
+ title: "Layer: UI",
+ target_path: "layer:ui",
+ parent_page_id: ROOT.id,
+ display_order: 1,
+ });
+ const layer2 = makePage({
+ id: "layer_page:layer:core",
+ page_type: "layer_page",
+ title: "Layer: Core",
+ target_path: "layer:core",
+ parent_page_id: ROOT.id,
+ display_order: 2,
+ });
+ const nav = computeDocNav(layer1, [ROOT, layer1, layer2]);
+ expect(nav.next?.pageId).toBe(layer2.id);
+ expect(nav.next?.title).toBe("Layer: Core");
+ });
});
diff --git a/packages/ui/src/docs/doc-nav.ts b/packages/ui/src/docs/doc-nav.ts
index c173830e9..2c5ec0659 100644
--- a/packages/ui/src/docs/doc-nav.ts
+++ b/packages/ui/src/docs/doc-nav.ts
@@ -79,10 +79,10 @@ export function computeDocNav(page: DocPage, pages: DocPage[]): DocNavInfo {
const byId = new Map(pages.map((p) => [p.id, p]));
const chain = page.parent_page_id ? ancestors(page, byId) : [];
- // Only when there is a documented ancestor to show. A page hanging directly
- // off the repo root has none, and a lone basename crumb would say less than
- // the directory trail the path still carries, so those keep the path split.
- if (chain.length > 0) {
+ // Use the stored tree when page.parent_page_id exists and is in the store.
+ // Root children have an empty ancestor chain (root crumb omitted), but still
+ // rely on parent_page_id for display_order sibling sorting and clean labels.
+ if (page.parent_page_id && byId.has(page.parent_page_id)) {
const breadcrumbs: DocNavSegment[] = [
...chain.map((a) => ({
label: crumbLabel(a),