import { useParams } from 'common' import Link from 'next/link' import { Fragment } from 'react' import SVG from 'react-inlinesvg' 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 { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled' import { BASE_PATH, DOCS_URL } from 'lib/constants' import { Book, BookOpen } from 'lucide-react' import { useAppStateSnapshot } from 'state/app-state' import { Button } from 'ui' import { navigateToSection } from './Content/Content.utils' import { DOCS_CONTENT, DOCS_MENU } from './ProjectAPIDocs.constants' const Separator = () =>
const FirstLevelNav = () => { const { ref } = useParams() const snap = useAppStateSnapshot() const { projectAuthAll: authEnabled, projectStorageAll: storageEnabled, projectEdgeFunctionAll: edgeFunctionsEnabled, realtimeAll: realtimeEnabled, } = useIsFeatureEnabled([ 'project_auth:all', 'project_storage:all', 'project_edge_function:all', 'realtime:all', ]) const docsMenu = DOCS_MENU.filter((item) => { if (item.key === 'user-management') return authEnabled if (item.key === 'storage') return storageEnabled if (item.key === 'edge-functions') return edgeFunctionsEnabled if (item.key === 'realtime') return realtimeEnabled return true }) const { data } = useOpenAPISpecQuery({ projectRef: ref }) const tables = data?.tables ?? [] const functions = data?.functions ?? [] const { data: buckets } = useBucketsQuery({ projectRef: ref }) const { data: edgeFunctions } = useEdgeFunctionsQuery({ projectRef: ref }) return ( <>{ snap.setActiveDocsSection([item.key]) navigateToSection(section.key) }} > {section.title}
))} {item.key === 'entities' && ( <> {tables.length > 0 &&snap.setActiveDocsSection([item.key, table.name])} > {table.name}
))} > )} {item.key === 'stored-procedures' && ( <> {functions.length > 0 &&snap.setActiveDocsSection([item.key, fn.name])} > {fn.name}
))} > )} {item.key === 'storage' && ( <> {(buckets ?? []).length > 0 &&snap.setActiveDocsSection([item.key, bucket.name])} > {bucket.name}
))} > )} {item.key === 'edge-functions' && ( <> {(edgeFunctions ?? []).length > 0 &&snap.setActiveDocsSection([item.key, fn.name])} > {fn.name}
))} > )}