mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
* Swap analytics buckets endpoint * Fix type issues * fix * Update API types * Fix tests * nit * Final fixes * Fix * chore(studio): analytics buckets contents (#39701) * first commit * improvements * misc * cleanup * remove tappable whole * design updates * analytics improvements * polish * add clashed case * fix pairing status * connect tables basics * add multiselect * restore prod version for non-feature preview users * fix padding inconsistency * terminology fix * better empty state * fix terminology * block table connection dialog button * Nit refactors * minor nits * Add comment --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> * Default circumstance to fresh in ImportForeignSchemaDialog * Hook up connecting tables for analytics buckets (#39906) * Hook up connecting tables for analytics buckets * Address comments * Clean up iceberg wrapper when deleting analytics bucket (#39902) * Clean up iceberg wrapper when deleting analytics bucket * Clean up s3 access key when deleting analytics bucket * Make connect table disabled for now * Most clean up and refactoring * Refactor RQ * Nit * Refactor * nit --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'api-types'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { PROJECT_STATUS } from 'lib/constants'
|
|
import type { ResponseError } from 'types'
|
|
import { storageKeys } from './keys'
|
|
|
|
export type BucketsVariables = { projectRef?: string }
|
|
|
|
export type Bucket = components['schemas']['StorageBucketResponse']
|
|
|
|
export type BucketType = Bucket['type']
|
|
|
|
export async function getBuckets({ projectRef }: BucketsVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get('/platform/storage/{ref}/buckets', {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as Bucket[]
|
|
}
|
|
|
|
export type BucketsData = Awaited<ReturnType<typeof getBuckets>>
|
|
export type BucketsError = ResponseError
|
|
|
|
export const useBucketsQuery = <TData = BucketsData>(
|
|
{ projectRef }: BucketsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<BucketsData, BucketsError, TData> = {}
|
|
) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const isActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHY
|
|
|
|
return useQuery<BucketsData, BucketsError, TData>({
|
|
queryKey: storageKeys.buckets(projectRef),
|
|
queryFn: ({ signal }) => getBuckets({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && isActive,
|
|
...options,
|
|
retry: (failureCount, error) => {
|
|
if (
|
|
typeof error === 'object' &&
|
|
error !== null &&
|
|
error.message.includes('Missing tenant config')
|
|
) {
|
|
return false
|
|
}
|
|
|
|
if (failureCount < 3) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
},
|
|
})
|
|
}
|