diff --git a/components/context/RestContext.tsx b/components/context/AutomatedPageContext.tsx similarity index 51% rename from components/context/RestContext.tsx rename to components/context/AutomatedPageContext.tsx index dcce66b990..745dbd892f 100644 --- a/components/context/RestContext.tsx +++ b/components/context/AutomatedPageContext.tsx @@ -1,26 +1,28 @@ import { createContext, useContext } from 'react' import type { MiniTocItem } from 'components/context/ArticleContext' -export type RestContextT = { +export type AutomatedPageContextT = { title: string intro: string renderedPage: string | JSX.Element[] miniTocItems: Array } -export const RestContext = createContext(null) +export const AutomatedPageContext = createContext(null) -export const useRestContext = (): RestContextT => { - const context = useContext(RestContext) +export const useAutomatedPageContext = (): AutomatedPageContextT => { + const context = useContext(AutomatedPageContext) if (!context) { - throw new Error('"useRestContext" may only be used inside "RestContext.Provider"') + throw new Error( + '"useAutomatedPageContext" may only be used inside "AutomatedPageContext.Provider"' + ) } return context } -export const getRestContextFromRequest = (req: any): RestContextT => { +export const getAutomatedPageContextFromRequest = (req: any): AutomatedPageContextT => { const page = req.context.page return { diff --git a/components/rest/RestReferencePage.tsx b/components/rest/RestReferencePage.tsx index e19455c63c..193f1f6784 100644 --- a/components/rest/RestReferencePage.tsx +++ b/components/rest/RestReferencePage.tsx @@ -8,7 +8,7 @@ import { MarkdownContent } from 'components/ui/MarkdownContent' import { Lead } from 'components/ui/Lead' import { RestOperation } from './RestOperation' import styles from './RestOperation.module.scss' -import { useRestContext } from 'components/context/RestContext' +import { useAutomatedPageContext } from 'components/context/AutomatedPageContext' import { Operation } from './types' const ClientSideHighlightJS = dynamic(() => import('components/article/ClientSideHighlightJS'), { @@ -28,7 +28,7 @@ export type StructuredContentT = { export const RestReferencePage = ({ restOperations }: StructuredContentT) => { const { asPath } = useRouter() - const { title, intro, renderedPage } = useRestContext() + const { title, intro, renderedPage } = useAutomatedPageContext() // We have some one-off redirects for rest api docs // currently those are limited to the repos page, but // that will grow soon as we restructure the rest api docs. diff --git a/components/sidebar/RestCollapsibleSection.tsx b/components/sidebar/RestCollapsibleSection.tsx index 667b33bfa9..ca9e687039 100644 --- a/components/sidebar/RestCollapsibleSection.tsx +++ b/components/sidebar/RestCollapsibleSection.tsx @@ -7,7 +7,7 @@ import { ActionList } from '@primer/react' import { Link } from 'components/Link' import { ProductTreeNode } from 'components/context/MainContext' import { EventType, sendEvent } from 'components/lib/events' -import { useRestContext } from 'components/context/RestContext' +import { useAutomatedPageContext } from 'components/context/AutomatedPageContext' import type { MiniTocItem } from 'components/context/ArticleContext' import styles from './SidebarProduct.module.scss' @@ -47,7 +47,7 @@ export const RestCollapsibleSection = (props: SectionProps) => { router.asPath.includes('/rest/guides') || router.asPath.includes('/rest/overview') ? [] - : useRestContext().miniTocItems + : useAutomatedPageContext().miniTocItems useEffect(() => { if (!currentAnchor) { diff --git a/pages/[versionId]/rest/[category]/[subcategory].tsx b/pages/[versionId]/rest/[category]/[subcategory].tsx index 2fc00e4479..8ea6cb1458 100644 --- a/pages/[versionId]/rest/[category]/[subcategory].tsx +++ b/pages/[versionId]/rest/[category]/[subcategory].tsx @@ -4,10 +4,10 @@ import { Operation } from 'components/rest/types' import { RestReferencePage } from 'components/rest/RestReferencePage' import { getMainContext, MainContext, MainContextT } from 'components/context/MainContext' import { - RestContext, - RestContextT, - getRestContextFromRequest, -} from 'components/context/RestContext' + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' import type { MiniTocItem } from 'components/context/ArticleContext' type MinitocItemsT = { @@ -16,16 +16,16 @@ type MinitocItemsT = { type Props = { mainContext: MainContextT - restContext: RestContextT + automatedPageContext: AutomatedPageContextT restOperations: Operation[] } -export default function SubCategory({ mainContext, restContext, restOperations }: Props) { +export default function SubCategory({ mainContext, automatedPageContext, restOperations }: Props) { return ( - + - + ) } @@ -50,7 +50,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => // Gets the miniTocItems in the article context. At this point it will only // include miniTocItems generated from the Markdown pages in // content/rest/* - const { miniTocItems } = getRestContextFromRequest(req) + const { miniTocItems } = getAutomatedPageContextFromRequest(req) // When operations exist, update the miniTocItems in the article context // with the list of operations in the OpenAPI. @@ -75,7 +75,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => props: { restOperations, mainContext: getMainContext(req, res), - restContext: getRestContextFromRequest(req), + automatedPageContext: getAutomatedPageContextFromRequest(req), }, } } diff --git a/pages/[versionId]/rest/[category]/index.tsx b/pages/[versionId]/rest/[category]/index.tsx index 0bdbe9554e..aa92bb9802 100644 --- a/pages/[versionId]/rest/[category]/index.tsx +++ b/pages/[versionId]/rest/[category]/index.tsx @@ -5,10 +5,10 @@ import { Operation } from 'components/rest/types' import { RestReferencePage } from 'components/rest/RestReferencePage' import { getMainContext, MainContext, MainContextT } from 'components/context/MainContext' import { - RestContext, - RestContextT, - getRestContextFromRequest, -} from 'components/context/RestContext' + AutomatedPageContext, + AutomatedPageContextT, + getAutomatedPageContextFromRequest, +} from 'components/context/AutomatedPageContext' import type { MiniTocItem } from 'components/context/ArticleContext' import { getTocLandingContextFromRequest, @@ -25,13 +25,13 @@ type MinitocItemsT = { type Props = { mainContext: MainContextT tocLandingContext: TocLandingContextT - restContext: RestContextT + automatedPageContext: AutomatedPageContextT restOperations: Operation[] } export default function Category({ mainContext, - restContext, + automatedPageContext, tocLandingContext, restOperations, }: Props) { @@ -39,7 +39,7 @@ export default function Category({ return ( - + {/* When the page is the rest product landing page, we don't want to render the rest-specific sidebar because toggling open the categories won't have the minitoc items at that level. These are pages that have @@ -51,7 +51,7 @@ export default function Category({ ) : ( )} - + ) } @@ -165,7 +165,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => // Gets the miniTocItems in the article context. At this point it will only // include miniTocItems generated from the Markdown pages in // content/rest/* - const { miniTocItems } = getRestContextFromRequest(req) + const { miniTocItems } = getAutomatedPageContextFromRequest(req) // When operations exist, update the miniTocItems in the article context // with the list of operations in the OpenAPI. @@ -194,7 +194,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => props: { restOperations, mainContext: getMainContext(req, res), - restContext: getRestContextFromRequest(req), + automatedPageContext: getAutomatedPageContextFromRequest(req), tocLandingContext, }, }