From 6882b7a1fea6c22e4c851dd446799f008602c66b Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Fri, 22 Nov 2024 19:12:13 -0500 Subject: [PATCH] fix: collapsed=true (#5259) --- .../src/DocsDefinitionResolver.ts | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts b/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts index 2eaae53ba25..b746fb5f25c 100644 --- a/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts +++ b/packages/cli/docs-resolver/src/DocsDefinitionResolver.ts @@ -488,37 +488,38 @@ export class DocsDefinitionResolver { const children = await Promise.all(items.map((item) => this.toNavigationChild(id, item, parentSlug))); - const sidebarRootChildren: FernNavigation.V1.SidebarRootChild[] = []; + const grouped: FernNavigation.V1.SidebarRootChild[] = []; children.forEach((child) => { - switch (child.type) { - case "apiReference": - case "section": - sidebarRootChildren.push(child); - return; - case "changelog": - case "link": - case "page": { - let last = sidebarRootChildren[sidebarRootChildren.length - 1]; - if (last?.type !== "sidebarGroup") { - last = { - id: this.#idgen.get(`${id}/group`), - type: "sidebarGroup", - children: [] - }; - sidebarRootChildren.push(last); - } - last.children.push(child); - return; - } - default: - assertNever(child); + if (child.type === "apiReference") { + grouped.push(child); + return; + } + + if (child.type === "section" && !child.collapsed) { + grouped.push(child); + return; } + + const lastChild = grouped.length > 0 ? grouped[grouped.length - 1] : undefined; + let sidebarGroup: FernNavigation.V1.SidebarGroupNode; + if (lastChild?.type === "sidebarGroup") { + sidebarGroup = lastChild; + } else { + sidebarGroup = { + id: this.#idgen.get(`${id}/group`), + type: "sidebarGroup", + children: [] + }; + grouped.push(sidebarGroup); + } + + sidebarGroup.children.push(child); }); return { type: "sidebarRoot", id, - children: sidebarRootChildren + children: grouped }; }