mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 08:56:46 -04:00
b91532f6c7
* migrate some www components to tokens * consolidate InteractiveShimmerCard to Panel component * update tokens in blog * update tokens in careers page * update tokens in customers section * update tokens in open-source section * update tokens in Realtime page * update tokens in Storage and Vector * update tokens in SplitCodeBlockCarousel * update tokens in PGCharts * remove unused css files * update tokens in Card * update tokens in Pricing page * clean up priving page imports * remove hardcoded theme vars * migrate first half of defaultTheme.ts to tokens * migrate second half of defaultTheme.ts to tokens * improve inputs * add foreground to text-light and text-lighter * add foreground to text-light and text-lighter * migrate docs components with styling tokens * migrate docs components with styling tokens * fix broken Repos component * fix broken classes in blog * update tokens on Button and other components * update tokens on IconPanel * update studio main layout base styling tokens * update tokens across studio, docs and www * update tokens across studio, docs and www * update ui/Panel to styling tokens * update ExampleProject and TableEditorMenu tokens * www vector page tokens * update studio UI tokens * update other studio UI tokens * update more studio UI tokens * change tokens here, change tokens there * finish updating colors with tokens variables * add gui sandbox for theme experimentation * use common package for www, docs and studio and fix Command K tokens * provide light mode default tokens options * fix conflict leftover * update loading line * fix className typo * fix prettier * update themeSandbox preset default values * fix text-background0 * prettier * update warningBanner with warning color * switch all border-border with border-default * improve border-secondary and foreground-muted in light mode * force ring color on toggle * fix button bg color and border-muted light token * fix input bg color * fix dark button hover * fix homepage product card * fix code-hike table header colors * button dark border * remove tabIndex leftover from homepage main ctas --------- Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
245 lines
10 KiB
TypeScript
245 lines
10 KiB
TypeScript
import ReactMarkdown from 'react-markdown'
|
|
|
|
import { CodeBlock, IconDatabase, Tabs } from 'ui'
|
|
|
|
import Options from '~/components/Options'
|
|
import Param from '~/components/Params'
|
|
import RefSubLayout from '~/layouts/ref/RefSubLayout'
|
|
import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers'
|
|
|
|
import RefDetailCollapse from '~/components/reference/RefDetailCollapse'
|
|
import { Fragment } from 'react'
|
|
import { IRefFunctionSection } from './Reference.types'
|
|
import components from '~/components'
|
|
|
|
const RefFunctionSection: React.FC<IRefFunctionSection> = (props) => {
|
|
const item = props.spec.functions.find((x: any) => x.id === props.funcData.id)
|
|
|
|
// gracefully return nothing if function does not exist
|
|
if (!item) return <></>
|
|
|
|
const hasTsRef = item['$ref'] || null
|
|
|
|
const tsDefinition =
|
|
hasTsRef && props.typeSpec ? extractTsDocNode(hasTsRef, props.typeSpec) : null
|
|
const parameters = hasTsRef && tsDefinition ? generateParameters(tsDefinition) : ''
|
|
const shortText = hasTsRef && tsDefinition ? tsDefinition.signatures[0].comment.shortText : ''
|
|
|
|
return (
|
|
<>
|
|
<RefSubLayout.Section
|
|
key={item.id}
|
|
title={`${props.commonFuncData.title}`}
|
|
id={item.id}
|
|
slug={props.commonFuncData.slug}
|
|
scrollSpyHeader={true}
|
|
>
|
|
<RefSubLayout.Details>
|
|
<>
|
|
<header className={['prose'].join(' ')}>
|
|
{shortText && <ReactMarkdown className="text-sm">{shortText}</ReactMarkdown>}
|
|
</header>
|
|
{item.description && (
|
|
<div className="prose">
|
|
<ReactMarkdown className="text-sm">{item.description}</ReactMarkdown>
|
|
</div>
|
|
)}
|
|
{item.notes && (
|
|
<div className="prose">
|
|
<ReactMarkdown className="text-sm" components={components}>
|
|
{item.notes}
|
|
</ReactMarkdown>
|
|
</div>
|
|
)}
|
|
{/* // parameters */}
|
|
{parameters && (
|
|
<div className="not-prose mt-12">
|
|
<h5 className="mb-3 text-base text-foreground">Parameters</h5>
|
|
<ul className="">
|
|
{parameters.map((param) => {
|
|
// grab override params from yaml file
|
|
const overrideParams = item.overrideParams
|
|
|
|
// params from the yaml file can override the params from parameters if it matches the name
|
|
const overide = overrideParams?.filter((x) => {
|
|
return param.name === x.name
|
|
})
|
|
|
|
const paramItem = overide?.length > 0 ? overide[0] : param
|
|
return (
|
|
<Param {...paramItem} key={param.name}>
|
|
{paramItem.subContent && (
|
|
<div className="mt-3">
|
|
<Options>
|
|
{param.subContent.map((param) => {
|
|
return (
|
|
<Fragment key={param.name + 'subcontent'}>
|
|
<Options.Option {...param}>
|
|
{param.subContent && (
|
|
<Options>
|
|
{param.subContent.map((param) => {
|
|
return (
|
|
<Options.Option
|
|
{...param}
|
|
key={param.name + 'subcontent-option'}
|
|
/>
|
|
)
|
|
})}
|
|
</Options>
|
|
)}
|
|
</Options.Option>
|
|
</Fragment>
|
|
)
|
|
})}
|
|
</Options>
|
|
</div>
|
|
)}
|
|
</Param>
|
|
)
|
|
})}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
</>
|
|
</RefSubLayout.Details>
|
|
<RefSubLayout.Examples>
|
|
{item.examples && (
|
|
<>
|
|
<div className="overflow-hidden w-full">
|
|
<Tabs
|
|
defaultActiveId={item.examples[0].id}
|
|
size="tiny"
|
|
type="rounded-pills"
|
|
scrollable
|
|
queryGroup="example"
|
|
>
|
|
{item.examples &&
|
|
item.examples.map((example, exampleIndex) => {
|
|
const exampleString =
|
|
'' +
|
|
(example.code &&
|
|
example.code
|
|
.trim()
|
|
.replace(/^```.*/, '')
|
|
.replace(/```$/, ''))
|
|
|
|
const codeBlockLang = example?.code?.startsWith('```js')
|
|
? 'js'
|
|
: example?.code?.startsWith('```ts')
|
|
? 'ts'
|
|
: example?.code?.startsWith('```dart')
|
|
? 'dart'
|
|
: example?.code?.startsWith('```c#')
|
|
? 'csharp'
|
|
: example?.code?.startsWith('```kotlin')
|
|
? 'kotlin'
|
|
: 'js'
|
|
// `
|
|
// import { createClient } from '@supabase/supabase-js'
|
|
|
|
// // Create a single supabase client for interacting with your database
|
|
// const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
|
|
// `
|
|
const staticExample = item.examples[exampleIndex]
|
|
|
|
const response = staticExample.response
|
|
const sql = staticExample?.data?.sql
|
|
const tables = staticExample?.data?.tables
|
|
|
|
return (
|
|
<Tabs.Panel
|
|
id={example.id}
|
|
key={example.id}
|
|
label={example.name}
|
|
className="flex flex-col gap-3"
|
|
>
|
|
<CodeBlock
|
|
className="useless-code-block-class"
|
|
language={codeBlockLang}
|
|
hideLineNumbers={true}
|
|
>
|
|
{exampleString}
|
|
</CodeBlock>
|
|
|
|
{((tables && tables.length > 0) || sql) && (
|
|
<RefDetailCollapse
|
|
id={`${example.id}-${exampleIndex}-data`}
|
|
label="Data source"
|
|
defaultOpen={false}
|
|
>
|
|
<>
|
|
{tables &&
|
|
tables.length > 0 &&
|
|
tables.map((table) => {
|
|
return (
|
|
<div className="bg-surface-100 border rounded prose max-w-none">
|
|
<div className="bg-background px-5 py-2">
|
|
<div className="flex gap-2 items-center">
|
|
<div className="text-brand">
|
|
<IconDatabase size={16} />
|
|
</div>
|
|
<h5 className="text-xs text-foreground">
|
|
{table.name}
|
|
</h5>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
})}
|
|
{sql && (
|
|
<CodeBlock
|
|
className="useless-code-block-class my-0 border border-t-0 border-default !rounded-tl-none !rounded-tr-none"
|
|
language="sql"
|
|
hideLineNumbers={true}
|
|
>
|
|
{sql.replace(/sql/g, '').replace(/```/g, '')}
|
|
</CodeBlock>
|
|
)}
|
|
</>
|
|
</RefDetailCollapse>
|
|
)}
|
|
|
|
{response && (
|
|
<RefDetailCollapse
|
|
id={`${example.id}-${exampleIndex}-response`}
|
|
label="Response"
|
|
defaultOpen={false}
|
|
>
|
|
<CodeBlock
|
|
className="useless-code-block-class rounded !rounded-tl-none !rounded-tr-none border border-default"
|
|
language={codeBlockLang}
|
|
hideLineNumbers={true}
|
|
>
|
|
{response.replace(/```/g, '').replace('json', '')}
|
|
</CodeBlock>
|
|
</RefDetailCollapse>
|
|
)}
|
|
|
|
{example.description && (
|
|
<RefDetailCollapse
|
|
id={`${example.id}-${exampleIndex}-notes`}
|
|
label="Notes"
|
|
defaultOpen={false}
|
|
>
|
|
<div className="bg-surface-100 border border-default rounded !rounded-tl-none !rounded-tr-none prose max-w-none px-5 py-2">
|
|
<ReactMarkdown className="text-sm">
|
|
{example.description}
|
|
</ReactMarkdown>
|
|
</div>
|
|
</RefDetailCollapse>
|
|
)}
|
|
</Tabs.Panel>
|
|
)
|
|
})}
|
|
</Tabs>
|
|
</div>
|
|
</>
|
|
)}
|
|
</RefSubLayout.Examples>
|
|
</RefSubLayout.Section>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default RefFunctionSection
|