import { useQuery } from '@tanstack/react-query' import { useParams } from 'common' import { useState } from 'react' import { SidePanel } from 'ui' import { Bucket } from './Content/Bucket' import { EdgeFunction } from './Content/EdgeFunction' import { EdgeFunctions } from './Content/EdgeFunctions' import { Entities } from './Content/Entities' import { Entity } from './Content/Entity' import { Introduction } from './Content/Introduction' import { Realtime } from './Content/Realtime' import { RPC } from './Content/RPC' import { Storage } from './Content/Storage' import { StoredProcedures } from './Content/StoredProcedures' import { UserManagement } from './Content/UserManagement' import { FirstLevelNav } from './FirstLevelNav' import LanguageSelector from './LanguageSelector' import { SecondLevelNav } from './SecondLevelNav' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { apiKeysQueryOptions, getKeys } from '@/data/api-keys/api-keys-query' import { useProjectApiUrl } from '@/data/config/project-endpoint-query' import { useGrant } from '@/lib/grants' import { useAppStateSnapshot } from '@/state/app-state' const getShowKeysTooltip = (status: 'loading' | 'granted' | 'denied' | 'error') => { if (status === 'denied') return 'You need additional permissions to view API keys' if (status === 'error') return 'Failed to check API key permissions' return undefined } /** * [Joshen] Reminder: when we choose to release this as a main feature * Ensure that UX is better than the existing, and make sure we do the * necessary communications around releasing this. * * Problems: * - Needs URL support * - Language selector is not clear, users are missing the bash language option * - GraphiQL needs a better home, cannot be placed under Database as its "API" */ export const ProjectAPIDocs = () => { const { ref } = useParams() const snap = useAppStateSnapshot() const isIntroduction = snap.activeDocsSection.length === 1 && snap.activeDocsSection[0] === 'introduction' const isEntityDocs = snap.activeDocsSection.length === 2 && snap.activeDocsSection[0] === 'entities' const [showKeys, setShowKeys] = useState(false) const language = snap.docsLanguage const apiKeysGrant = useGrant('GET /v1/projects/{ref}/api-keys', { projectRef: ref }) const { data: apiKeysData } = useQuery( apiKeysQueryOptions( { projectRef: ref, grant: apiKeysGrant.grant }, { enabled: snap.showProjectApiDocs, select: getKeys } ) ) const canShowKeys = apiKeysGrant.status === 'granted' const showKeysTooltip = getShowKeysTooltip(apiKeysGrant.status) const { anonKey } = apiKeysData ?? {} const { data: endpoint } = useProjectApiUrl( { projectRef: ref }, { enabled: snap.showProjectApiDocs } ) const apikey = showKeys ? (anonKey?.api_key ?? 'SUPABASE_CLIENT_ANON_KEY') : 'SUPABASE_CLIENT_ANON_KEY' return ( snap.setShowProjectApiDocs(false)} >

API Docs

{!isEntityDocs && } {isIntroduction && ( setShowKeys(!showKeys)} tooltip={{ content: { side: 'bottom', text: showKeysTooltip } }} > {showKeys ? 'Hide keys' : 'Show keys'} )}
{snap.activeDocsSection.length === 1 ? : }
{snap.activeDocsSection[0] === 'introduction' && ( )} {snap.activeDocsSection[0] === 'user-management' && ( )} {snap.activeDocsSection[0] === 'realtime' && } {snap.activeDocsSection[0] === 'storage' && ( <> {snap.activeDocsSection[1] !== undefined ? ( ) : ( )} )} {snap.activeDocsSection[0] === 'edge-functions' && ( <> {snap.activeDocsSection[1] !== undefined ? ( ) : ( )} )} {snap.activeDocsSection[0] === 'entities' && ( <> {snap.activeDocsSection[1] !== undefined ? ( ) : ( )} )} {snap.activeDocsSection[0] === 'stored-procedures' && ( <> {snap.activeDocsSection[1] !== undefined ? ( ) : ( )} )}
) }