Skip to content

Commit

Permalink
fix: missing tabs (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jul 6, 2024
1 parent 4d1511a commit 5886b0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 7 additions & 3 deletions packages/fdr-sdk/src/converters/db/convertDocsDefinitionToDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ function transformUnversionedNavigationConfigForDb(
untabbed: (config) => {
return {
items: config.items.map(transformNavigationItemForDb),
landingPage: transformPageNavigationItemForDb(config.landingPage),
// landing page's slug should be "" because it's the root
landingPage: transformPageNavigationItemForDb(config.landingPage, ""),
};
},
tabbed: (config) => {
return {
tabs: config.tabs?.map(transformNavigationTabForDb),
tabsV2: config.tabsV2?.map(transformNavigationTabV2ForDb),
landingPage: transformPageNavigationItemForDb(config.landingPage),
landingPage: transformPageNavigationItemForDb(config.landingPage, ""),
};
},
});
Expand Down Expand Up @@ -463,12 +464,15 @@ function transformColorsV3ForDb({

function transformPageNavigationItemForDb(
writeShape: DocsV1Write.PageMetadata,
defaultSlug?: string,
): WithoutQuestionMarks<DocsV1Read.NavigationItem.Page>;
function transformPageNavigationItemForDb(
writeShape: DocsV1Write.PageMetadata | undefined,
defaultSlug?: string,
): WithoutQuestionMarks<DocsV1Read.NavigationItem.Page> | undefined;
function transformPageNavigationItemForDb(
writeShape: DocsV1Write.PageMetadata | undefined,
defaultSlug?: string,
): WithoutQuestionMarks<DocsV1Read.NavigationItem.Page> | undefined {
if (writeShape == null) {
return undefined;
Expand All @@ -478,7 +482,7 @@ function transformPageNavigationItemForDb(
id: writeShape.id,
title: writeShape.title,
icon: writeShape.icon,
urlSlug: writeShape.urlSlugOverride ?? kebabCase(writeShape.title),
urlSlug: writeShape.urlSlugOverride ?? defaultSlug ?? kebabCase(writeShape.title),
fullSlug: writeShape.fullSlug,
hidden: writeShape.hidden ?? false,
};
Expand Down
15 changes: 9 additions & 6 deletions packages/fdr-sdk/src/navigation/utils/findNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export declare namespace Node {
next: NavigationNodeNeighbor | undefined;
prev: NavigationNodeNeighbor | undefined;
collector: NodeCollector;
landingPage: FernNavigation.LandingPageNode | undefined;
}

interface Redirect {
Expand Down Expand Up @@ -56,13 +57,14 @@ export function findNode(root: FernNavigation.RootNode, slug: string[]): Node {

const sidebar = found.parents.find((node): node is FernNavigation.SidebarRootNode => node.type === "sidebarRoot");
const currentVersion = found.parents.find((node): node is FernNavigation.VersionNode => node.type === "version");
const tabbedNode = found.parents.find((node): node is FernNavigation.TabbedNode => node.type === "tabbed");
const unversionedNode = found.parents.find(
(node): node is FernNavigation.UnversionedNode => node.type === "unversioned",
);
const landingPage = (currentVersion ?? unversionedNode)?.landingPage;
if (isPage(found.node)) {
const rootChild = (currentVersion ?? root).child;
const parentsAndNode = [...found.parents, found.node];
const tabs = rootChild.type === "tabbed" ? rootChild.children : [];
const tabbedNodeIndex = parentsAndNode.findIndex(
(node): node is FernNavigation.TabbedNode => node.type === "tabbed",
);
const tabbedNodeIndex = parentsAndNode.findIndex((node) => node === tabbedNode);
const currentTab = tabbedNodeIndex !== -1 ? parentsAndNode[tabbedNodeIndex + 1] : undefined;
return {
type: "found",
Expand All @@ -82,13 +84,14 @@ export function findNode(root: FernNavigation.RootNode, slug: string[]): Node {
}
return node;
}),
tabs,
tabs: tabbedNode?.children ?? [],
currentVersion,
currentTab: currentTab?.type === "tab" || currentTab?.type === "changelog" ? currentTab : undefined,
sidebar,
apiReference:
found.parents.find((node): node is FernNavigation.ApiReferenceNode => node.type === "apiReference") ??
(found.node.type === "apiReference" ? found.node : undefined),
landingPage,
next: found.next,
prev: found.prev,
collector,
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/docs-bundle/src/utils/getDocsPageProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ async function convertDocsToDocsPageProps({
js: docs.definition.config.js,
navbarLinks: docs.definition.config.navbarLinks ?? [],
logoHeight: docs.definition.config.logoHeight,
logoHref: docs.definition.config.logoHref,
logoHref:
docs.definition.config.logoHref ??
(node.landingPage?.slug != null && !node.landingPage.hidden ? `/${node.landingPage.slug}` : undefined),
search: docs.definition.search,
files: docs.definition.filesV2,
resolvedPath,
Expand Down

0 comments on commit 5886b0c

Please sign in to comment.