* cleanup FEATURE_NEXTJS * fixing some server tests * updating article a for server tests * update h2 to h4 map topic tests * data off on TOCs * updating dropdown article versions links * Update so markdown renders in intros * updating typo and all server tests are now passing * remove nextjs feature flag * head.js tests pass * updating article-version-picker * remove nextjs feature flag browser test * update header.js tests * fix page-titles.js test * fix deprecated-enterprise versions * adding early access * testing * getting childTocItem * fixing table of contents to show child toc items * updated to 2 because the sidebar article also has the same link * remove comment * updating pick * Update TocLandingContext.tsx * update package.json and change className to h4 for h2 * updating with mikes feedback * remove a.active test * React clean up: Delete unnecessary layouts/includes Part 2 (#20143) * Delete unnecessary layouts * setting back tests failing :( * update layouts * delete unnecessary includes * remove github-ae-release-notes and updating layouts * remove a.active test
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import pick from 'lodash/pick'
|
|
import { createContext, useContext } from 'react'
|
|
import { FeaturedLink, getFeaturedLinksFromReq } from './ProductLandingContext'
|
|
|
|
export type TocItem = {
|
|
fullPath: string
|
|
title: string
|
|
intro?: string
|
|
}
|
|
|
|
export type TocLandingContextT = {
|
|
title: string
|
|
introPlainText: string
|
|
productCallout: string
|
|
isEarlyAccess: boolean
|
|
tocItems: Array<TocItem>
|
|
variant?: 'compact' | 'expanded'
|
|
featuredLinks: Record<string, Array<FeaturedLink>>
|
|
renderedEarlyAccessPage: string
|
|
}
|
|
|
|
export const TocLandingContext = createContext<TocLandingContextT | null>(null)
|
|
|
|
export const useTocLandingContext = (): TocLandingContextT => {
|
|
const context = useContext(TocLandingContext)
|
|
|
|
if (!context) {
|
|
throw new Error('"useTocLandingContext" may only be used inside "TocLandingContext.Provider"')
|
|
}
|
|
|
|
return context
|
|
}
|
|
|
|
export const getTocLandingContextFromRequest = (req: any): TocLandingContextT => {
|
|
return {
|
|
title: req.context.page.title,
|
|
productCallout: req.context.page.product || '',
|
|
introPlainText: req.context.page.introPlainText,
|
|
isEarlyAccess: req.context.page?.documentType === 'early-access',
|
|
tocItems: (req.context.genericTocFlat || req.context.genericTocNested || []).map((obj: any) =>
|
|
pick(obj, ['fullPath', 'title', 'intro', 'childTocItems'])
|
|
),
|
|
variant: req.context.genericTocFlat ? 'expanded' : 'compact',
|
|
|
|
featuredLinks: getFeaturedLinksFromReq(req),
|
|
renderedEarlyAccessPage: req.context.renderedPage,
|
|
}
|
|
}
|