mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
* Add IS_PLATFORM checks for some unnecessary queries and UI for local * Revert changes for analytics/endpoint/[name] * Smol * Smol --------- Co-authored-by: Terry Sutton <saltcod@gmail.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import { analyticsKeys } from './keys'
|
|
|
|
type WarehouseCollectionsVariables = {
|
|
projectRef: string
|
|
}
|
|
|
|
export async function getWarehouseCollections(
|
|
{ projectRef }: WarehouseCollectionsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) {
|
|
throw new Error('projectRef is required')
|
|
}
|
|
|
|
// TODO: Remove type cast when codegen types are fixed
|
|
const { data, error } = await get(`/platform/projects/{ref}/analytics/warehouse/collections`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
export type WarehouseCollectionsData = Awaited<ReturnType<typeof getWarehouseCollections>>
|
|
|
|
export const useWarehouseCollectionsQuery = (
|
|
{ projectRef }: WarehouseCollectionsVariables,
|
|
{ enabled }: { enabled: boolean } = { enabled: true }
|
|
) =>
|
|
useQuery(
|
|
analyticsKeys.warehouseCollections(projectRef),
|
|
({ signal }) => getWarehouseCollections({ projectRef }, signal),
|
|
{
|
|
enabled: enabled && !!projectRef && IS_PLATFORM,
|
|
}
|
|
)
|