mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Context More housekeeping - deprecates the old Table component in favor of the Table component under `ui` JFYI also realised as part of this that the following 2 routes are unreachable from the dashboard and hence am opting to deprecate them with a redirect - /logs/explorer/recent - /logs/explorer/saved ## Areas affected to check - [ ] Integrations -> Webhooks <img width="600" alt="image" src="https://github.com/user-attachments/assets/58523cdb-6219-49be-9d2f-5bc26ae03d7f" /> - [ ] Database -> Column Privileges <img width="600" alt="image" src="https://github.com/user-attachments/assets/98bea654-24ac-4646-9c65-5bc4f18565e9" /> - [ ] Observability -> API <img width="600" alt="image" src="https://github.com/user-attachments/assets/a6512c6f-bd04-4d25-8e3c-99c85883434a" /> - [ ] Observability -> Storage - Its a table under "Request caching" which I don't have data for 😅 🙏 - [ ] Observability -> Database <img width="600" alt="image" src="https://github.com/user-attachments/assets/4f0ba203-64b3-41f7-971e-974e232bdedd" /> - [ ] Table Editor -> Project API Docs -> Column list <img width="600" alt="image" src="https://github.com/user-attachments/assets/6358e7a8-5770-46f9-a5a2-4851855ae97f" /> - [ ] Table Editor -> Project API Docs -> RPC parameters list <img width="600" alt="image" src="https://github.com/user-attachments/assets/5e45a1d6-cd29-451c-bf00-5d806ef37cec" />
153 lines
5.0 KiB
TypeScript
153 lines
5.0 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useEffect } from 'react'
|
|
import { Card, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
|
|
|
|
import LanguageSelector from '../LanguageSelector'
|
|
import { DOCS_RESOURCE_CONTENT } from '../ProjectAPIDocs.constants'
|
|
import ResourceContent from '../ResourceContent'
|
|
import type { ContentProps } from './Content.types'
|
|
import { tempRemovePostgrestText } from './Content.utils'
|
|
import { useProjectJsonSchemaQuery } from '@/data/docs/project-json-schema-query'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
function getColumnType(type: string, format: string) {
|
|
// json and jsonb both have type=undefined, so check format instead
|
|
if (type === undefined && (format === 'jsonb' || format === 'json')) return 'json'
|
|
|
|
switch (type) {
|
|
case 'string':
|
|
return 'string'
|
|
case 'integer':
|
|
return 'number'
|
|
case 'json':
|
|
return 'json'
|
|
case 'number':
|
|
return 'number'
|
|
case 'boolean':
|
|
return 'boolean'
|
|
default:
|
|
return type
|
|
}
|
|
}
|
|
|
|
export const Entity = ({ language, apikey = '', endpoint = '' }: ContentProps) => {
|
|
const { ref } = useParams()
|
|
const snap = useAppStateSnapshot()
|
|
const resource = snap.activeDocsSection[1]
|
|
|
|
const { data: jsonSchema, refetch } = useProjectJsonSchemaQuery({ projectRef: ref })
|
|
|
|
const definition = jsonSchema?.definitions?.[resource]
|
|
const columns =
|
|
definition?.properties !== undefined
|
|
? Object.entries(definition.properties).map(([id, val]: any) => ({
|
|
...val,
|
|
id,
|
|
required: (definition?.required ?? []).includes(id),
|
|
}))
|
|
: []
|
|
|
|
useEffect(() => {
|
|
if (resource !== undefined) refetch()
|
|
}, [resource])
|
|
|
|
if (resource === undefined) return null
|
|
|
|
return (
|
|
<div className="divide-y relative">
|
|
<div className="flex items-center justify-between px-4 py-4 sticky top-0 bg-surface-100 z-10 border-b shadow-md">
|
|
<div className="flex flex-col gap-y-1">
|
|
<h2>{resource}</h2>
|
|
<p className="text-sm text-foreground-light">
|
|
{definition?.description ?? 'No description available'}
|
|
</p>
|
|
</div>
|
|
<LanguageSelector />
|
|
</div>
|
|
<div className="space-y-2 px-4 py-4 border-t-0!">
|
|
<p className="text-sm text-foreground-light">Columns</p>
|
|
<Card>
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead key="name">Name</TableHead>
|
|
<TableHead key="format">Format</TableHead>
|
|
<TableHead key="type">Type</TableHead>
|
|
<TableHead key="description">Description</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{columns.map((column) => {
|
|
const formattedColumnType = getColumnType(column.type, column.format)
|
|
return (
|
|
<TableRow key={column.id}>
|
|
<TableCell title={column.id}>{column.id}</TableCell>
|
|
<TableCell title={column.format}>
|
|
<p className="truncate">{column.format}</p>
|
|
</TableCell>
|
|
<TableCell title={formattedColumnType}>{formattedColumnType}</TableCell>
|
|
<TableCell title={column.description}>
|
|
{tempRemovePostgrestText(column.description ?? '').trim()}
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
})}
|
|
</TableBody>
|
|
</Table>
|
|
</Card>
|
|
</div>
|
|
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.readRows}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.readRows.code({
|
|
resourceId: resource,
|
|
endpoint,
|
|
apikey,
|
|
})}
|
|
/>
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.filtering}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.filtering.code({
|
|
resourceId: resource,
|
|
endpoint,
|
|
apikey,
|
|
})}
|
|
/>
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.insertRows}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.insertRows.code({
|
|
resourceId: resource,
|
|
endpoint,
|
|
apikey,
|
|
})}
|
|
/>
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.updateRows}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.updateRows.code({
|
|
resourceId: resource,
|
|
endpoint,
|
|
apikey,
|
|
})}
|
|
/>
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.deleteRows}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.deleteRows.code({
|
|
resourceId: resource,
|
|
endpoint,
|
|
apikey,
|
|
})}
|
|
/>
|
|
<ResourceContent
|
|
selectedLanguage={language}
|
|
snippet={DOCS_RESOURCE_CONTENT.subscribeChanges}
|
|
codeSnippets={DOCS_RESOURCE_CONTENT.subscribeChanges.code({ resourceId: resource })}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|