Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): enable Pipelines before opening creation (#51311)

Danny White6c829b32daf3
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx
new file mode 100644
index 00000000000..6bb01ac3a2c
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx
@@ -0,0 +1,238 @@
+import { QueryClient } from '@tanstack/react-query'
+import { fireEvent, screen, waitFor } from '@testing-library/react'
+import type { components } from 'api-types'
+import { mockAnimationsApi } from 'jsdom-testing-mocks'
+import { http, HttpResponse } from 'msw'
+import { useQueryState } from 'nuqs'
+import { beforeEach, expect, test, vi } from 'vitest'
+
+import { Destinations } from './Destinations'
+import { replicationKeys } from '@/data/replication/keys'
+import { customRender } from '@/tests/lib/custom-render'
+import { addAPIMock, mswServer, type APIErrorBody } from '@/tests/lib/msw'
+
+mockAnimationsApi()
+const options = vi.hoisted(() => ({
+ legacy: false,
+ hasAccess: true,
+ isLoading: false,
+ failEnable: false,
+ failRefresh: false,
+}))
+vi.mock('./useIsETLPrivateAlpha', () => ({
+ useIsETLBigQueryPrivateAlpha: () => !options.legacy,
+ useIsETLIcebergPrivateAlpha: () => options.legacy,
+ useIsETLDucklakePrivateAlpha: () => false,
+ useIsETLSnowflakePrivateAlpha: () => false,
+ useIsETLClickHousePrivateAlpha: () => false,
+}))
+vi.mock('@/hooks/misc/useCheckEntitlements', () => ({
+ useCheckEntitlements: () => ({ hasAccess: options.hasAccess, isLoading: options.isLoading }),
+}))
+vi.mock('./DestinationPanel/DestinationPanel', () => ({
+ DestinationPanel: () => {
+ const [type] = useQueryState('destinationType')
+ return type ? <h2>Creation sheet: {type}</h2> : null
+ },
+}))
+let isEnabled = false
+let enableGate: Promise<void> | undefined
+beforeEach(() => {
+ isEnabled = false
+ enableGate = undefined
+ options.legacy = false
+ options.hasAccess = true
+ options.isLoading = false
+ options.failRefresh = false
+ options.failEnable = false
+ mswServer.use(
+ http.get('http://localhost:3000/api/enabled-features-overrides', () =>
+ HttpResponse.json<{ disabled_features: string[] }>({ disabled_features: [] })
+ )
+ )
+ addAPIMock({
+ method: 'get',
+ path: '/platform/projects/:ref',
+ response: () => HttpResponse.json<APIErrorBody>({ message: 'Unavailable' }, { status: 404 }),
+ })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/destinations',
+ response: () =>
+ HttpResponse.json<components['schemas']['DestinationsResponse_Output']>({ destinations: [] }),
+ })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/pipelines',
+ response: () =>
+ HttpResponse.json<components['schemas']['PipelinesResponse_Output']>({ pipelines: [] }),
+ })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: () =>
+ options.failRefresh && isEnabled
+ ? HttpResponse.json<APIErrorBody>(
+ { message: 'replication API URL is not configured' },
+ { status: 503 }
+ )
+ : HttpResponse.json<components['schemas']['SourcesResponse_Output']>({
+ sources: isEnabled
+ ? [
+ {
+ id: 42,
+ name: 'default',
+ tenant_id: 'tenant',
+ config: {
+ host: 'localhost',
+ port: 5432,
+ name: 'postgres',
+ username: 'postgres',
+ },
+ },
+ ]
+ : [],
+ }),
+ })
+ addAPIMock({
+ method: 'post',
+ path: '/platform/replication/:ref/tenants-sources',
+ response: async () => {
+ await enableGate
+ if (options.failEnable) {
+ options.failEnable = false
+ return HttpResponse.json<APIErrorBody>({ message: 'Unavailable' }, { status: 503 })
+ }
+ isEnabled = true
+ return HttpResponse.json<components['schemas']['CreateTenantSourceResponse_Output']>({
+ source_id: 42,
+ tenant_id: 'tenant',
+ })
+ },
+ })
+})
+const renderList = async (waitForSources = true) => {
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ const view = customRender(<Destinations />, { queryClient, nuqs: { hasMemory: true } })
+ await screen.findByRole('heading', { name: 'Add a pipeline' })
+ if (waitForSources)
+ await waitFor(() =>
+ expect(queryClient.getQueryState(replicationKeys.sources('default'))?.status).toBe('success')
+ )
+ return view
+}
+const addPipeline = () =>
+ fireEvent.click(screen.getAllByRole('button', { name: 'Add pipeline' })[0])
+test.each([true, false, 'retry', 'refresh error'])(
+ 'opens creation after enabling when needed (enabled: %s)',
+ async (enabled) => {
+ isEnabled = enabled === true
+ options.failEnable = enabled === 'retry'
+ const view = await renderList()
+ options.failRefresh = enabled === 'refresh error'
+ options.isLoading = enabled !== true
+ options.hasAccess = !options.isLoading
+ addPipeline()
+ if (enabled !== true) {
+ expect(screen.getByText('Checking Pipelines access…')).toBeInTheDocument()
+ expect(screen.queryByText('Pipelines requires the Pro plan.')).not.toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Enable' })).toBeDisabled()
+ options.isLoading = false
+ options.hasAccess = true
+ view.rerender(<Destinations />)
+ fireEvent.click(screen.getByRole('button', { name: 'Enable' }))
+ if (enabled === 'retry') {
+ await waitFor(() => expect(options.failEnable).toBe(false))
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Enable' })).toBeEnabled())
+ expect(screen.queryByRole('heading', { name: /Creation sheet/ })).not.toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Enable' }))
+ }
+ }
+ if (enabled === 'refresh error') {
+ await screen.findByRole('button', { name: 'Retry' })
+ expect(screen.queryByRole('heading', { name: /Creation sheet/ })).not.toBeInTheDocument()
+ options.failRefresh = false
+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }))
+ await waitFor(() =>
+ expect(screen.getAllByRole('button', { name: 'Add pipeline' })[0]).not.toHaveAttribute(
+ 'aria-disabled',
+ 'true'
+ )
+ )
+ addPipeline()
+ }
+ await screen.findByRole('heading', { name: 'Creation sheet: BigQuery' })
+ }
+)
+test('dismissal during enablement prevents a late response opening creation', async () => {
+ let finish: (() => void) | undefined
+ enableGate = new Promise<void>((resolve) => {
+ finish = resolve
+ })
+ await renderList()
+ addPipeline()
+ fireEvent.click(await screen.findByRole('button', { name: 'Enable' }))
+ fireEvent.keyDown(screen.getByRole('dialog'), { key: 'Escape' })
+ await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
+ finish?.()
+ fireEvent.pointerDown(screen.getByRole('button', { name: 'More actions' }), {
+ button: 0,
+ ctrlKey: false,
+ })
+ expect(await screen.findByRole('menuitem', { name: 'Disable Pipelines' })).toBeInTheDocument()
+ expect(screen.queryByRole('heading', { name: /Creation sheet/ })).not.toBeInTheDocument()
+})
+test('creation defaults to BigQuery regardless of legacy destination flags', async () => {
+ options.legacy = true
+ isEnabled = true
+ await renderList()
+ addPipeline()
+ await screen.findByRole('heading', { name: 'Creation sheet: BigQuery' })
+})
+test.each(['loading', 'error'])('blocks creation when source status is %s', async (state) => {
+ let finish: (() => void) | undefined
+ let hasFailed = false
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: async () => {
+ if (state === 'loading')
+ await new Promise<void>((resolve) => {
+ finish = resolve
+ })
+ if (state === 'error' && !hasFailed) {
+ hasFailed = true
+ return HttpResponse.json<APIErrorBody>(
+ { message: 'replication API URL is not configured' },
+ { status: 503 }
+ )
+ }
+ return HttpResponse.json<components['schemas']['SourcesResponse_Output']>({ sources: [] })
+ },
+ })
+ await renderList(false)
+ if (state === 'error') {
+ await screen.findByRole('button', { name: 'Retry' })
+ const button = screen.getAllByRole('button', { name: 'Add pipeline' })[0]
+ expect(button).toHaveAttribute('aria-disabled', 'true')
+ fireEvent.focus(button)
+ expect(await screen.findByRole('tooltip')).toHaveTextContent('Replication unavailable locally')
+ } else {
+ expect(screen.getAllByRole('button', { name: 'Add pipeline' })[0]).toBeDisabled()
+ expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
+ }
+ addPipeline()
+ fireEvent.keyDown(document, { key: 'N', shiftKey: true })
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
+ expect(screen.queryByRole('heading', { name: /Creation sheet/ })).not.toBeInTheDocument()
+ if (state === 'error') fireEvent.click(await screen.findByRole('button', { name: 'Retry' }))
+ else {
+ await waitFor(() => expect(finish).toBeDefined())
+ finish?.()
+ }
+ await waitFor(() =>
+ expect(screen.getAllByRole('button', { name: 'Add pipeline' })[0]).toBeEnabled()
+ )
+ addPipeline()
+ expect(await screen.findByRole('dialog')).toHaveTextContent('Enable Pipelines')
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index 2e21f98ddc3..22038b3d706 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -31,15 +31,9 @@ import { DisablePipelinesDialog } from './DisablePipelinesDialog'
import { EnablePipelinesModal } from './EnablePipelinesCallout'
import { getStatusName } from './Pipeline.utils'
import { PipelineStatusName } from './Replication.constants'
-import {
- useIsETLBigQueryPrivateAlpha,
- useIsETLClickHousePrivateAlpha,
- useIsETLDucklakePrivateAlpha,
- useIsETLIcebergPrivateAlpha,
- useIsETLSnowflakePrivateAlpha,
-} from './useIsETLPrivateAlpha'
import { useRedirectLegacyReadReplicaDestination } from './useRedirectLegacyReadReplicaDestination'
import { AlertError } from '@/components/ui/AlertError'
+import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { Shortcut } from '@/components/ui/Shortcut'
import { TableRowNoResults } from '@/components/ui/TableRowNoResults'
import { useReplicationDestinationsQuery } from '@/data/replication/destinations-query'
@@ -100,28 +94,11 @@ export const Destinations = () => {
useRedirectLegacyReadReplicaDestination()
- const etlEnableBigQuery = useIsETLBigQueryPrivateAlpha()
- const etlEnableIceberg = useIsETLIcebergPrivateAlpha()
- const etlEnableDucklake = useIsETLDucklakePrivateAlpha()
- const etlEnableSnowflake = useIsETLSnowflakePrivateAlpha()
- const etlEnableClickHouse = useIsETLClickHousePrivateAlpha()
-
- const newDestinationDefaultType: DestinationType | null = etlEnableBigQuery
- ? 'BigQuery'
- : etlEnableIceberg
- ? 'Analytics Bucket'
- : etlEnableDucklake
- ? 'DuckLake'
- : etlEnableSnowflake
- ? 'Snowflake'
- : etlEnableClickHouse
- ? 'ClickHouse'
- : null
-
const prefetchedRef = useRef(false)
const searchInputRef = useRef<HTMLInputElement>(null)
const [filterString, setFilterString] = useState<string>('')
const [showEnablePipelinesDialog, setShowEnablePipelinesDialog] = useState(false)
+ const pendingCreationTypeRef = useRef<DestinationType | null>(null)
const [showDisablePipelinesDialog, setShowDisablePipelinesDialog] = useState(false)
const [, setDestinationType] = useQueryState(
@@ -210,7 +187,13 @@ export const Destinations = () => {
return sortDirection === 'asc' ? comparison : -comparison
})
- const { data: sourcesData, isSuccess: isSourcesSuccess } = useReplicationSourcesQuery({
+ const {
+ data: sourcesData,
+ isSuccess: isSourcesSuccess,
+ isError: isSourcesError,
+ error: sourcesError,
+ refetch: refetchSources,
+ } = useReplicationSourcesQuery({
projectRef,
})
const externalReplicationSource = useMemo(
@@ -230,9 +213,36 @@ export const Destinations = () => {
const isLocalETLNotSetUp = checkLocalETLNotSetUp(destinationsError)
const hasErrorsFetchingData = !isLocalETLNotSetUp && isDestinationsError
+ const canCreate = isSourcesSuccess
+ const isCheckingPipelineStatus = !isSourcesSuccess && !isSourcesError
+ const sourceErrorTitle = checkLocalETLNotSetUp(sourcesError)
+ ? 'Replication unavailable locally'
+ : 'Failed to retrieve pipeline enablement status'
+
const openDestinationPanel = () => {
- if (!newDestinationDefaultType) return
- setDestinationType(newDestinationDefaultType)
+ if (!canCreate) return
+ if (replicationNotEnabled) {
+ pendingCreationTypeRef.current = 'BigQuery'
+ setShowEnablePipelinesDialog(true)
+ return
+ }
+ setDestinationType('BigQuery')
+ }
+
+ const handleEnableDialogOpenChange = (open: boolean) => {
+ setShowEnablePipelinesDialog(open)
+ if (!open) pendingCreationTypeRef.current = null
+ }
+
+ const handlePipelinesEnabled = () => {
+ const type = pendingCreationTypeRef.current
+ pendingCreationTypeRef.current = null
+ if (
+ type &&
+ queryClient.getQueryState(replicationKeys.sources(projectRef))?.status === 'success'
+ ) {
+ setDestinationType(type)
+ }
}
useShortcut(
@@ -311,7 +321,12 @@ export const Destinations = () => {
</DropdownMenuItem>
<DropdownMenuSeparator />
{replicationNotEnabled ? (
- <DropdownMenuItem onClick={() => setShowEnablePipelinesDialog(true)}>
+ <DropdownMenuItem
+ onClick={() => {
+ pendingCreationTypeRef.current = null
+ setShowEnablePipelinesDialog(true)
+ }}
+ >
Enable Pipelines
</DropdownMenuItem>
) : (
@@ -338,17 +353,22 @@ export const Destinations = () => {
id={SHORTCUT_IDS.LIST_PAGE_NEW_ITEM}
label="Add pipeline"
onTrigger={openDestinationPanel}
- options={{ enabled: !!newDestinationDefaultType }}
+ options={{ enabled: canCreate }}
side="bottom"
+ tooltipOpen={canCreate ? undefined : false}
>
- <Button
+ <ButtonTooltip
+ tooltip={{
+ content: { text: isSourcesError && !canCreate ? sourceErrorTitle : undefined },
+ }}
variant="primary"
icon={<Plus />}
- disabled={!newDestinationDefaultType}
+ loading={isCheckingPipelineStatus}
+ disabled={!canCreate}
onClick={openDestinationPanel}
>
Add pipeline
- </Button>
+ </ButtonTooltip>
</Shortcut>
</div>
</div>
@@ -359,6 +379,20 @@ export const Destinations = () => {
{isDestinationsLoading ? 'Loading pipelines' : ''}
</p>
+ {isSourcesError && (
+ <AlertError
+ projectRef={projectRef}
+ error={sourcesError}
+ subject={sourceErrorTitle}
+ description={
+ checkLocalETLNotSetUp(sourcesError)
+ ? 'Configure the replication API to manage pipelines in local development.'
+ : undefined
+ }
+ additionalActions={<Button onClick={() => refetchSources()}>Retry</Button>}
+ />
+ )}
+
{hasErrorsFetchingData && (
<AlertError error={destinationsError} subject="Failed to retrieve pipelines" />
)}
@@ -419,14 +453,18 @@ export const Destinations = () => {
title="Add a pipeline"
description="Send tables to an external destination for analytics workloads."
>
- <Button
+ <ButtonTooltip
+ tooltip={{
+ content: { text: isSourcesError && !canCreate ? sourceErrorTitle : undefined },
+ }}
variant="default"
icon={<Plus />}
- disabled={!newDestinationDefaultType}
+ loading={isCheckingPipelineStatus}
+ disabled={!canCreate}
onClick={openDestinationPanel}
>
Add pipeline
- </Button>
+ </ButtonTooltip>
</EmptyStatePresentational>
)}
</div>
@@ -435,7 +473,8 @@ export const Destinations = () => {
<EnablePipelinesModal
open={showEnablePipelinesDialog}
- onOpenChange={setShowEnablePipelinesDialog}
+ onOpenChange={handleEnableDialogOpenChange}
+ onSuccess={handlePipelinesEnabled}
/>
<DisablePipelinesDialog
diff --git a/apps/studio/components/interfaces/Database/Replication/EnablePipelinesCallout.tsx b/apps/studio/components/interfaces/Database/Replication/EnablePipelinesCallout.tsx
index a1485e9d76e..2793b2b6ba3 100644
--- a/apps/studio/components/interfaces/Database/Replication/EnablePipelinesCallout.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/EnablePipelinesCallout.tsx
@@ -13,6 +13,7 @@ import {
DialogTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
+import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { DestinationType } from './DestinationPanel/DestinationPanel.types'
import { InlineLink } from '@/components/ui/InlineLink'
@@ -22,12 +23,13 @@ import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
import { DOCS_URL } from '@/lib/constants'
type EnablePipelinesModalProps =
- | { open: boolean; onOpenChange: (open: boolean) => void }
- | { open?: never; onOpenChange?: never }
+ | { open: boolean; onOpenChange: (open: boolean) => void; onSuccess?: () => void }
+ | { open?: never; onOpenChange?: never; onSuccess?: () => void }
export const EnablePipelinesModal = ({
open: extOpen,
onOpenChange,
+ onSuccess,
}: EnablePipelinesModalProps) => {
const { ref: projectRef } = useParams()
const [_open, _setOpen] = useState(false)
@@ -36,12 +38,13 @@ export const EnablePipelinesModal = ({
const setOpen = onOpenChange ?? _setOpen
const hideTrigger = extOpen !== undefined && onOpenChange !== undefined
- const { hasAccess } = useCheckEntitlements('replication.etl')
+ const { hasAccess, isLoading } = useCheckEntitlements('replication.etl')
const { mutate: createTenantSource, isPending: creatingTenantSource } =
useCreateTenantSourceMutation({
onSuccess: () => {
toast.success('Pipelines enabled')
+ onSuccess?.()
setOpen(false)
},
onError: (error) => {
@@ -50,6 +53,7 @@ export const EnablePipelinesModal = ({
})
const onEnablePipelines = async () => {
+ if (isLoading || !hasAccess) return
if (!projectRef) return console.error('Project ref is required')
createTenantSource({ projectRef })
}
@@ -67,7 +71,15 @@ export const EnablePipelinesModal = ({
</DialogHeader>
<DialogSectionSeparator />
<DialogSection className="flex flex-col gap-y-3">
- {hasAccess ? (
+ <p role="status" aria-live="polite" className="sr-only">
+ {isLoading ? 'Checking Pipelines access…' : ''}
+ </p>
+ {isLoading && (
+ <div aria-hidden="true">
+ <GenericSkeletonLoader />
+ </div>
+ )}
+ {!isLoading && hasAccess && (
<>
<p className="text-sm text-foreground-light">
Pipelines bills for configured pipeline hours and Postgres row data processed during
@@ -81,7 +93,8 @@ export const EnablePipelinesModal = ({
Pipelines is in public alpha and may change.
</p>
</>
- ) : (
+ )}
+ {!isLoading && !hasAccess && (
<p className="text-sm text-foreground-light">Pipelines requires the Pro plan.</p>
)}
</DialogSection>
@@ -89,9 +102,14 @@ export const EnablePipelinesModal = ({
<Button disabled={creatingTenantSource} onClick={() => setOpen(false)}>
Cancel
</Button>
- {hasAccess ? (
- <Button variant="primary" loading={creatingTenantSource} onClick={onEnablePipelines}>
- Enable Pipelines
+ {isLoading || hasAccess ? (
+ <Button
+ variant="primary"
+ loading={isLoading || creatingTenantSource}
+ disabled={isLoading}
+ onClick={onEnablePipelines}
+ >
+ Enable
</Button>
) : (
<UpgradePlanButton source="replication" featureProposition="use replication" />