Files
supabase/apps/studio/data/replication/pipelines-query.ts
Alaister YoungandJoshen Lim 8855d05803 chore(studio): swap react-query to object syntax (#39842)
* chore(studio): swap react-query to object syntax

* Fix small issues found

* Fix realtime settings

* Nit

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-10-27 09:38:27 +01:00

42 lines
1.3 KiB
TypeScript

import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
import { replicationKeys } from './keys'
type ReplicationPipelinesParams = { projectRef?: string }
async function fetchReplicationPipelines(
{ projectRef }: ReplicationPipelinesParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/platform/replication/{ref}/pipelines', {
params: { path: { ref: projectRef } },
signal,
})
if (error) {
handleError(error)
}
return data
}
export type ReplicationPipelinesData = Awaited<ReturnType<typeof fetchReplicationPipelines>>
export type Pipeline = ReplicationPipelinesData['pipelines'][0]
export const useReplicationPipelinesQuery = <TData = ReplicationPipelinesData>(
{ projectRef }: ReplicationPipelinesParams,
{
enabled = true,
...options
}: UseQueryOptions<ReplicationPipelinesData, ResponseError, TData> = {}
) =>
useQuery<ReplicationPipelinesData, ResponseError, TData>({
queryKey: replicationKeys.pipelines(projectRef),
queryFn: ({ signal }) => fetchReplicationPipelines({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})