mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
* midway * Render, save, and save configuration of SQL blocks * Fix re ordering of blocks not showing save UI * Remove console log * Smol fix * Add queryHeight param to queryBlock * Reinstate telemetry for run query clicked from assistant * Add * Add resizing * Change compactType * Fix switching reports doesnt update * ONly show date picker if theres a chart thats using daily stats or infra monitoring * Fix client crash * Smol update
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'api-types'
|
|
import { get } from 'data/fetchers'
|
|
import type { Dashboards, LogSqlSnippets, SqlSnippets } from 'types'
|
|
import { contentKeys } from './keys'
|
|
|
|
export type ContentBase = components['schemas']['GetUserContentObject']
|
|
|
|
export type Content = Omit<ContentBase, 'content' | 'type'> &
|
|
(
|
|
| {
|
|
type: 'sql'
|
|
content: SqlSnippets.Content
|
|
}
|
|
| {
|
|
type: 'report'
|
|
content: Dashboards.Content
|
|
}
|
|
| {
|
|
type: 'log_sql'
|
|
content: LogSqlSnippets.Content
|
|
}
|
|
)
|
|
|
|
export type ContentType = Content['type']
|
|
|
|
interface GetContentVariables {
|
|
projectRef?: string
|
|
type: ContentType
|
|
name?: string
|
|
}
|
|
|
|
export async function getContent(
|
|
{ projectRef, type, name }: GetContentVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (typeof projectRef === 'undefined') {
|
|
throw new Error('projectRef is required for getContent')
|
|
}
|
|
|
|
const { data, error } = await get('/platform/projects/{ref}/content', {
|
|
params: { path: { ref: projectRef }, query: { type, name } },
|
|
signal,
|
|
})
|
|
|
|
if (error) {
|
|
throw error
|
|
}
|
|
|
|
return {
|
|
cursor: data.cursor,
|
|
content: data.data as unknown as Content[],
|
|
}
|
|
}
|
|
|
|
export type ContentData = Awaited<ReturnType<typeof getContent>>
|
|
export type ContentError = unknown
|
|
|
|
export const useContentQuery = <TData = ContentData>(
|
|
{ projectRef, type, name }: GetContentVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<ContentData, ContentError, TData> = {}
|
|
) =>
|
|
useQuery<ContentData, ContentError, TData>(
|
|
contentKeys.list(projectRef, { type, name }),
|
|
({ signal }) => getContent({ projectRef, type, name }, signal),
|
|
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
|
|
)
|