Skip to content

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

feat(studio): open the pipeline wizard from Add pipeline (#51903)

Danny White827e79c5bcf2
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationPage.test.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationPage.test.tsx
index a601f33c436..5e881ccb1b8 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationPage.test.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationPage.test.tsx
@@ -1,10 +1,16 @@
+import { QueryClient } from '@tanstack/react-query'
import { fireEvent, screen } from '@testing-library/react'
+import type { components } from 'api-types'
+import { HttpResponse } from 'msw'
import { beforeEach, expect, it, vi } from 'vitest'
+import { replicationKeys } from '@/data/replication/keys'
import PipelineCreationPage from '@/pages/project/[ref]/database/pipelines/new'
import { customRender } from '@/tests/lib/custom-render'
+import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
const state = vi.hoisted(() => ({
+ hasProjectRef: true,
push: vi.fn(),
enabled: false,
loading: false,
@@ -19,7 +25,7 @@ vi.mock('next/router', async (importOriginal) => ({
}))
vi.mock('common', async (importOriginal) => ({
...(await importOriginal<typeof import('common')>()),
- useParams: () => ({ ref: 'default' }),
+ useParams: () => ({ ref: state.hasProjectRef ? 'default' : undefined }),
useFeatureFlags: () => ({ hasLoaded: state.flagsLoaded }),
}))
vi.mock('@/hooks/misc/withAuth', () => ({ withAuth: (component: unknown) => component }))
@@ -49,8 +55,28 @@ vi.mock('./PipelineCreationFlow', () => ({
),
}))
+const mockSources = (sources: components['schemas']['SourcesResponse_Output']['sources']) =>
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: () => HttpResponse.json<components['schemas']['SourcesResponse_Output']>({ sources }),
+ })
beforeEach(() => {
+ mockSources([
+ {
+ id: 42,
+ name: 'default',
+ tenant_id: 'tenant',
+ config: {
+ host: 'localhost',
+ port: 5432,
+ name: 'postgres',
+ username: 'postgres',
+ },
+ },
+ ])
Object.assign(state, {
+ hasProjectRef: true,
enabled: true,
loading: false,
flagsLoaded: true,
@@ -59,9 +85,9 @@ beforeEach(() => {
canUseReplication: true,
})
})
-it('renders the page body when the preview and project allow access', () => {
+it('renders the page body when the preview and project allow access', async () => {
customRender(<PipelineCreationPage />)
- expect(screen.getByText('Wizard form')).toBeInTheDocument()
+ expect(await screen.findByText('Wizard form')).toBeInTheDocument()
})
it.each(['loading', 'orgPending'] as const)('waits while %s', (key) => {
state[key] = true
@@ -95,8 +121,60 @@ it('falls back when the preview is off even if organisation and project queries
expect(screen.getByRole('status')).toHaveTextContent('Returning to Pipelines')
})
-it('returns through the shared router without reloading the toast host', () => {
+it('returns through the shared router without reloading the toast host', async () => {
customRender(<PipelineCreationPage />)
- fireEvent.click(screen.getByRole('button', { name: 'Wizard form' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'Wizard form' }))
expect(state.push).toHaveBeenCalledWith('/project/default/database/pipelines')
})
+
+it.each(['disabled', 'error'])(
+ 'returns direct entry to Pipelines when enablement is %s',
+ async (status) => {
+ if (status === 'disabled') mockSources([])
+ else
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: () =>
+ HttpResponse.json<APIErrorBody>(
+ { message: 'replication API URL is not configured' },
+ { status: 503 }
+ ),
+ })
+ customRender(<PipelineCreationPage />)
+ expect(await screen.findByRole('status')).toHaveTextContent('Returning to Pipelines')
+ expect(screen.queryByText('Wizard form')).not.toBeInTheDocument()
+ }
+)
+
+it.each([false, true])('waits for the project reference (preview: %s)', (enabled) => {
+ state.enabled = enabled
+ state.hasProjectRef = false
+ customRender(<PipelineCreationPage />)
+ expect(screen.queryByRole('status')).not.toBeInTheDocument()
+ expect(screen.queryByText('Wizard form')).not.toBeInTheDocument()
+})
+it('rechecks cached enablement before allowing direct entry', async () => {
+ const queryClient = new QueryClient()
+ queryClient.setQueryData(replicationKeys.sources('default'), {
+ sources: [{ id: 42, name: 'default' }],
+ })
+ let finish: (() => void) | undefined
+ const gate = new Promise<void>((resolve) => {
+ finish = resolve
+ })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/replication/:ref/sources',
+ response: async () => {
+ await gate
+ return HttpResponse.json<components['schemas']['SourcesResponse_Output']>({ sources: [] })
+ },
+ })
+ customRender(<PipelineCreationPage />, { queryClient })
+ expect(screen.queryByText('Wizard form')).not.toBeInTheDocument()
+ expect(screen.queryByRole('status')).not.toBeInTheDocument()
+ finish?.()
+ expect(await screen.findByRole('status')).toHaveTextContent('Returning to Pipelines')
+ expect(screen.queryByText('Wizard form')).not.toBeInTheDocument()
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx
index 6bb01ac3a2c..0a7b40dcf3f 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.test.tsx
@@ -13,12 +13,40 @@ import { addAPIMock, mswServer, type APIErrorBody } from '@/tests/lib/msw'
mockAnimationsApi()
const options = vi.hoisted(() => ({
+ wizard: false,
+ previewLoading: false,
+ flagsLoaded: true,
+ tanStack: false,
+ navigate: vi.fn(),
+ push: vi.fn(),
legacy: false,
hasAccess: true,
isLoading: false,
failEnable: false,
failRefresh: false,
}))
+vi.mock('@/lib/constants', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('@/lib/constants')>()),
+ IS_PLATFORM: true,
+}))
+vi.mock('common', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('common')>()),
+ useParams: () => ({ ref: 'default' }),
+ useFeatureFlags: () => ({ hasLoaded: options.flagsLoaded }),
+}))
+vi.mock('@tanstack/react-router', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('@tanstack/react-router')>()),
+ useRouter: () => (options.tanStack ? { navigate: options.navigate } : undefined),
+}))
+vi.mock('next/compat/router', () => ({
+ useRouter: () => ({ push: options.push, events: { on: vi.fn(), off: vi.fn() } }),
+}))
+vi.mock('@/components/interfaces/App/FeaturePreview/FeaturePreviewContext', () => ({
+ usePipelineCreationPreview: () => ({
+ isEnabled: options.wizard,
+ isLoading: options.previewLoading,
+ }),
+}))
vi.mock('./useIsETLPrivateAlpha', () => ({
useIsETLBigQueryPrivateAlpha: () => !options.legacy,
useIsETLIcebergPrivateAlpha: () => options.legacy,
@@ -38,6 +66,12 @@ vi.mock('./DestinationPanel/DestinationPanel', () => ({
let isEnabled = false
let enableGate: Promise<void> | undefined
beforeEach(() => {
+ options.wizard = false
+ options.previewLoading = false
+ options.flagsLoaded = true
+ options.tanStack = false
+ options.navigate.mockClear()
+ options.push.mockClear()
isEnabled = false
enableGate = undefined
options.legacy = false
@@ -236,3 +270,73 @@ test.each(['loading', 'error'])('blocks creation when source status is %s', asyn
addPipeline()
expect(await screen.findByRole('dialog')).toHaveTextContent('Enable Pipelines')
})
+
+test('renders both wizard entry controls as links', async () => {
+ options.wizard = true
+ isEnabled = true
+ await renderList()
+ const links = screen.getAllByRole('link', { name: 'Add pipeline' })
+ expect(links).toHaveLength(2)
+ links.forEach((link) =>
+ expect(link).toHaveAttribute('href', '/project/default/database/pipelines/new')
+ )
+ fireEvent.click(links[0], { ctrlKey: true })
+ expect(options.push).not.toHaveBeenCalled()
+ expect(options.navigate).not.toHaveBeenCalled()
+})
+test.each([false, true])('opens the wizard with the shortcut (TanStack: %s)', async (tanStack) => {
+ options.wizard = true
+ options.tanStack = tanStack
+ isEnabled = true
+ await renderList()
+ fireEvent.keyDown(document, { key: 'N', shiftKey: true })
+ if (tanStack)
+ expect(options.navigate).toHaveBeenCalledWith({
+ to: '/project/$ref/database/pipelines/new',
+ params: { ref: 'default' },
+ })
+ else expect(options.push).toHaveBeenCalledWith('/project/default/database/pipelines/new')
+})
+test('enables Pipelines before opening the wizard', async () => {
+ options.wizard = true
+ await renderList()
+ addPipeline()
+ expect(options.push).not.toHaveBeenCalled()
+ fireEvent.click(await screen.findByRole('button', { name: 'Enable' }))
+ await waitFor(() =>
+ expect(options.push).toHaveBeenCalledWith('/project/default/database/pipelines/new')
+ )
+})
+test.each(['previewLoading', 'flagsLoaded'] as const)(
+ 'waits for %s before choosing a creation flow',
+ async (gate) => {
+ options.previewLoading = gate === 'previewLoading'
+ options.flagsLoaded = gate !== 'flagsLoaded'
+ isEnabled = true
+ const view = await renderList()
+ expect(screen.getAllByRole('button', { name: 'Add pipeline' })[0]).toBeDisabled()
+ addPipeline()
+ fireEvent.keyDown(document, { key: 'N', shiftKey: true })
+ expect(options.push).not.toHaveBeenCalled()
+ expect(screen.queryByRole('heading', { name: /Creation sheet/ })).not.toBeInTheDocument()
+ options.previewLoading = false
+ options.flagsLoaded = true
+ options.wizard = true
+ view.rerender(<Destinations />)
+ fireEvent.keyDown(document, { key: 'N', shiftKey: true })
+ expect(options.push).toHaveBeenCalledWith('/project/default/database/pipelines/new')
+ }
+)
+
+test('keeps request-access creation in the sheet when no wizard destination is available', async () => {
+ options.wizard = true
+ options.legacy = true
+ isEnabled = true
+ await renderList()
+ addPipeline()
+ expect(
+ await screen.findByRole('heading', { name: 'Creation sheet: BigQuery' })
+ ).toBeInTheDocument()
+ expect(options.push).not.toHaveBeenCalled()
+ expect(options.navigate).not.toHaveBeenCalled()
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index f44d5fe774b..208f0790f2c 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -1,6 +1,8 @@
import { useQueries, useQueryClient } from '@tanstack/react-query'
-import { useParams } from 'common'
+import { useRouter as useTanStackRouter } from '@tanstack/react-router'
+import { useFeatureFlags, useParams } from 'common'
import { MoreVerticalIcon, PlusIcon, SearchIcon, WorkflowIcon, XIcon } from 'lucide-react'
+import { useRouter as useNextRouter } from 'next/compat/router'
import Link from 'next/link'
import { parseAsStringEnum, useQueryState } from 'nuqs'
import { useEffect, useMemo, useRef, useState } from 'react'
@@ -31,7 +33,14 @@ import { DisablePipelinesDialog } from './DisablePipelinesDialog'
import { EnablePipelinesModal } from './EnablePipelinesCallout'
import { getStatusName } from './Pipeline.utils'
import { PipelineStatusName } from './Replication.constants'
+import {
+ useIsETLBigQueryPrivateAlpha,
+ useIsETLClickHousePrivateAlpha,
+ useIsETLDucklakePrivateAlpha,
+ useIsETLSnowflakePrivateAlpha,
+} from './useIsETLPrivateAlpha'
import { useRedirectLegacyReadReplicaDestination } from './useRedirectLegacyReadReplicaDestination'
+import { usePipelineCreationPreview } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { AlertError } from '@/components/ui/AlertError'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { Shortcut } from '@/components/ui/Shortcut'
@@ -47,6 +56,7 @@ import { useReplicationPipelinesQuery } from '@/data/replication/pipelines-query
import { useReplicationSourcesQuery } from '@/data/replication/sources-query'
import { checkLocalETLNotSetUp } from '@/data/replication/utils'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
+import { IS_PLATFORM } from '@/lib/constants'
import { onSearchInputEscape } from '@/lib/keyboard'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
@@ -89,6 +99,16 @@ const compareStatusNames = (
export const Destinations = () => {
const queryClient = useQueryClient()
+ const router = useTanStackRouter({ warn: false })
+ const nextRouter = useNextRouter()
+ const { isEnabled: isWizardEnabled, isLoading: isPreviewLoading } = usePipelineCreationPreview()
+ const bigQuery = useIsETLBigQueryPrivateAlpha()
+ const duckLake = useIsETLDucklakePrivateAlpha()
+ const snowflake = useIsETLSnowflakePrivateAlpha()
+ const clickHouse = useIsETLClickHousePrivateAlpha()
+ const hasWizardDestination = bigQuery || duckLake || snowflake || clickHouse
+ const { hasLoaded: hasFlagsLoaded } = useFeatureFlags()
+ const isCreationGateLoading = isPreviewLoading || (IS_PLATFORM && !hasFlagsLoaded)
const { ref: projectRef } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
@@ -213,20 +233,37 @@ export const Destinations = () => {
const isLocalETLNotSetUp = checkLocalETLNotSetUp(destinationsError)
const hasErrorsFetchingData = !isLocalETLNotSetUp && isDestinationsError
- const canCreate = isSourcesSuccess
- const isCheckingPipelineStatus = !isSourcesSuccess && !isSourcesError
+ const canCreate = isSourcesSuccess && !isCreationGateLoading
+ const isCheckingPipelineStatus = isCreationGateLoading || (!isSourcesSuccess && !isSourcesError)
const sourceErrorTitle = checkLocalETLNotSetUp(sourcesError)
? 'Replication unavailable locally'
: 'Failed to retrieve pipeline enablement status'
- const openDestinationPanel = () => {
+ const canLinkToWizard =
+ isWizardEnabled && hasWizardDestination && !!projectRef && !replicationNotEnabled && canCreate
+ const wizardHref = `/project/${projectRef}/database/pipelines/new`
+
+ const openCreation = (type: DestinationType) => {
+ if (isWizardEnabled && hasWizardDestination && projectRef) {
+ if (router)
+ void router.navigate({
+ to: '/project/$ref/database/pipelines/new',
+ params: { ref: projectRef },
+ })
+ else void nextRouter?.push(`/project/${projectRef}/database/pipelines/new`)
+ } else {
+ setDestinationType(type)
+ }
+ }
+
+ const handleAddPipeline = () => {
if (!canCreate) return
if (replicationNotEnabled) {
pendingCreationTypeRef.current = 'BigQuery'
setShowEnablePipelinesDialog(true)
return
}
- setDestinationType('BigQuery')
+ openCreation('BigQuery')
}
const handleEnableDialogOpenChange = (open: boolean) => {
@@ -241,7 +278,7 @@ export const Destinations = () => {
type &&
queryClient.getQueryState(replicationKeys.sources(projectRef))?.status === 'success'
) {
- setDestinationType(type)
+ openCreation(type)
}
}
@@ -352,7 +389,7 @@ export const Destinations = () => {
<Shortcut
id={SHORTCUT_IDS.LIST_PAGE_NEW_ITEM}
label="Add pipeline"
- onTrigger={openDestinationPanel}
+ onTrigger={handleAddPipeline}
options={{ enabled: canCreate }}
side="bottom"
tooltipOpen={canCreate ? undefined : false}
@@ -365,9 +402,10 @@ export const Destinations = () => {
icon={<PlusIcon />}
loading={isCheckingPipelineStatus}
disabled={!canCreate}
- onClick={openDestinationPanel}
+ asChild={canLinkToWizard}
+ onClick={canLinkToWizard ? undefined : handleAddPipeline}
>
- Add pipeline
+ {canLinkToWizard ? <Link href={wizardHref}>Add pipeline</Link> : 'Add pipeline'}
</ButtonTooltip>
</Shortcut>
</div>
@@ -463,9 +501,10 @@ export const Destinations = () => {
icon={<PlusIcon />}
loading={isCheckingPipelineStatus}
disabled={!canCreate}
- onClick={openDestinationPanel}
+ asChild={canLinkToWizard}
+ onClick={canLinkToWizard ? undefined : handleAddPipeline}
>
- Add pipeline
+ {canLinkToWizard ? <Link href={wizardHref}>Add pipeline</Link> : 'Add pipeline'}
</ButtonTooltip>
</EmptyStatePresentational>
)}
diff --git a/apps/studio/pages/project/[ref]/database/pipelines/new.tsx b/apps/studio/pages/project/[ref]/database/pipelines/new.tsx
index 4548b43d27c..7137492e358 100644
--- a/apps/studio/pages/project/[ref]/database/pipelines/new.tsx
+++ b/apps/studio/pages/project/[ref]/database/pipelines/new.tsx
@@ -12,6 +12,7 @@ import {
useIsETLDucklakePrivateAlpha,
useIsETLSnowflakePrivateAlpha,
} from '@/components/interfaces/Database/Replication/useIsETLPrivateAlpha'
+import { useReplicationSourcesQuery } from '@/data/replication/sources-query'
import { useHighAvailability } from '@/hooks/misc/useHighAvailability'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
@@ -32,10 +33,18 @@ const PipelineCreationPage: NextPageWithLayout<Record<string, never>> = () => {
const duckLake = useIsETLDucklakePrivateAlpha()
const snowflake = useIsETLSnowflakePrivateAlpha()
const clickHouse = useIsETLClickHousePrivateAlpha()
+ const isProjectAccessLoading =
+ isLoading || (isEnabled && (!hasLoaded || isOrganizationPending || isPending))
+ const canAccessFlow = isEnabled && !isHighAvailability && canUseReplication
+ const sources = useReplicationSourcesQuery(
+ { projectRef: ref },
+ { enabled: !isProjectAccessLoading && canAccessFlow, refetchOnMount: 'always' }
+ )
+ const hasSource = sources.data?.sources.some((source) => source.name === ref) === true
const listHref = `${BASE_PATH}/project/${ref}/database/pipelines`
const isAccessLoading =
- isLoading || (isEnabled && (!hasLoaded || isOrganizationPending || isPending))
- const canOpenFlow = isEnabled && !isHighAvailability && canUseReplication
+ !ref || isProjectAccessLoading || (canAccessFlow && !sources.isFetchedAfterMount)
+ const canOpenFlow = canAccessFlow && sources.isSuccess && hasSource
useEffect(() => {
if (!isAccessLoading && !canOpenFlow) {
const fallback = isEnabled ? listHref : `${listHref}?destinationType=BigQuery`