mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem - after #53761 the option-1 sidebar reference list has no row for server, middleware and tanstack db - list marks no row as current on a library page, for example on `/reference/javascript/select` - management api intro shows its endpoint list in the right rail and its toc in an extra column inside the content ## Solution - adds the server, middleware and tanstack db rows with the new and experimental badges of the current nav - fixes the reference list so it marks the library of the current page - changes the management api to open as its own sidebar level with the endpoint list on the left - moves the toc, the links and the feedback of the management api intro into the right rail + removes the rail on endpoint pages - adds the "on this page" menu to the management api intro below `lg` - adds the reference library column to the option-1 nav size allowlist because it is a list of peer libraries | before | after | | -------|------| | <img width="2880" height="1800" alt="image" src="https://github.com/user-attachments/assets/3a216c0b-31c1-4629-82a1-0590c7e639ae" /> | <img width="2880" height="1800" alt="image" src="https://github.com/user-attachments/assets/c53afc0e-8d15-45d7-9dc8-320443761ed2" /> | | before | after | | -------|------| | <img width="2880" height="1800" alt="image" src="https://github.com/user-attachments/assets/5dc79bb9-b160-44e6-a3c5-39182fb71d4f" /> | <img width="2880" height="1800" alt="image" src="https://github.com/user-attachments/assets/9e0dff3c-5261-4c70-b1f1-f74314231a08" /> | <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. open [/docs/reference?docs-ia-mvp-v1=option-1](https://docs-ivb0vb1qq-supabase.vercel.app/docs/reference?docs-ia-mvp-v1=option-1) and do all steps in the same tab because the flag override lasts only for the tab 2. make sure that the reference list shows server and middleware 3. open [/docs/reference/javascript/select](https://docs-ivb0vb1qq-supabase.vercel.app/docs/reference/javascript/select) and make sure that the sidebar marks only the javascript row 4. click `Management API` in the sidebar and make sure that the sidebar shows `< Management API` with the endpoint list 5. make sure that the right rail shows the toc, the additional links and the feedback buttons 6. open [/docs/guides/database/overview](https://docs-ivb0vb1qq-supabase.vercel.app/docs/guides/database/overview) and make sure that the sidebar and the right rail did not change ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
405 lines
14 KiB
TypeScript
405 lines
14 KiB
TypeScript
'use client'
|
|
|
|
import type { NavMenuSection } from '~/components/Navigation/Navigation.types'
|
|
import {
|
|
DocsSidebarNav,
|
|
DocsSidebarNavProvider,
|
|
DocsSidebarNavTop,
|
|
DocsSidebarResources,
|
|
} from '~/components/Navigation/NavigationMenu/DocsSidebarNav'
|
|
import DefaultNavigationMenu, {
|
|
type MenuId,
|
|
} from '~/components/Navigation/NavigationMenu/NavigationMenu'
|
|
import { isReferencePath } from '~/components/Navigation/NavigationMenu/DocsSidebarNav.utils'
|
|
import {
|
|
getMenuGroupLabel,
|
|
getListedMenuId,
|
|
getMenuGroupLabelByPath,
|
|
useCloseMenuOnRouteChange,
|
|
} from '~/components/Navigation/NavigationMenu/NavigationMenu.utils'
|
|
import { DesktopTopNavBar, MobileTopNavBar } from '~/components/Navigation/NavigationMenu/TopNavBar'
|
|
import { LegacyTopNavBar } from '~/components/Navigation/NavigationMenu/TopNavBar.legacy'
|
|
import { useDocsLayoutV2 } from '~/features/DocsLayout/useDocsLayoutV2'
|
|
import { useDocsPathname, useNavItems } from '~/features/IaNav'
|
|
import { DOCS_CONTENT_CONTAINER_ID } from '~/features/ui/helpers.constants'
|
|
import { menuState, useMenuMobileOpen } from '~/hooks/useMenuState'
|
|
import { HeadingSlotProvider } from '~/layouts/HeadingSlot'
|
|
import { MobileHeaderSlotsContext } from '~/layouts/MobileHeaderSlots'
|
|
import { RightRailProvider } from '~/layouts/RightRail'
|
|
import { UpdatedAtSlotProvider } from '~/layouts/UpdatedAtSlot'
|
|
// End of third-party imports
|
|
|
|
import { isFeatureEnabled } from 'common'
|
|
import dynamic from 'next/dynamic'
|
|
import {
|
|
memo,
|
|
useRef,
|
|
useState,
|
|
type PropsWithChildren,
|
|
type ReactNode,
|
|
type RefObject,
|
|
} from 'react'
|
|
import { cn, ScrollBar, ScrollRoot, ScrollViewport } from 'ui'
|
|
import { MobileNavLock } from 'ui-patterns/MobileNav/MobileNavLock'
|
|
|
|
interface NavContainerProps extends PropsWithChildren {
|
|
toggleRef: RefObject<HTMLElement | null>
|
|
className?: string
|
|
}
|
|
|
|
const Footer = dynamic(() => import('~/components/Navigation/Footer').then((mod) => mod.Footer))
|
|
const LegacyFooter = dynamic(() =>
|
|
import('~/components/Navigation/Footer.legacy').then((mod) => mod.LegacyFooter)
|
|
)
|
|
const GlobalMenuDrawerSection = dynamic(() =>
|
|
import('~/components/Navigation/NavigationMenu/GlobalMenuDrawer').then(
|
|
(mod) => mod.GlobalMenuDrawerSection
|
|
)
|
|
)
|
|
const GlobalMenuDrawerFooter = dynamic(() =>
|
|
import('~/components/Navigation/NavigationMenu/GlobalMenuDrawer').then(
|
|
(mod) => mod.GlobalMenuDrawerFooter
|
|
)
|
|
)
|
|
|
|
const footerEnabled = isFeatureEnabled('docs:footer')
|
|
|
|
const Container = memo(function Container({
|
|
children,
|
|
className,
|
|
}: PropsWithChildren<{ className?: string }>) {
|
|
return (
|
|
<main
|
|
// used by layout to scroll to top
|
|
id={DOCS_CONTENT_CONTAINER_ID}
|
|
tabIndex={-1}
|
|
className={cn(
|
|
'w-full layout-v2:min-w-0 transition-all ease-out relative scroll-mt-(--header-height) outline-hidden',
|
|
// desktop override any margin styles
|
|
'lg:ml-0',
|
|
className
|
|
)}
|
|
>
|
|
<div className="flex flex-col sticky top-0">{children}</div>
|
|
</main>
|
|
)
|
|
})
|
|
|
|
const NavContainer = memo(function NavContainer({
|
|
children,
|
|
toggleRef,
|
|
className,
|
|
}: NavContainerProps) {
|
|
const mobileMenuOpen = useMenuMobileOpen()
|
|
|
|
return (
|
|
<nav
|
|
aria-labelledby="main-nav-title"
|
|
data-docs-sidebar
|
|
className={cn(
|
|
'fixed lg:relative z-40 lg:z-auto',
|
|
'inset-x-0 top-(--header-height) overflow-hidden',
|
|
'h-[calc(100dvh-var(--header-height))]',
|
|
!mobileMenuOpen && 'max-lg:hidden',
|
|
'lg:w-(--docs-side-column-width) lg:shrink-0 lg:left-0',
|
|
'lg:top-(--header-height) lg:sticky',
|
|
'lg:h-[calc(100vh-var(--header-height))]',
|
|
'flex flex-col ml-0',
|
|
'lg:border-r',
|
|
className
|
|
)}
|
|
>
|
|
{mobileMenuOpen ? <MobileNavLock toggleRef={toggleRef} /> : null}
|
|
<div className="hidden lg:block shrink-0 px-4 bg-background">
|
|
<DocsSidebarNavTop className="-mx-4 flex px-4 pt-2" />
|
|
</div>
|
|
<ScrollRoot className="flex min-h-0 flex-1 flex-col">
|
|
<ScrollViewport
|
|
// firefox makes a scroll container a tab stop, but the links inside already scroll it
|
|
tabIndex={-1}
|
|
className={cn(
|
|
'docs-sidebar-scroll relative scroll-pt-8 scroll-pb-24',
|
|
'overscroll-contain',
|
|
'lg:backdrop-blur-sm lg:backdrop-filter bg-background'
|
|
)}
|
|
>
|
|
<span id="main-nav-title" className="sr-only">
|
|
Main menu
|
|
</span>
|
|
<div
|
|
className={cn(
|
|
'transition-all ease-out duration-200',
|
|
'px-6 pt-6 pb-16 lg:pb-32',
|
|
'bg-background',
|
|
// desktop styles
|
|
'lg:pb-10 lg:px-4 lg:pt-0 lg:flex lg:flex-col',
|
|
'lg:opacity-100 lg:visible'
|
|
)}
|
|
>
|
|
<div className="lg:pl-2">
|
|
<DocsSidebarNav>{children}</DocsSidebarNav>
|
|
</div>
|
|
</div>
|
|
</ScrollViewport>
|
|
<ScrollBar />
|
|
</ScrollRoot>
|
|
<GlobalMenuDrawerFooter className="shrink-0 border-t bg-background px-6 py-4 lg:hidden" />
|
|
<DocsSidebarResources className="hidden lg:flex shrink-0 border-t py-2 pl-6 pr-4" />
|
|
</nav>
|
|
)
|
|
})
|
|
|
|
// legacy sidebar for the docs-ia-mvp-v1 control variant. delete it when option-1 ships
|
|
const LegacyNavContainer = memo(function LegacyNavContainer({
|
|
children,
|
|
toggleRef,
|
|
className,
|
|
}: NavContainerProps) {
|
|
const mobileMenuOpen = useMenuMobileOpen()
|
|
|
|
return (
|
|
<nav
|
|
aria-labelledby="main-nav-title"
|
|
data-docs-nav="sidebar"
|
|
className={cn(
|
|
'fixed lg:relative z-40 lg:z-auto',
|
|
'inset-x-0 top-(--header-height) overflow-hidden',
|
|
'h-[calc(100dvh-var(--header-height))]',
|
|
!mobileMenuOpen && 'max-lg:hidden',
|
|
'lg:w-[420px] layout-v2:lg:w-(--docs-side-column-width) layout-v2:lg:shrink-0 lg:left-0',
|
|
'lg:top-(--header-height) lg:sticky',
|
|
'lg:h-[calc(100vh-var(--header-height))]',
|
|
'flex flex-col ml-0',
|
|
'lg:border-r',
|
|
'lg:overflow-y-auto',
|
|
className
|
|
)}
|
|
>
|
|
{mobileMenuOpen ? <MobileNavLock toggleRef={toggleRef} /> : null}
|
|
<ScrollRoot className="flex min-h-0 flex-1 flex-col">
|
|
<ScrollViewport
|
|
className={cn(
|
|
'relative',
|
|
'overscroll-contain',
|
|
'lg:backdrop-blur-sm lg:backdrop-filter bg-background'
|
|
)}
|
|
>
|
|
<span id="main-nav-title" className="sr-only">
|
|
Main menu
|
|
</span>
|
|
<div className="top-0 sticky h-0 z-10">
|
|
<div className="bg-linear-to-b from-background to-transparent h-4 w-full"></div>
|
|
</div>
|
|
<div
|
|
className={cn(
|
|
'transition-all ease-out duration-200',
|
|
'px-6 pt-6 pb-16 lg:pb-32',
|
|
'bg-background',
|
|
// desktop styles
|
|
'lg:pb-10 lg:px-10 lg:flex',
|
|
'lg:opacity-100 lg:visible'
|
|
)}
|
|
>
|
|
{children}
|
|
</div>
|
|
</ScrollViewport>
|
|
<ScrollBar />
|
|
</ScrollRoot>
|
|
<GlobalMenuDrawerFooter className="shrink-0 border-t bg-background px-6 py-4 lg:hidden" />
|
|
</nav>
|
|
)
|
|
})
|
|
|
|
interface SkeletonSideNavProps extends PropsWithChildren {
|
|
toggleRef: RefObject<HTMLElement | null>
|
|
menuId?: MenuId
|
|
additionalNavItems?: Record<string, Partial<NavMenuSection>[]>
|
|
className?: string
|
|
}
|
|
|
|
interface SkeletonRightRailProps {
|
|
hasRightRail: boolean
|
|
onTargetChange: (target: HTMLElement | null) => void
|
|
}
|
|
|
|
interface SkeletonProps extends PropsWithChildren {
|
|
menuId?: MenuId
|
|
hideSideNav?: boolean
|
|
hasRightRail?: boolean
|
|
NavigationMenu?: ReactNode
|
|
hideFooter?: boolean
|
|
className?: string
|
|
additionalNavItems?: Record<string, Partial<NavMenuSection>[]>
|
|
}
|
|
|
|
const SkeletonSideNav = ({
|
|
toggleRef,
|
|
menuId,
|
|
additionalNavItems,
|
|
className,
|
|
children,
|
|
}: SkeletonSideNavProps) =>
|
|
useDocsLayoutV2() ? (
|
|
<DocsSidebarNavProvider menuId={menuId} additionalNavItems={additionalNavItems}>
|
|
<NavContainer toggleRef={toggleRef} className={className}>
|
|
{children}
|
|
</NavContainer>
|
|
</DocsSidebarNavProvider>
|
|
) : (
|
|
<LegacyNavContainer toggleRef={toggleRef} className={className}>
|
|
{children}
|
|
</LegacyNavContainer>
|
|
)
|
|
|
|
const SkeletonFooter = () => (useDocsLayoutV2() ? <Footer className="mt-16" /> : <LegacyFooter />)
|
|
|
|
// the server renders the legacy layout, so css shows the rail from the pre-paint layout attribute
|
|
const SkeletonRightRail = ({ hasRightRail, onTargetChange }: SkeletonRightRailProps) => {
|
|
const isLayoutV2 = useDocsLayoutV2()
|
|
if (!hasRightRail) return null
|
|
|
|
return (
|
|
<aside
|
|
data-docs-right-rail
|
|
className="hidden layout-v2:lg:block w-(--docs-side-column-width) shrink-0 border-l"
|
|
>
|
|
<div
|
|
ref={isLayoutV2 ? onTargetChange : undefined}
|
|
className="sticky top-(--header-height) flex h-[calc(100vh-var(--header-height))] flex-col"
|
|
/>
|
|
</aside>
|
|
)
|
|
}
|
|
|
|
function TopNavSkeleton({ children }: PropsWithChildren) {
|
|
const isLayoutV2 = useDocsLayoutV2()
|
|
const [headingSlot, setHeadingSlot] = useState<HTMLElement | null>(null)
|
|
const [updatedAtSlot, setUpdatedAtSlot] = useState<HTMLElement | null>(null)
|
|
|
|
return (
|
|
<HeadingSlotProvider value={headingSlot}>
|
|
<UpdatedAtSlotProvider value={updatedAtSlot}>
|
|
<div className="group/docs flex flex-col h-full w-full">
|
|
<div className="hidden lg:sticky w-full lg:flex top-0 left-0 right-0 z-50">
|
|
{isLayoutV2 ? (
|
|
<DesktopTopNavBar
|
|
headingSlotRef={setHeadingSlot}
|
|
updatedAtSlotRef={setUpdatedAtSlot}
|
|
/>
|
|
) : (
|
|
<LegacyTopNavBar />
|
|
)}
|
|
</div>
|
|
{children}
|
|
</div>
|
|
</UpdatedAtSlotProvider>
|
|
</HeadingSlotProvider>
|
|
)
|
|
}
|
|
|
|
function SidebarSkeleton({
|
|
children,
|
|
menuId: _menuId,
|
|
NavigationMenu,
|
|
hideFooter = !footerEnabled,
|
|
className,
|
|
hideSideNav,
|
|
hasRightRail = false,
|
|
additionalNavItems,
|
|
}: SkeletonProps) {
|
|
const isLayoutV2 = useDocsLayoutV2()
|
|
const pathname = useDocsPathname()
|
|
const navItems = useNavItems()
|
|
const menuId = _menuId ?? getListedMenuId({ pathname, navItems })
|
|
// the v2 docs home keeps the sidebar, so only the legacy layout hides it
|
|
const isSideNavHidden = hideSideNav && !isLayoutV2
|
|
|
|
const mobileMenuOpen = useMenuMobileOpen()
|
|
const [tocSlot, setTocSlot] = useState<HTMLDivElement | null>(null)
|
|
const [scrolledTitle, setScrolledTitle] = useState<string | null>(null)
|
|
const [pickedGroupLabel, setPickedGroupLabel] = useState<string>()
|
|
const [rightRailTarget, setRightRailTarget] = useState<HTMLElement | null>(null)
|
|
const { GLOBAL_MENU_ITEMS } = navItems
|
|
// getMenuId falls back to the getting started group, but a page without a sidebar is in no group
|
|
const treeGroupLabel = hideSideNav ? undefined : getMenuGroupLabel(menuId, GLOBAL_MENU_ITEMS)
|
|
// the reference index has no menu id, so its group comes from its path and not from the fallback tree
|
|
const currentGroupLabel =
|
|
!_menuId && isReferencePath(pathname)
|
|
? getMenuGroupLabelByPath({ menu: GLOBAL_MENU_ITEMS, pathname })
|
|
: treeGroupLabel
|
|
// a page without a sidebar opens the drawer on the first group, so the drawer is never empty
|
|
const defaultGroupLabel = hideSideNav
|
|
? GLOBAL_MENU_ITEMS.find(([section]) => section.enabled !== false)?.[0].label
|
|
: currentGroupLabel
|
|
const selectedGroupLabel = pickedGroupLabel ?? defaultGroupLabel
|
|
// a page outside every group keeps its own nav. a fallback tree from another group stays hidden
|
|
const isSideNavShown =
|
|
!currentGroupLabel ||
|
|
(selectedGroupLabel === currentGroupLabel && currentGroupLabel === treeGroupLabel)
|
|
|
|
const handleMenuToggle = () => {
|
|
// the menu opens on the current group again
|
|
if (!mobileMenuOpen) setPickedGroupLabel(undefined)
|
|
menuState.setMenuMobileOpen(!mobileMenuOpen)
|
|
}
|
|
|
|
const menuButtonRef = useRef<HTMLButtonElement>(null)
|
|
const MobileBar = isLayoutV2 ? MobileTopNavBar : LegacyTopNavBar
|
|
|
|
useCloseMenuOnRouteChange()
|
|
|
|
const navigationMenu = (
|
|
<>
|
|
<GlobalMenuDrawerSection
|
|
selectedLabel={selectedGroupLabel}
|
|
currentLabel={currentGroupLabel}
|
|
currentLevel={menuId}
|
|
onGroupPick={setPickedGroupLabel}
|
|
className={cn('lg:hidden', !isSideNavHidden && isSideNavShown && 'mb-6 border-b pb-6')}
|
|
/>
|
|
{isSideNavHidden ? null : (
|
|
<div className={cn('lg:contents', !isSideNavShown && 'max-lg:hidden')}>
|
|
{NavigationMenu ?? (
|
|
<DefaultNavigationMenu menuId={menuId} additionalNavItems={additionalNavItems} />
|
|
)}
|
|
</div>
|
|
)}
|
|
</>
|
|
)
|
|
|
|
return (
|
|
<RightRailProvider value={rightRailTarget}>
|
|
<div className={cn('flex flex-row h-full relative', className)}>
|
|
<SkeletonSideNav
|
|
toggleRef={menuButtonRef}
|
|
menuId={hideSideNav ? undefined : menuId}
|
|
additionalNavItems={additionalNavItems}
|
|
className={cn(hideSideNav && 'lg:hidden layout-v2:lg:flex')}
|
|
>
|
|
{navigationMenu}
|
|
</SkeletonSideNav>
|
|
<Container>
|
|
<div className="sticky top-0 z-20 lg:hidden">
|
|
<MobileBar
|
|
isMenuOpen={mobileMenuOpen}
|
|
onMenuToggle={handleMenuToggle}
|
|
scrolledTitle={mobileMenuOpen ? null : scrolledTitle}
|
|
menuButtonRef={menuButtonRef}
|
|
/>
|
|
<div ref={setTocSlot} className={isLayoutV2 ? undefined : 'md:hidden'} />
|
|
</div>
|
|
<div className="grow">
|
|
<MobileHeaderSlotsContext value={{ tocSlot, onTitleScroll: setScrolledTitle }}>
|
|
{children}
|
|
</MobileHeaderSlotsContext>
|
|
{hideFooter ? null : <SkeletonFooter />}
|
|
</div>
|
|
</Container>
|
|
<SkeletonRightRail hasRightRail={hasRightRail} onTargetChange={setRightRailTarget} />
|
|
</div>
|
|
</RightRailProvider>
|
|
)
|
|
}
|
|
|
|
export { SidebarSkeleton, TopNavSkeleton }
|