Files
supabase/apps/studio/components/interfaces/Docs/RpcContent.tsx
Charis f7bf7d7ce4 feat(studio): move data api docs to integrations section (#42749)
Feature / Refactor

## What is the current behavior?

Data API docs live at the `/api` route as a standalone page. Old links
point to the previous location.

## What is the new behavior?

Data API docs are moved to the integrations section with a dedicated
docs tab and settings tab. Old links are cleaned up, a mobile menu is
added for data API docs navigation, and minor code review fixes are
applied.

## Additional context

Resolves FE-2517

## Summary by CodeRabbit

* **New Features**
* Revamped API docs UI with reusable section layout, language toggle
(JS/Bash), API key selection, and improved code snippets
* Added Data API docs tab, mobile navigation, and dedicated
loading/error/disabled states

* **Navigation Updates**
* Moved API docs and related links into the Integrations/Data API area
and added redirects to new routes
* Updated various internal links to the new Data API settings and
overview locations

* **Tests**
  * Added comprehensive unit tests for Data API utilities
2026-02-12 15:57:44 -05:00

107 lines
3.1 KiB
TypeScript

import { useParams } from 'common'
import { DocSection } from './DocSection'
import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'
import Description from '@/components/interfaces/Docs/Description'
import Param from '@/components/interfaces/Docs/Param'
import Snippets from '@/components/interfaces/Docs/Snippets'
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
import { ProjectJsonSchemaPaths } from '@/data/docs/project-json-schema-query'
/**
* TODO: need to support rpc with the same name and different params type
*/
interface RpcContentProps {
rpcId: string
rpcs: { [key: string]: any }
paths?: ProjectJsonSchemaPaths
selectedLang: 'bash' | 'js'
showApiKey: string
refreshDocs: () => void
}
export const RpcContent = ({
rpcId,
rpcs,
paths,
selectedLang,
showApiKey,
refreshDocs,
}: RpcContentProps) => {
const { ref: projectRef } = useParams()
const { data: settings } = useProjectSettingsV2Query({ projectRef })
const protocol = settings?.app_config?.protocol ?? 'https'
const hostEndpoint = settings?.app_config?.endpoint ?? ''
const endpoint = `${protocol}://${hostEndpoint ?? ''}`
const meta = rpcs[rpcId]
const pathKey = `/rpc/${rpcId}`
const path = paths && pathKey in paths ? paths[pathKey] : undefined
const keyToShow = !!showApiKey ? showApiKey : 'SUPABASE_KEY'
const { parameters, summary } = path?.post || {}
const rpcParamsObject =
parameters && parameters[0] && parameters[0].schema && (parameters[0].schema as any).properties
? (parameters[0].schema as any).properties
: {}
const rpcParams = Object.entries(rpcParamsObject)
.map(([k, v]: any) => ({ name: k, ...v }))
.filter((x) => !!x.name)
if (!path) return null
return (
<div className="flex flex-col flex-1">
<DocSection
title={meta.id}
content={
<>
<label className="font-mono text-xs uppercase text-foreground-lighter inline-block mb-2">
Description
</label>
<Description content={summary ?? ''} metadata={{ rpc: rpcId }} onChange={refreshDocs} />
</>
}
snippets={
<CodeSnippet
selectedLang={selectedLang}
snippet={Snippets.rpcSingle({
rpcName: rpcId,
// @ts-ignore
rpcCamelCase: meta.camelCase,
rpcParams: rpcParams,
apiKey: keyToShow,
endpoint: endpoint,
})}
/>
}
/>
{rpcParams.length > 0 && (
<div className="flex flex-col flex-1">
<DocSection title="Function Arguments" content={null} />
{rpcParams.map((x, i) => {
return (
<DocSection
key={i}
title={null}
content={
<Param
key={x.name}
name={x.name}
type={x.type}
format={x.format}
required={true}
description={false}
/>
}
/>
)
})}
</div>
)}
</div>
)
}