Files
supabase/apps/studio/data/analytics/warehouse-collections-query.ts
Joshen LimandTerry Sutton 8b4fb55b54 Add IS_PLATFORM checks for some unnecessary queries and UI for local (#33557)
* 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>
2025-02-17 15:09:36 +08:00

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,
}
)