Skip to content

Commit 883ffb8

Browse files
author
Sarah Bawabe
committed
adjust version dropdown to render for versioned products
1 parent c3dd478 commit 883ffb8

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

packages/fern-docs/bundle/src/components/header/VersionDropdown.tsx

+27-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FernNavigation } from "@fern-api/fdr-sdk";
55
import { DocsLoader } from "@/server/docs-loader";
66
import { withVersionSwitcherInfo } from "@/server/withVersionSwitcherInfo";
77

8+
import { isProductNode } from "../../../../../fdr-sdk/src/navigation/versions/latest/isProductNode";
89
import { FaIconServer } from "../fa-icon-server";
910
import {
1011
VersionDropdownClient,
@@ -15,6 +16,12 @@ export declare namespace VersionDropdown {
1516
export interface Props {}
1617
}
1718

19+
/**
20+
* The version dropdown is used to switch between versions at a root level or at a product level.
21+
*
22+
* The version dropdown is used at a root level if the root is versioned.
23+
* The version dropdown is used at a product level if the root has a productgroup and the current product is versioned.
24+
*/
1825
export async function VersionDropdown({
1926
loader,
2027
currentNode,
@@ -27,30 +34,47 @@ export async function VersionDropdown({
2734
parents: FernNavigation.NavigationNodeParent[];
2835
}) {
2936
const root = await loader.getRoot();
30-
if (root.child.type !== "versioned") {
37+
38+
// If the root is not versioned or a productgroup, don't render the version dropdown
39+
if (root.child.type !== "versioned" && root.child.type !== "productgroup") {
3140
return null;
3241
}
3342

34-
const versions = root.child.children;
43+
let versions: FernNavigation.VersionNode[] = [];
44+
45+
// Handle case where root is a productgroup and the current product is versioned OR the root is versioned
46+
if (root.child.type === "productgroup") {
47+
const currentProduct = parents.find(isProductNode);
48+
49+
// If the current product is not versioned, don't render the version dropdown
50+
if (currentProduct?.child.type !== "versioned") {
51+
return null;
52+
}
53+
versions = currentProduct.child.children;
54+
} else if (root.child.type === "versioned") {
55+
versions = root.child.children;
56+
}
3557

3658
if (versions.length <= 1) {
3759
return null;
3860
}
3961

4062
const withInfo = withVersionSwitcherInfo({
4163
node: currentNode,
42-
parents: parents,
64+
parents,
4365
versions,
4466
slugMap,
4567
});
4668

4769
const versionOptions = versions.map((version): VersionDropdownItem => {
4870
const versionInfo = withInfo.find((info) => info.id === version.versionId);
71+
4972
const slug =
5073
versionInfo?.pointsTo ??
5174
versionInfo?.landingPage ??
5275
versionInfo?.slug ??
5376
version.slug;
77+
5478
return {
5579
versionId: version.versionId,
5680
title: version.title,

0 commit comments

Comments
 (0)