@@ -5,6 +5,7 @@ import { FernNavigation } from "@fern-api/fdr-sdk";
5
5
import { DocsLoader } from "@/server/docs-loader" ;
6
6
import { withVersionSwitcherInfo } from "@/server/withVersionSwitcherInfo" ;
7
7
8
+ import { isProductNode } from "../../../../../fdr-sdk/src/navigation/versions/latest/isProductNode" ;
8
9
import { FaIconServer } from "../fa-icon-server" ;
9
10
import {
10
11
VersionDropdownClient ,
@@ -15,6 +16,12 @@ export declare namespace VersionDropdown {
15
16
export interface Props { }
16
17
}
17
18
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
+ */
18
25
export async function VersionDropdown ( {
19
26
loader,
20
27
currentNode,
@@ -27,30 +34,47 @@ export async function VersionDropdown({
27
34
parents : FernNavigation . NavigationNodeParent [ ] ;
28
35
} ) {
29
36
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" ) {
31
40
return null ;
32
41
}
33
42
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
+ }
35
57
36
58
if ( versions . length <= 1 ) {
37
59
return null ;
38
60
}
39
61
40
62
const withInfo = withVersionSwitcherInfo ( {
41
63
node : currentNode ,
42
- parents : parents ,
64
+ parents,
43
65
versions,
44
66
slugMap,
45
67
} ) ;
46
68
47
69
const versionOptions = versions . map ( ( version ) : VersionDropdownItem => {
48
70
const versionInfo = withInfo . find ( ( info ) => info . id === version . versionId ) ;
71
+
49
72
const slug =
50
73
versionInfo ?. pointsTo ??
51
74
versionInfo ?. landingPage ??
52
75
versionInfo ?. slug ??
53
76
version . slug ;
77
+
54
78
return {
55
79
versionId : version . versionId ,
56
80
title : version . title ,
0 commit comments