import { useParams } from 'common' import { useEffect } from 'react' 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 Table from '@/components/to-be-cleaned/Table' 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 (

{resource}

{definition?.description ?? 'No description available'}

Columns

Name, Format, Type, Description, ]} body={columns.map((column) => { const formattedColumnType = getColumnType(column.type, column.format) return ( {column.id}

{column.format}

{formattedColumnType} {tempRemovePostgrestText(column.description ?? '').trim()}
) })} /> ) }