Files
supabase/apps/docs/features/docs/Reference.apiPage.tsx
T
Kody JacksonandClaude Haiku 5.5 e646c430d7 refactor(docs) - tidy Mgmt API heading props (#52392)
## What changed

Follow-up to #52340, addressing the review comments left after it
merged:

- Removed the redundant `headingTag="h2"` on the Management API intro
section. `h2` is the default, and the intro header is hidden on pages
with `hideTitle`.
- Exported a `HeadingTag` type from `Reference.ui.tsx` and used it in
the section prop types.
- Renamed the `headingTag` prop to `tag` to match the `tag` prop on the
shared `Heading` component.

Manually poked around at pages like the following and behavior seems to
be the same:
-
https://docs-git-kody-docs-mgmt-api-heading-cleanup-supabase.vercel.app/docs/reference/cli/global-flags
-
https://docs-git-kody-docs-mgmt-api-heading-cleanup-supabase.vercel.app/docs/reference/javascript/typescript-support

https://docs-git-kody-docs-mgmt-api-heading-cleanup-supabase.vercel.app/docs/reference/api/v1-get-security-advisors

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-27 09:12:02 -05:00

94 lines
3.7 KiB
TypeScript

import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'
import { reference_api } from '~/components/Navigation/NavigationMenu/NavigationMenu.constants'
import { TocAnchorsProvider } from '~/features/docs/GuidesMdx.client'
import { getSectionsBySlug } from '~/features/docs/Reference.generated.singleton'
import { getRefFrontmatter } from '~/features/docs/Reference.mdx'
import { ReferenceNavigation } from '~/features/docs/Reference.navigation'
import { ReferenceContentScrollHandler } from '~/features/docs/Reference.navigation.client'
import { SectionSwitch } from '~/features/docs/Reference.sections'
import {
ReferenceLinks,
ReferenceSidebar,
type ReferenceLink,
} from '~/features/docs/Reference.sidebar'
import { LayoutMainContent } from '~/layouts/DefaultLayout'
import { SidebarSkeleton } from '~/layouts/MainSkeleton'
import { notFound, redirect } from 'next/navigation'
import { cn } from 'ui'
export async function ApiReferencePage({ path }: { path: Array<string> }) {
const operationSlug = path[0]
if (!operationSlug) {
redirect('/reference/api/introduction')
}
return <ApiOperationPage operationSlug={operationSlug} />
}
// DOCS-1268: one endpoint per page, reusing the same SectionSwitch (and
// therefore the same ApiEndpointSection/MarkdownSection) that used to render
// every operation on the single monolithic /reference/api page.
async function ApiOperationPage({ operationSlug }: { operationSlug: string }) {
const sectionsBySlug = await getSectionsBySlug('api', 'latest')
const section = sectionsBySlug?.get(operationSlug)
if (!section) notFound()
const isIntroduction = section.type === 'markdown'
const additionalLinks = isIntroduction
? (((await getRefFrontmatter(`api/${section.id}`)).links as ReferenceLink[] | undefined) ?? [])
: []
return (
<ReferenceContentScrollHandler libPath="api" version="latest" isLatestVersion={true}>
<SidebarSkeleton
menuId={MenuId.RefApi}
NavigationMenu={
<ReferenceNavigation
libraryId="api"
name="Management API"
menuData={reference_api}
libPath="api"
version="latest"
isLatestVersion={true}
realNavigation
/>
}
>
<LayoutMainContent>
{isIntroduction ? (
<TocAnchorsProvider>
<div className="grid grid-cols-12 relative gap-4">
<article
// Used to get headings for the table of contents
id="sb-docs-guide-main-article"
className="@container/article col-span-12 md:col-span-8 min-w-0"
>
<SectionSwitch libraryId="api" version="latest" section={section} />
{/* The sidebar is hidden below `md`, so keep the links reachable */}
{additionalLinks.length !== 0 && (
<ReferenceLinks links={additionalLinks} className="mt-8 md:hidden" />
)}
</article>
<ReferenceSidebar
links={additionalLinks}
className={cn(
'hidden md:flex md:col-span-3 md:col-start-10',
'self-start sticky',
'top-[calc(var(--header-height)+3rem)]',
'max-h-[calc(100vh-var(--header-height)-4rem)]'
)}
/>
</div>
</TocAnchorsProvider>
) : (
<article className="@container/article">
<SectionSwitch libraryId="api" version="latest" section={section} tag="h1" />
</article>
)}
</LayoutMainContent>
</SidebarSkeleton>
</ReferenceContentScrollHandler>
)
}