Files
supabase/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx
T
Miranda Limonczenko 4b7af187a4 feat(docs): add Option 1 navigation behind the flag (#52191)
Closes DOCS-1469

## Problem

Option 1 in the navigation proposal groups the docs into Start, Build,
Develop and deploy, Run and manage, Self-Hosting, Reference, and
Resources. The `docs-ia-mvp-v1` flag from #52049 switches to an Option 1
config. That config is still a copy of today's navigation.

## Solution

- **Top nav:** reads Start, Build, Develop and deploy, Run and manage,
Self-Hosting, Reference, and Resources. Menus still open sidebars by URL
prefix, as they do today.
- **Run and manage:** pages under `/guides/platform`,
`/guides/security`, and `/guides/observability` share one sidebar with
the outline's seven groups.
- **Other sidebars:** follow the outline. REST, GraphQL and Realtime
share one sidebar, and Cron and Queues share one sidebar.
- **Seven new topics:** keep their outline labels and link to the
section on their source page, for example
`getting-started/api-keys#leaked-key`.
- **No flash of today's nav:** flags load in the browser, so the nav
stays invisible until the query param or the flags resolve, with a
1-second fallback. The links stay in the HTML for agents.
- **Tests:** each page appears once across the sidebars, and every link
goes to a page in today's navigation. With the flag off, `useNavItems`
returns today's navigation.

**Not changed:** no URLs move. Breadcrumbs still show today's trail,
which DOCS-1470 covers.

## Manual testing

1. Open [Database Backups with the flag
on](https://docs-git-docs-ia-nav-option-1-supabase.vercel.app/docs/guides/platform/backups?docs-ia-mvp-v1=option-1).
The top nav reads Start, Build, Develop and deploy, Run and manage,
Self-Hosting, Reference, and Resources. The sidebar shows the seven Run
and manage groups.
2. Open [the same page with the flag
off](https://docs-git-docs-ia-nav-option-1-supabase.vercel.app/docs/guides/platform/backups?docs-ia-mvp-v1=control).
Today's navigation shows.
3. Open [Database with the flag
on](https://docs-git-docs-ia-nav-option-1-supabase.vercel.app/docs/guides/database/overview?docs-ia-mvp-v1=option-1).
The sidebar starts with Connect to your database.
4. In the sidebar, open Row Level Security, roles and Vault, and select
Test RLS policies with pgTAP. The testing overview opens at Database
unit testing with pgTAP.
2026-10-28 16:03:11 +00:00

116 lines
3.3 KiB
TypeScript

'use client'
import { usePathname } from 'next/navigation'
import { Accordion } from 'radix-ui'
import { PropsWithChildren } from 'react'
import { cn } from 'ui'
import { type NavMenuSection } from '../Navigation.types'
import { MenuId } from './NavigationMenu'
import NavigationMenuGuideListItems from './NavigationMenuGuideListItems'
import { useIaNavReady, useNavItems } from '@/features/IaNav'
const NavigationMenuGuideList = ({
id,
additionalNavItems,
}: {
id: string
additionalNavItems?: Record<string, Partial<NavMenuSection>[]>
}) => {
const pathname = usePathname()
const firstLevelRoute = pathname?.split('/')?.slice(0, 4)?.join('/')
const NavItems = useNavItems()
const isNavReady = useIaNavReady()
let menu = NavItems[id]
if (id === MenuId.Integrations && additionalNavItems?.integrations) {
const integrationsListIndex = menu.items.findIndex((item) => item.name === 'Integrations')
if (integrationsListIndex !== -1) {
menu = {
...menu,
items: [
...menu.items.slice(0, integrationsListIndex),
{
...menu.items[integrationsListIndex],
items: [...menu.items[integrationsListIndex].items, ...additionalNavItems.integrations],
},
...menu.items.slice(integrationsListIndex + 1),
],
}
}
}
// Inject federated prompts into the 'AI Tools > Prompts' section
if (id === MenuId.GettingStarted && additionalNavItems?.prompts) {
const aiToolsSectionIndex = menu.items.findIndex((item) => item.name === 'AI Tools')
if (aiToolsSectionIndex !== -1) {
const beforeAITools = menu.items.slice(0, aiToolsSectionIndex)
const afterAITools = menu.items.slice(aiToolsSectionIndex + 1)
const aiToolsSection = menu.items[aiToolsSectionIndex]
const promptsSectionIndex = aiToolsSection.items.findIndex((item) => item.name === 'Prompts')
if (promptsSectionIndex !== -1) {
const beforePrompts = aiToolsSection.items.slice(0, promptsSectionIndex)
const afterPrompts = aiToolsSection.items.slice(promptsSectionIndex + 1)
const promptsSection = aiToolsSection.items[promptsSectionIndex]
const modifiedPromptsSection = {
...promptsSection,
items: additionalNavItems.prompts,
}
const modifiedAIToolsSection = {
...aiToolsSection,
items: [...beforePrompts, modifiedPromptsSection, ...afterPrompts],
}
menu = {
...menu,
items: [...beforeAITools, modifiedAIToolsSection, ...afterAITools],
}
}
}
}
return (
<NavigationMenuGuideListWrapper
id={id}
firstLevelRoute={firstLevelRoute}
className={cn(!isNavReady && 'invisible noscript:visible')}
>
<NavigationMenuGuideListItems menu={menu} id={id} />
</NavigationMenuGuideListWrapper>
)
}
export function NavigationMenuGuideListWrapper({
id,
firstLevelRoute,
className,
children,
}: PropsWithChildren<{
id: string
firstLevelRoute?: string
className?: string
}>) {
return (
<Accordion.Root
collapsible={true}
key={id}
type="single"
value={firstLevelRoute}
className={cn(
'transition-all duration-150 ease-out opacity-100 ml-0 delay-150 w-full',
className
)}
>
{children}
</Accordion.Root>
)
}
export default NavigationMenuGuideList