mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 09:20:21 -04:00
6841db7792
Unknown state is explicitly set before a project is coming up, leading to a bunch of invalid backups list requests
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { databaseKeys } from './keys'
|
|
import type { components } from '@/data/api'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { useIsOrioleDbInAws } from '@/hooks/misc/useSelectedProject'
|
|
import { PROJECT_STATUS } from '@/lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type BackupsVariables = {
|
|
projectRef?: string
|
|
projectStatus?: string
|
|
}
|
|
|
|
export type DatabaseBackup = components['schemas']['BackupsResponse']['backups'][number]
|
|
|
|
export async function getBackups({ projectRef }: BackupsVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/database/{ref}/backups`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type BackupsData = Awaited<ReturnType<typeof getBackups>>
|
|
export type BackupsError = ResponseError
|
|
|
|
export const useBackupsQuery = <TData = BackupsData>(
|
|
{ projectRef, projectStatus }: BackupsVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<BackupsData, BackupsError, TData> = {}
|
|
) => {
|
|
// [Joshen] Check for specifically false to account for project not loaded yet
|
|
const isOrioleDbInAws = useIsOrioleDbInAws()
|
|
|
|
return useQuery<BackupsData, BackupsError, TData>({
|
|
queryKey: databaseKeys.backups(projectRef),
|
|
queryFn: ({ signal }) => getBackups({ projectRef }, signal),
|
|
enabled:
|
|
enabled &&
|
|
!isOrioleDbInAws &&
|
|
typeof projectRef !== 'undefined' &&
|
|
projectStatus !== PROJECT_STATUS.COMING_UP &&
|
|
projectStatus !== PROJECT_STATUS.UNKNOWN,
|
|
...options,
|
|
})
|
|
}
|