Files
supabase/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx
T
Miranda Limonczenko 447cfa5227 feat(docs): add docs-ia-mvp-v1 flag for the new navigation (#52049)
Closes DOCS-1464

## Problem

The new docs navigation, Option 1, needs an A/B test against today's
navigation. The docs app has no flag that switches the navigation per
visitor.

`docs:*` keys in this repo are build-time toggles from
`enabled-features`. They are the same for every visitor, so they can't
run an A/B. The flag is `docs-ia-mvp-v1`, a PostHog multivariate flag,
like `docs-search-v2`.

## Solution

- **Variant hook:** `useIaNavVariant` reads `docs-ia-mvp-v1` and returns
`control` or `option-1`. It copies `useSearchV2Variant`. It returns
`control` until the flag resolves, records exposure once resolved, and
respects consent.
- **Query param override:** `?docs-ia-mvp-v1=option-1` or
`?docs-ia-mvp-v1=control` forces a variant for dogfooding and evals. A
forced variant records no exposure.
- **Option 1 config:** `features/IaNav/option1.constants.ts` re-exports
today's navigation constants. An export defined in that file replaces
the re-exported one, so Option 1 in DOCS-1469 overrides only what
changes.
- **Consumers:** The top nav, the mobile menu, and the guide sidebar
read from `useNavItems`, which picks the config for the variant.

**Not changed:** Reference sidebars, breadcrumbs, and hub pages.
Breadcrumbs and hub pages can read `useIaNavVariant` in DOCS-1470 and
DOCS-1471.

**PostHog:** The flag doesn't exist in PostHog yet. Until it does, every
visitor gets `control`, and the query param still works.

## Manual testing

1. Open [Auth with Option 1
forced](https://docs-git-docs-ia-nav-flag-supabase.vercel.app/docs/guides/auth?docs-ia-mvp-v1=option-1).
The top nav and sidebar match today's navigation, because the Option 1
config is a copy. Locally, you can make a change to see the variant.
2. Open [Auth with no
param](https://docs-git-docs-ia-nav-flag-supabase.vercel.app/docs/guides/auth).
The navigation is unchanged.
2026-10-27 15:00:59 -07:00

105 lines
3.1 KiB
TypeScript

'use client'
import { usePathname } from 'next/navigation'
import { Accordion } from 'radix-ui'
import { PropsWithChildren } from 'react'
import { type NavMenuSection } from '../Navigation.types'
import { MenuId } from './NavigationMenu'
import NavigationMenuGuideListItems from './NavigationMenuGuideListItems'
import { 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()
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}>
<NavigationMenuGuideListItems menu={menu} id={id} />
</NavigationMenuGuideListWrapper>
)
}
export function NavigationMenuGuideListWrapper({
id,
firstLevelRoute,
children,
}: PropsWithChildren<{
id: string
firstLevelRoute?: string
}>) {
return (
<Accordion.Root
collapsible={true}
key={id}
type="single"
value={firstLevelRoute}
className="transition-all duration-150 ease-out opacity-100 ml-0 delay-150 w-full"
>
{children}
</Accordion.Root>
)
}
export default NavigationMenuGuideList