Files
supabase/apps/studio/data/replication/publications-query.ts
Joshen LimandDanny White 0910908561 Swap analytics buckets endpoint (#39610)
* 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>
2025-10-29 19:10:10 +08:00

50 lines
1.7 KiB
TypeScript

import { UseQueryOptions, useQuery } from '@tanstack/react-query'
import { components } from 'api-types'
import { get, handleError } from 'data/fetchers'
import { ResponseError } from 'types'
import { replicationKeys } from './keys'
type ReplicationPublicationsParams = { projectRef?: string; sourceId?: number }
export type ReplicationPublication =
components['schemas']['ReplicationPublicationsResponse']['publications'][number]
async function fetchReplicationPublications(
{ projectRef, sourceId }: ReplicationPublicationsParams,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
if (!sourceId) throw new Error('sourceId is required')
const { data, error } = await get(
'/platform/replication/{ref}/sources/{source_id}/publications',
{
params: { path: { ref: projectRef, source_id: sourceId } },
signal,
}
)
if (error) {
handleError(error)
}
return data.publications.filter((pub) => pub.name !== 'supabase_realtime')
}
export type ReplicationPublicationsData = Awaited<ReturnType<typeof fetchReplicationPublications>>
export const useReplicationPublicationsQuery = <TData = ReplicationPublicationsData>(
{ projectRef, sourceId }: ReplicationPublicationsParams,
{
enabled = true,
...options
}: UseQueryOptions<ReplicationPublicationsData, ResponseError, TData> = {}
) =>
useQuery<ReplicationPublicationsData, ResponseError, TData>({
queryKey: replicationKeys.publications(projectRef, sourceId),
queryFn: ({ signal }) => fetchReplicationPublications({ projectRef, sourceId }, signal),
enabled: enabled && typeof projectRef !== 'undefined' && typeof sourceId !== 'undefined',
...options,
})