Skip to content

Commit cf965e0

Browse files
authored
Convert to new site tree (github#19450)
1 parent 8c8274f commit cf965e0

File tree

8 files changed

+35
-142
lines changed

8 files changed

+35
-142
lines changed

components/SidebarNav.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ import Link from 'next/link'
33
import { LinkExternalIcon, MarkGithubIcon } from '@primer/octicons-react'
44
import { useTranslation } from './hooks/useTranslation'
55
import { useMainContext } from './context/MainContext'
6-
import { ProductSiteTree } from './product/ProductSiteTree'
76
import { ProductSiteTreeNew } from './product/ProductSiteTreeNew'
87
import { AllProductsLink } from './product/AllProductsLink'
98
import { useVersion } from './hooks/useVersion'
10-
import { useFeatureFlags } from './hooks/useFeatureFlags'
119

1210
type Props = {}
1311
export const SidebarNav = (props: Props) => {
1412
const router = useRouter()
1513
const { currentVersion } = useVersion()
1614
const { error, relativePath } = useMainContext()
17-
const { FEATURE_NEW_SITETREE } = useFeatureFlags()
1815
const { t } = useTranslation('header')
1916

2017
return (
@@ -44,7 +41,7 @@ export const SidebarNav = (props: Props) => {
4441
</ul>
4542
) : (
4643
<ul className="sidebar-products">
47-
{FEATURE_NEW_SITETREE ? <ProductSiteTreeNew /> : <ProductSiteTree />}
44+
<ProductSiteTreeNew />
4845
</ul>
4946
)}
5047
</nav>

components/context/MainContext.tsx

+6-37
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,17 @@ type VersionItem = {
2525
versionTitle: string
2626
}
2727

28-
type Article = {
29-
href: string
30-
title: string
31-
shortTitle?: string
32-
hidden?: boolean
33-
}
34-
type ProductSiteTree = {
35-
title: string
36-
href: string
37-
external?: boolean
38-
categories?: Record<
39-
string,
40-
Article & {
41-
standalone?: boolean
42-
articles?: Record<string, Article>
43-
maptopics?: Record<string, Article & { articles?: Record<string, Article> }>
44-
}
45-
>
46-
}
47-
48-
export type SiteTreePage = {
28+
export type CurrentProductTree = {
4929
page: {
5030
hidden?: boolean
5131
documentType: 'article' | 'mapTopic'
5232
title: string
33+
shortTitle: string
5334
}
5435
renderedShortTitle?: string
5536
renderedFullTitle: string
5637
href: string
57-
childPages: Array<SiteTreePage>
38+
childPages: Array<CurrentProductTree>
5839
}
5940

6041
type DataT = {
@@ -100,8 +81,7 @@ export type MainContextT = {
10081
currentLanguage: string
10182
languages: Record<string, LanguageItem>
10283
allVersions: Record<string, VersionItem>
103-
productSiteTree?: ProductSiteTree
104-
productSiteTreeNew?: SiteTreePage
84+
currentProductTree?: CurrentProductTree
10585
featureFlags: FeatureFlags
10686
page: {
10787
languageVariants: Array<{ name: string; code: string; hreflang: string; href: string }>
@@ -179,19 +159,8 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
179159
),
180160
allVersions: req.context.allVersions,
181161
// this gets rid of some `undefined` values, which is necessary so next.js can serialize the data
182-
productSiteTree: !req.context.FEATURE_NEW_SITETREE
183-
? JSON.parse(
184-
JSON.stringify(
185-
req.context.siteTree[req.context.currentLanguage][req.context.currentVersion].products[
186-
req.context.currentProduct
187-
]
188-
)
189-
)
190-
: null,
191-
productSiteTreeNew: req.context.FEATURE_NEW_SITETREE ? req.context.siteTree : null,
192-
featureFlags: {
193-
FEATURE_NEW_SITETREE: req.context.FEATURE_NEW_SITETREE || false,
194-
},
162+
currentProductTree: JSON.parse(JSON.stringify(req.context.currentProductTree)),
163+
featureFlags: {},
195164
}
196165
}
197166

components/context/ProductLandingContext.tsx

+17-31
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ export type CodeExample = {
1919
export type Product = {
2020
title: string
2121
href: string
22-
categories: Record<
23-
string,
24-
{
25-
href: string
26-
title: string
27-
standalone?: boolean
28-
articles?: Record<string, { href: string; title: string; shortTitle?: string }>
29-
}
30-
>
3122
}
3223

3324
export type ProductLandingContextT = {
@@ -79,14 +70,7 @@ export const useProductLandingContext = (): ProductLandingContextT => {
7970
}
8071

8172
export const getProductLandingContextFromRequest = (req: any): ProductLandingContextT => {
82-
const {
83-
currentCategory,
84-
currentPath,
85-
siteTree,
86-
currentLanguage,
87-
currentVersion,
88-
currentProduct,
89-
} = req.context
73+
const productTree = req.context.currentProductTree
9074
return {
9175
...pick(req.context.page, [
9276
'title',
@@ -97,14 +81,13 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
9781
'product_video',
9882
'changelog',
9983
]),
100-
product: JSON.parse(
101-
JSON.stringify(siteTree[currentLanguage][currentVersion].products[currentProduct])
102-
),
103-
whatsNewChangelog: req.context.whatsNewChangelog,
104-
changelogUrl: req.context.changelogUrl,
105-
84+
product: {
85+
href: productTree.href,
86+
title: productTree.renderedShortTitle || productTree.renderedFullTitle,
87+
},
88+
whatsNewChangelog: req.context.whatsNewChangelog || [],
89+
changelogUrl: req.context.changelogUrl || [],
10690
productCodeExamples: req.context.productCodeExamples || [],
107-
10891
productCommunityExamples: req.context.productCommunityExamples || [],
10992

11093
productUserExamples: (req.context.productUserExamples || []).map(
@@ -114,11 +97,13 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
11497
})
11598
),
11699

117-
introLinks: Object.fromEntries(
118-
Object.entries(req.context.page.introLinks || {}).filter(([key, val]) => !!val)
119-
),
100+
introLinks: {
101+
quickstart: productTree.page.introLinks.quickstart,
102+
reference: productTree.page.introLinks.reference,
103+
overview: productTree.page.introLinks.overview,
104+
},
120105

121-
guideCards: (req.context.featuredLinks.guideCards || []).map((link: any) => {
106+
guideCards: (req.context.featuredLinks ? (req.context.featuredLinks.guideCards || []) : []).map((link: any) => {
122107
return {
123108
href: link.href,
124109
title: link.title,
@@ -127,14 +112,14 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
127112
}
128113
}),
129114

130-
featuredArticles: Object.entries(req.context.featuredLinks)
115+
featuredArticles: Object.entries(req.context.featuredLinks || [])
131116
.filter(([key]) => {
132117
return key === 'guides' || key === 'popular'
133118
})
134119
.map(([key, links]: any) => {
135120
return {
136121
label: req.context.site.data.ui.toc[key],
137-
viewAllHref: key === 'guides' && !currentCategory ? `${currentPath}/${key}` : '',
122+
viewAllHref: key === 'guides' && !req.context.currentCategory ? `${req.context.currentPath}/${key}` : '',
138123
articles: links.map((link: any) => {
139124
return {
140125
hideIntro: key === 'popular',
@@ -145,6 +130,7 @@ export const getProductLandingContextFromRequest = (req: any): ProductLandingCon
145130
}
146131
}),
147132
}
148-
}),
133+
}
134+
),
149135
}
150136
}

components/hooks/useFeatureFlags.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useMainContext } from 'components/context/MainContext'
22

3-
export type FeatureFlags = {
4-
FEATURE_NEW_SITETREE: boolean
5-
}
3+
export type FeatureFlags = {}
64

75
export const useFeatureFlags = (): FeatureFlags => {
86
const { featureFlags } = useMainContext()

components/landing/AllArticlesProduct.tsx

-55
This file was deleted.

components/landing/ProductArticlesList.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import Link from 'next/link'
22

3+
import cx from 'classnames'
34
import { useState } from 'react'
45
import { ChevronUpIcon } from '@primer/octicons-react'
5-
import { SiteTreePage, useMainContext } from 'components/context/MainContext'
6+
import { CurrentProductTree, useMainContext } from 'components/context/MainContext'
67

78
const maxArticles = 10
89

910
export const ProductArticlesList = () => {
10-
const { productSiteTreeNew } = useMainContext()
11+
const { currentProductTree } = useMainContext()
1112

12-
if (!productSiteTreeNew) {
13+
if (!currentProductTree) {
1314
return null
1415
}
1516

1617
return (
1718
<div className="d-flex gutter flex-wrap">
18-
{productSiteTreeNew.childPages.map((childPage) => {
19+
{currentProductTree.childPages.map((childPage) => {
1920
if (childPage.page.documentType === 'article') {
2021
return null
2122
}
@@ -26,7 +27,7 @@ export const ProductArticlesList = () => {
2627
)
2728
}
2829

29-
const ArticleList = ({ page }: { page: SiteTreePage }) => {
30+
const ArticleList = ({ page }: { page: CurrentProductTree }) => {
3031
const [isShowingMore, setIsShowingMore] = useState(false)
3132

3233
return (
@@ -38,13 +39,13 @@ const ArticleList = ({ page }: { page: SiteTreePage }) => {
3839
</h4>
3940

4041
<ul className="list-style-none">
41-
{page.childPages.map((grandchildPage) => {
42+
{page.childPages.map((grandchildPage, index) => {
4243
if (page.childPages[0].page.documentType === 'mapTopic' && grandchildPage.page.hidden) {
4344
return null
4445
}
4546

4647
return (
47-
<li className="mb-3 { page.childPages.length > maxArticles ? d-none : null }">
48+
<li className={cx('mb-3', index >= maxArticles ? 'd-none' : null)}>
4849
<Link href={grandchildPage.href}>
4950
<a>{grandchildPage.page.title}</a>
5051
</Link>

components/product/ProductSiteTreeNew.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AllProductsLink } from 'components/product/AllProductsLink'
1313
// -->
1414
export const ProductSiteTreeNew = () => {
1515
const router = useRouter()
16-
const { productSiteTreeNew: currentProductTree } = useMainContext()
16+
const { currentProductTree: currentProductTree } = useMainContext()
1717

1818
if (!currentProductTree) {
1919
return null

pages/[versionId]/[productId]/index.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import { CommunityExamples } from 'components/landing/CommunityExamples'
2121
import { CodeExamples } from 'components/landing/CodeExamples'
2222
import { LandingSection } from 'components/landing/LandingSection'
2323
import { useTranslation } from 'components/hooks/useTranslation'
24-
import { useFeatureFlags } from 'components/hooks/useFeatureFlags'
25-
import { AllArticlesProduct } from 'components/landing/AllArticlesProduct'
2624
import { ProductArticlesList } from 'components/landing/ProductArticlesList'
2725

2826
type Props = {
@@ -43,7 +41,6 @@ const ProductPageInner = () => {
4341
const { title, guideCards, productUserExamples, productCommunityExamples, productCodeExamples } =
4442
useProductLandingContext()
4543
const { t } = useTranslation('product_landing')
46-
const { FEATURE_NEW_SITETREE } = useFeatureFlags()
4744

4845
return (
4946
<DefaultLayout>
@@ -82,7 +79,7 @@ const ProductPageInner = () => {
8279
)}
8380

8481
<LandingSection sectionLink="all-docs" title={`All ${title} Docs`}>
85-
{FEATURE_NEW_SITETREE ? <ProductArticlesList /> : <AllArticlesProduct />}
82+
<ProductArticlesList />
8683
</LandingSection>
8784
</DefaultLayout>
8885
)

0 commit comments

Comments
 (0)