import { useParams } from 'common' import { useState } from 'react' import { DocsButton } from 'components/ui/DocsButton' import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query' import { useOpenAPISpecQuery } from 'data/open-api/api-spec-query' import { useBucketsQuery } from 'data/storage/buckets-query' import { DOCS_URL } from 'lib/constants' import { ChevronLeft, Code } from 'lucide-react' import { useAppStateSnapshot } from 'state/app-state' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, CommandGroup_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, Command_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, } from 'ui' import { useIsAPIDocsSidePanelEnabled } from '../App/FeaturePreview/FeaturePreviewContext' import { navigateToSection } from './Content/Content.utils' import { DOCS_RESOURCE_CONTENT } from './ProjectAPIDocs.constants' const SecondLevelNav = () => { const { ref } = useParams() const snap = useAppStateSnapshot() const [open, setOpen] = useState(false) const isNewAPIDocsEnabled = useIsAPIDocsSidePanelEnabled() const { data } = useOpenAPISpecQuery({ projectRef: ref }) const tables = data?.tables ?? [] const functions = data?.functions ?? [] const [section, resource] = snap.activeDocsSection const { data: buckets } = useBucketsQuery({ projectRef: ref }) const { data: edgeFunctions } = useEdgeFunctionsQuery({ projectRef: ref }) const bucket = (buckets ?? []).find((b) => b.name === resource) const content: { [key: string]: { title: string; options: any[]; docsUrl: string } } = { entities: { title: 'Tables & Views', options: tables, docsUrl: `${DOCS_URL}/reference/javascript/select`, }, 'stored-procedures': { title: 'Stored Procedures', options: functions, docsUrl: `${DOCS_URL}/reference/javascript/rpc`, }, storage: { title: 'Storage', options: buckets ?? [], docsUrl: `${DOCS_URL}/reference/javascript/storage-createbucket`, }, 'edge-functions': { title: 'Edge Functions', options: edgeFunctions ?? [], docsUrl: `${DOCS_URL}/reference/javascript/functions-invoke`, }, } const updateSection = (value: string) => { snap.setActiveDocsSection([snap.activeDocsSection[0], value]) setOpen(false) } const menuItems = Object.values(DOCS_RESOURCE_CONTENT).filter( (content) => content.category === snap.activeDocsSection[0] ) return (
{content[section].title}
{option.name}
navigateToSection(item.key)} > {item.title}
) })}Unable to find what you're looking for?
The API methods shown here are only the commonly used ones to get you started building quickly.
Head over to our docs site for the full API documentation.