Skip to content

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

feat(studio): validate pipeline wizard connections (#51818)

Danny White8047d93e3ca6
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionSection.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionSection.tsx
index 4eede44234d..d7699498226 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionSection.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionSection.tsx
@@ -12,10 +12,12 @@ export const PipelineConnectionSection = ({
type,
form,
children,
+ revealInvalidSettings = false,
}: {
type: DestinationType
form: UseFormReturn<DestinationPanelSchemaType>
children: ReactNode
+ revealInvalidSettings?: boolean
}) => (
<section aria-label="Destination connection">
<div className="flex flex-col gap-y-4 p-5">
@@ -25,6 +27,11 @@ export const PipelineConnectionSection = ({
</div>
<DialogSectionSeparator />
{children}
- <AdvancedSettings type={type} form={form} group="connection" />
+ <AdvancedSettings
+ type={type}
+ form={form}
+ group="connection"
+ revealInvalidSettings={revealInvalidSettings}
+ />
</section>
)
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.test.ts b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.test.ts
new file mode 100644
index 00000000000..cc0f9dbc183
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, it } from 'vitest'
+
+import { generateDefaultValues } from '../DestinationPanel/DestinationForm/DestinationForm.utils'
+import {
+ getConnectionFieldNames,
+ getConnectionValidationIssues,
+} from './PipelineConnectionValidation.utils'
+
+const validData = {
+ ...generateDefaultValues({ catalogToken: '', editMode: false }),
+ name: 'Warehouse',
+ projectId: 'project',
+ datasetId: 'dataset',
+ serviceAccountKey: '{}',
+ ducklakeMode: 'custom' as const,
+ ducklakeCatalogUrl: 'postgresql://user:password@host/catalog',
+ ducklakeDataPath: 's3://bucket/data',
+ ducklakeS3AccessKeyId: 'key',
+ ducklakeS3SecretAccessKey: 'secret',
+ ducklakeS3Region: 'us-east-1',
+ ducklakeS3Endpoint: 's3.us-east-1.amazonaws.com',
+ snowflakeAccountId: 'account',
+ snowflakeUser: 'user',
+ snowflakePrivateKey: '-----BEGIN PRIVATE KEY-----\nkey\n-----END PRIVATE KEY-----',
+ snowflakeDatabase: 'database',
+ snowflakeSchema: 'PUBLIC',
+ clickhouseUrl: 'https://host:8443',
+ clickhouseUser: 'default',
+ clickhousePassword: 'password',
+ clickhouseDatabase: 'database',
+}
+
+describe('connection validation', () => {
+ it.each(['BigQuery', 'DuckLake', 'Snowflake', 'ClickHouse'] as const)(
+ 'validates %s independently of unfilled data fields and other destinations',
+ (type) => {
+ expect(getConnectionValidationIssues(type, validData)).toEqual([])
+ expect(getConnectionValidationIssues(type, { ...validData, name: ' ' })).toContainEqual({
+ path: 'name',
+ message: 'Name is required.',
+ })
+ const fields = getConnectionFieldNames(type)
+ expect(fields).toContain('name')
+ expect(fields).not.toContain('publicationName')
+ expect(fields).not.toContain('tableOptions')
+ }
+ )
+
+ it.each([
+ ['BigQuery', { serviceAccountKey: 'invalid' }, 'serviceAccountKey'],
+ ['DuckLake', { ducklakeCatalogUrl: '' }, 'ducklakeCatalogUrl'],
+ ['Snowflake', { snowflakePrivateKey: 'invalid' }, 'snowflakePrivateKey'],
+ ['ClickHouse', { clickhouseUrl: '' }, 'clickhouseUrl'],
+ ] as const)('rejects invalid %s connection settings (%s)', (type, changes, path) => {
+ expect(getConnectionValidationIssues(type, { ...validData, ...changes })).toEqual(
+ expect.arrayContaining([expect.objectContaining({ path })])
+ )
+ })
+})
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.ts b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.ts
new file mode 100644
index 00000000000..82a88578765
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineConnectionValidation.utils.ts
@@ -0,0 +1,51 @@
+import * as z from 'zod'
+
+import { BigQueryFormSchema } from '../DestinationPanel/DestinationForm/BigQuery/BigQuery.schema'
+import { getBigQueryValidationIssues } from '../DestinationPanel/DestinationForm/BigQuery/BigQuery.utils'
+import { ClickHouseFormSchema } from '../DestinationPanel/DestinationForm/ClickHouse/ClickHouse.schema'
+import { getClickHouseValidationIssues } from '../DestinationPanel/DestinationForm/ClickHouse/ClickHouse.utils'
+import {
+ DestinationPanelFormSchema,
+ type DestinationPanelSchemaType,
+} from '../DestinationPanel/DestinationForm/DestinationForm.schema'
+import { DuckLakeFormSchema } from '../DestinationPanel/DestinationForm/DuckLake/DuckLake.schema'
+import { getDucklakeValidationIssues } from '../DestinationPanel/DestinationForm/DuckLake/DuckLake.utils'
+import { SnowflakeFormSchema } from '../DestinationPanel/DestinationForm/Snowflake/Snowflake.schema'
+import { getSnowflakeValidationIssues } from '../DestinationPanel/DestinationForm/Snowflake/Snowflake.utils'
+
+type ConnectionDestination = 'BigQuery' | 'DuckLake' | 'Snowflake' | 'ClickHouse'
+const schemas = {
+ BigQuery: BigQueryFormSchema.omit({ tableOptions: true }),
+ DuckLake: DuckLakeFormSchema,
+ Snowflake: SnowflakeFormSchema,
+ ClickHouse: ClickHouseFormSchema,
+}
+const validators = {
+ BigQuery: getBigQueryValidationIssues,
+ DuckLake: getDucklakeValidationIssues,
+ Snowflake: getSnowflakeValidationIssues,
+ ClickHouse: getClickHouseValidationIssues,
+}
+
+export const getConnectionFieldNames = (type: ConnectionDestination) =>
+ ['name', ...Object.keys(schemas[type].shape)].filter(
+ (name): name is keyof DestinationPanelSchemaType => name in DestinationPanelFormSchema.shape
+ )
+
+export const getConnectionValidationIssues = (
+ type: ConnectionDestination,
+ data: DestinationPanelSchemaType
+) => {
+ const result = schemas[type]
+ .extend({ name: z.string().trim().min(1, 'Name is required.') })
+ .safeParse(data)
+ return [
+ ...(result.success
+ ? []
+ : result.error.issues.map((issue) => ({ path: issue.path[0], message: issue.message }))),
+ ...validators[type](data),
+ ].filter(
+ (issue): issue is { path: keyof DestinationPanelSchemaType; message: string } =>
+ typeof issue.path === 'string' && issue.path in DestinationPanelFormSchema.shape
+ )
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.test.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.test.tsx
index c30ea9095c8..9b0bf1c520d 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.test.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.test.tsx
@@ -1,7 +1,7 @@
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
import type { components } from 'api-types'
import { mockAnimationsApi } from 'jsdom-testing-mocks'
-import { HttpResponse } from 'msw'
+import { delay, HttpResponse } from 'msw'
import { NuqsAdapter } from 'nuqs/adapters/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
@@ -28,6 +28,14 @@ vi.mock('@/components/layouts/AppLayout/ProjectDropdown', () => ({
mockAnimationsApi()
beforeEach(() => {
+ addAPIMock({
+ method: 'post',
+ path: '/platform/replication/:ref/destinations/validate',
+ response: () =>
+ HttpResponse.json<components['schemas']['ValidateDestinationResponse_Output']>({
+ validation_failures: [],
+ }),
+ })
addAPIMock({
method: 'get',
path: '/platform/replication/:ref/sources',
@@ -53,9 +61,120 @@ beforeEach(() => {
})
})
const next = () => fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+const fillConnection = () => {
+ for (const [name, value] of [
+ ['Pipeline name', 'Warehouse'],
+ ['Project ID', 'my-project'],
+ ['Dataset ID', 'dataset'],
+ ['Service account key', '{}'],
+ ]) {
+ fireEvent.change(screen.getByRole('textbox', { name }), { target: { value } })
+ }
+}
+const continueToData = async () => {
+ next()
+ await screen.findByText(/Step 3 of 4/)
+}
const back = () => fireEvent.click(screen.getByRole('button', { name: 'Back' }))
describe('PipelineCreationFlow', () => {
+ it('requires valid fields, recovers from request and critical failures, and reviews warnings before continuing', async () => {
+ let attempt = 0
+ const requests: unknown[] = []
+ addAPIMock({
+ method: 'post',
+ path: '/platform/replication/:ref/destinations/validate',
+ response: async ({ request }) => {
+ requests.push(await request.json())
+ await delay(10)
+ attempt++
+ if (attempt === 1)
+ return HttpResponse.json<{ message: string }>({ message: 'Try again' }, { status: 500 })
+ return HttpResponse.json<components['schemas']['ValidateDestinationResponse_Output']>({
+ validation_failures: [
+ {
+ name: 'Credentials',
+ reason: 'Check credentials',
+ failure_type: attempt === 2 ? 'critical' : 'warning',
+ },
+ ],
+ })
+ },
+ })
+ customRender(
+ <PipelineCreationFlow availableDestinations={['BigQuery', 'Snowflake']} onClose={vi.fn()} />,
+ {
+ nuqs: { hasMemory: true },
+ }
+ )
+ next()
+ fireEvent.click(screen.getByRole('button', { name: /Advanced settings/ }))
+ fireEvent.change(screen.getByRole('spinbutton', { name: 'Connection pool size' }), {
+ target: { value: '-1' },
+ })
+ fireEvent.click(screen.getByRole('button', { name: /Advanced settings/ }))
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ expect((await screen.findAllByText(/Project ID is required\./)).length).toBeGreaterThan(0)
+ expect(requests).toHaveLength(0)
+ expect(screen.getByRole('spinbutton', { name: 'Connection pool size' })).toBeVisible()
+ fireEvent.click(screen.getByRole('button', { name: /Advanced settings/ }))
+ expect(
+ screen.queryByRole('spinbutton', { name: 'Connection pool size' })
+ ).not.toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ expect(screen.getByRole('spinbutton', { name: 'Connection pool size' })).toBeVisible()
+ fireEvent.change(screen.getByRole('spinbutton', { name: 'Connection pool size' }), {
+ target: { value: '5' },
+ })
+ expect(screen.queryByText('Check connection settings')).not.toBeInTheDocument()
+ fillConnection()
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ expect(screen.getByRole('button', { name: 'Back' })).toBeDisabled()
+ expect(await screen.findByText('Try again')).toBeInTheDocument()
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'retry-project' },
+ })
+ expect(screen.getByText('Try again')).toBeInTheDocument()
+ back()
+ fireEvent.click(screen.getByRole('radio', { name: /Snowflake/ }))
+ next()
+ expect(screen.queryByText('Try again')).not.toBeInTheDocument()
+ back()
+ fireEvent.click(screen.getByRole('radio', { name: /BigQuery/ }))
+ next()
+ expect(screen.queryByText('Try again')).not.toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ expect(await screen.findByText('Check credentials')).toBeInTheDocument()
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Continue' })).not.toBeDisabled())
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'edited-project' },
+ })
+ expect(screen.getByText('Check credentials')).toBeInTheDocument()
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'retry-project' },
+ })
+ expect(screen.getByText('Check credentials')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ await screen.findByText(/Replication can start/)
+ expect(screen.getByText(/Step 2 of 4/)).toBeInTheDocument()
+ expect(requests[2]).not.toHaveProperty('pipeline_config')
+ expect(requests[2]).not.toHaveProperty('source_id')
+ next()
+ back()
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'changed' },
+ })
+ expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument()
+ expect(screen.queryByText('Check credentials')).not.toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'changed-during-test' },
+ })
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Continue' })).not.toBeDisabled())
+ expect(screen.getByText(/Step 2 of 4/)).toBeInTheDocument()
+ expect(screen.queryByText(/Replication can start/)).not.toBeInTheDocument()
+ })
+
it('uses browser Back and Forward to revisit steps without losing values', async () => {
window.history.replaceState(null, '', '/project/default/database/pipelines/new')
customRender(
@@ -68,7 +187,8 @@ describe('PipelineCreationFlow', () => {
fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
target: { value: 'history-project' },
})
- next()
+ fillConnection()
+ await continueToData()
await waitFor(() => expect(window.location.search).toBe('?step=data'))
await act(async () => {
await new Promise<void>((resolve) => {
@@ -77,7 +197,7 @@ describe('PipelineCreationFlow', () => {
})
})
expect(screen.getByText(/Step 2 of 4/)).toBeInTheDocument()
- expect(screen.getByRole('textbox', { name: 'Project ID' })).toHaveValue('history-project')
+ expect(screen.getByRole('textbox', { name: 'Project ID' })).toHaveValue('my-project')
await act(async () => {
await new Promise<void>((resolve) => {
window.addEventListener('popstate', () => resolve(), { once: true })
@@ -85,9 +205,25 @@ describe('PipelineCreationFlow', () => {
})
})
expect(screen.getByText(/Step 3 of 4/)).toBeInTheDocument()
- back()
+ await act(async () => {
+ await new Promise<void>((resolve) => {
+ window.addEventListener('popstate', () => resolve(), { once: true })
+ window.history.back()
+ })
+ })
+ await waitFor(() => expect(window.location.search).toBe('?step=connection'))
+ expect(screen.getByRole('textbox', { name: 'Project ID' })).toHaveValue('my-project')
+ fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
+ target: { value: 'changed-project' },
+ })
+ await act(async () => {
+ await new Promise<void>((resolve) => {
+ window.addEventListener('popstate', () => resolve(), { once: true })
+ window.history.forward()
+ })
+ })
await waitFor(() => expect(window.location.search).toBe('?step=connection'))
- expect(screen.getByRole('textbox', { name: 'Project ID' })).toHaveValue('history-project')
+ expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument()
})
it.each(['connection', 'data', 'review', 'invalid'])(
@@ -104,7 +240,7 @@ describe('PipelineCreationFlow', () => {
}
)
- it('preserves connection and data values across steps and destination changes', () => {
+ it('preserves connection and data values across steps and destination changes', async () => {
customRender(
<PipelineCreationFlow availableDestinations={['BigQuery', 'Snowflake']} onClose={vi.fn()} />,
{ nuqs: { hasMemory: true } }
@@ -117,7 +253,8 @@ describe('PipelineCreationFlow', () => {
fireEvent.change(screen.getByRole('textbox', { name: 'Project ID' }), {
target: { value: 'my-project' },
})
- next()
+ fillConnection()
+ await continueToData()
expect(screen.getByText(/Step [1-4] of 4/)).toHaveTextContent('Step 3 of 4')
fireEvent.click(screen.getByRole('button', { name: /Advanced settings/ }))
fireEvent.change(screen.getByRole('spinbutton', { name: 'Batch wait time' }), {
@@ -133,7 +270,7 @@ describe('PipelineCreationFlow', () => {
fireEvent.click(screen.getByRole('radio', { name: /BigQuery/ }))
next()
expect(screen.getByRole('textbox', { name: 'Project ID' })).toHaveValue('my-project')
- next()
+ await continueToData()
fireEvent.click(screen.getByRole('button', { name: /Advanced settings/ }))
expect(screen.getByRole('spinbutton', { name: 'Batch wait time' })).toHaveValue(750)
next()
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.tsx
index 8e7c1a12bcd..c4739ca3934 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineCreationFlow.tsx
@@ -19,6 +19,8 @@ import { PipelineDataSection } from './PipelineDataSection'
import { PipelineDestinationReview } from './PipelineDestinationReview'
import { PipelineDestinationSelection } from './PipelineDestinationSelection'
import { PipelineReviewCosts } from './PipelineReviewCosts'
+import { PipelineValidationAdmonition } from './PipelineValidationAdmonition'
+import { usePipelineConnectionValidation } from './usePipelineConnectionValidation'
import { DiscardChangesConfirmationDialog } from '@/components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'
import { SteppedFlow, SteppedFlowHeader } from '@/components/ui/SteppedFlow/SteppedFlow'
import { useReplicationPublicationQuery } from '@/data/replication/publication-query'
@@ -47,11 +49,6 @@ export const PipelineCreationFlow = ({
const [step, setStep] = useQueryState('step', stepParser)
const hasInitializedStepRef = useRef(false)
- useEffect(() => {
- if (hasInitializedStepRef.current) return
- hasInitializedStepRef.current = true
- void setStep('destination', { history: 'replace' })
- }, [setStep])
const [type, setType] = useState<FlowDestination>(availableDestinations[0] ?? 'BigQuery')
const [isPublicationPanelVisible, setIsPublicationPanelVisible] = useState(false)
const formId = useId()
@@ -77,6 +74,8 @@ export const PipelineCreationFlow = ({
confirmOnClose()
}
const { ref: projectRef } = useParams()
+ const { validateConnection, resetValidation, isValidating, isConnectionVerified, failures } =
+ usePipelineConnectionValidation({ projectRef, type, form })
const sourceId = useReplicationSourceId({ projectRef })
const publicationName = useWatch({ control: form.control, name: 'publicationName' })
const { data: publication } = useReplicationPublicationQuery({
@@ -84,9 +83,26 @@ export const PipelineCreationFlow = ({
sourceId,
publicationName,
})
- const currentStep = steps.find((item) => item.id === step) ?? steps[0]
+ const accessibleStep =
+ (step === 'data' || step === 'review') && !isConnectionVerified ? 'connection' : step
+ const handleNext = async () => {
+ if (accessibleStep === 'connection' && !isConnectionVerified && !(await validateConnection()))
+ return
+ const next = steps[steps.findIndex(({ id }) => id === accessibleStep) + 1]
+ if (next) void setStep(next.id)
+ }
+ const currentStep = steps.find((item) => item.id === accessibleStep) ?? steps[0]
const canSelectDestination = availableDestinations.includes(type)
+ useEffect(() => {
+ if (!hasInitializedStepRef.current) {
+ hasInitializedStepRef.current = true
+ void setStep('destination', { history: 'replace' })
+ return
+ }
+ if (step !== accessibleStep) void setStep(accessibleStep, { history: 'replace' })
+ }, [step, accessibleStep, setStep])
+
useEffect(() => {
if (!hasUnsavedChanges) return
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
@@ -112,43 +128,52 @@ export const PipelineCreationFlow = ({
<form id={formId} onSubmit={(event) => event.preventDefault()}>
<SteppedFlow
steps={steps}
- currentStep={step}
+ currentStep={accessibleStep}
onStepChange={setStep}
+ onNext={handleNext}
+ nextLoading={isValidating}
+ navigationDisabled={isValidating}
nextLabel="Continue"
- nextDisabled={step === 'destination' && !canSelectDestination}
+ nextDisabled={accessibleStep === 'destination' && !canSelectDestination}
onCancel={handleClose}
finalAction={{ label: 'Start pipeline', disabled: true }}
>
<SteppedFlowHeader title={currentStep.title} />
- {step === 'destination' && (
+ {accessibleStep === 'destination' && (
<div className="p-5">
<PipelineDestinationSelection
availableDestinations={availableDestinations}
value={type}
onChange={(value) => {
const next = availableDestinations.find((item) => item === value)
- if (next) setType(next)
+ if (next) {
+ resetValidation()
+ setType(next)
+ }
}}
renderLogo={(value) => <DestinationLogo type={value} />}
/>
</div>
)}
- {step === 'connection' && (
- <PipelineConnectionSection type={type} form={form}>
- {type === 'BigQuery' && <BigQueryFields form={form} editMode={false} />}
- {type === 'DuckLake' && <DuckLakeFields form={form} editMode={false} />}
- {type === 'Snowflake' && <SnowflakeFields form={form} editMode={false} />}
- {type === 'ClickHouse' && <ClickHouseFields form={form} editMode={false} />}
- </PipelineConnectionSection>
+ {accessibleStep === 'connection' && (
+ <>
+ <PipelineConnectionSection type={type} form={form} revealInvalidSettings>
+ {type === 'BigQuery' && <BigQueryFields form={form} editMode={false} />}
+ {type === 'DuckLake' && <DuckLakeFields form={form} editMode={false} />}
+ {type === 'Snowflake' && <SnowflakeFields form={form} editMode={false} />}
+ {type === 'ClickHouse' && <ClickHouseFields form={form} editMode={false} />}
+ </PipelineConnectionSection>
+ <PipelineValidationAdmonition failures={failures} />
+ </>
)}
- {step === 'data' && (
+ {accessibleStep === 'data' && (
<PipelineDataSection
type={type}
form={form}
onSelectNewPublication={() => setIsPublicationPanelVisible(true)}
/>
)}
- {step === 'review' && (
+ {accessibleStep === 'review' && (
<>
<PipelineDestinationReview type={type} control={form.control} />
<Separator />
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.test.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.test.tsx
index 38e58ede62b..ddcf53a51ce 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.test.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.test.tsx
@@ -57,15 +57,21 @@ test('shows critical issues without suggesting replication can start', () => {
expect(screen.queryByText(/Replication can start/)).not.toBeInTheDocument()
})
-test('distinguishes blockers and warnings in mixed results', () => {
+test('preserves API copy and inline code in compact results', () => {
customRender(
<PipelineValidationAdmonition
failures={[
- { name: 'Credentials', reason: 'Replace the key.', failure_type: 'critical' },
- { name: 'Replica identity', reason: 'Review table settings.', failure_type: 'warning' },
+ {
+ name: 'BigQuery dataset not found',
+ reason: 'The dataset was not found.\n\nCheck access to project `my-gcp-proj`.',
+ failure_type: 'critical',
+ },
]}
/>
)
- expect(screen.getByText('Required').closest('li')).toHaveTextContent('Replace the key.')
- expect(screen.getByText('Warning').closest('li')).toHaveTextContent('Review table settings.')
+ expect(screen.getByText('BigQuery dataset not found')).toBeInTheDocument()
+ expect(screen.getByText('The dataset was not found.')).toBeInTheDocument()
+ expect(screen.queryByRole('list')).not.toBeInTheDocument()
+ expect(screen.getByText('my-gcp-proj').tagName).toBe('CODE')
+ expect(screen.getByText('my-gcp-proj')).toHaveClass('text-code-inline')
})
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.tsx b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.tsx
index 5be0d8fb6a2..1c08cc77f47 100644
--- a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineValidationAdmonition.tsx
@@ -1,15 +1,11 @@
import { forwardRef, type ComponentRef } from 'react'
-import { Badge } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { Markdown } from '@/components/interfaces/Markdown'
import type { ValidationFailure } from '@/data/replication/validate-destination-mutation'
export const SANDWICHED_ADMONITION_CLASS =
- 'mb-0 rounded-none border-x-0 border-t-0 border-b border-default'
-
-export const CONNECTION_VALIDATION_HINT =
- 'Check destination credentials and connection settings, including Advanced settings under Destination connection.'
+ 'mb-0 rounded-none border-x-0 border-t border-b-0 border-default'
export const DATA_VALIDATION_HINT =
'Some issues may require changes to the project’s database settings.'
@@ -66,21 +62,23 @@ export const PipelineValidationAdmonition = forwardRef<
changes are applied downstream.
</p>
) : null}
- <ul className="space-y-2">
+ <div className="space-y-2">
{failures.map((failure, index) => (
- <li key={`${failure.name}-${index}`}>
- <Badge className="mb-1">
- {failure.failure_type === 'critical' ? 'Required' : 'Warning'}
- </Badge>
+ <div key={`${failure.name}-${index}`}>
{failures.length > 1 ? (
- <p className="mb-0.5! font-medium text-foreground">{failure.name}</p>
+ <p className="mb-0.5! font-medium text-foreground">
+ {failure.name}
+ {hasCritical && failures.some((item) => item.failure_type === 'warning')
+ ? ` (${failure.failure_type === 'critical' ? 'required' : 'warning'})`
+ : ''}
+ </p>
) : null}
- <Markdown className="text-sm text-foreground-light [&>p]:mb-0!">
+ <Markdown className="text-sm text-foreground-light [&>p]:inline [&>p+p]:before:content-[' ']">
{failure.reason}
</Markdown>
- </li>
+ </div>
))}
- </ul>
+ </div>
{hint ? <p className="mt-2 mb-0! text-sm text-foreground-light">{hint}</p> : null}
</Admonition>
)
diff --git a/apps/studio/components/interfaces/Database/Replication/CreatePipeline/usePipelineConnectionValidation.ts b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/usePipelineConnectionValidation.ts
new file mode 100644
index 00000000000..2f179a0354a
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/CreatePipeline/usePipelineConnectionValidation.ts
@@ -0,0 +1,93 @@
+import { useLayoutEffect, useRef, useState } from 'react'
+import { useWatch, type UseFormReturn } from 'react-hook-form'
+
+import type { DestinationPanelSchemaType } from '../DestinationPanel/DestinationForm/DestinationForm.schema'
+import { useDestinationValidation } from '../DestinationPanel/DestinationForm/useDestinationValidation'
+import {
+ getConnectionFieldNames,
+ getConnectionValidationIssues,
+} from './PipelineConnectionValidation.utils'
+import type { ValidationFailure } from '@/data/replication/validate-destination-mutation'
+
+export const usePipelineConnectionValidation = ({
+ projectRef,
+ type,
+ form,
+}: {
+ projectRef?: string
+ type: Parameters<typeof getConnectionFieldNames>[0]
+ form: UseFormReturn<DestinationPanelSchemaType>
+}) => {
+ const names = getConnectionFieldNames(type)
+ const values = useWatch({ control: form.control, name: names })
+ const snapshot = JSON.stringify([type, ...values])
+ const currentSnapshotRef = useRef(snapshot)
+ const [result, setResult] = useState<{
+ snapshot: string
+ type: typeof type
+ failures: ValidationFailure[]
+ verified: boolean
+ }>()
+ const [isValidating, setIsValidating] = useState(false)
+ const isValidatingRef = useRef(false)
+ const { validateDestination } = useDestinationValidation({ projectRef, selectedType: type })
+ const isConnectionVerified = result?.snapshot === snapshot && result.verified
+ const failures =
+ result?.type === type && (!result.verified || isConnectionVerified) ? result.failures : []
+
+ const validateConnection = async () => {
+ if (isValidatingRef.current) return false
+ form.clearErrors(names)
+ const data = form.getValues()
+ const issues = getConnectionValidationIssues(type, data)
+ if (issues.length > 0) {
+ issues.forEach(({ path, message }) => form.setError(path, { type: 'validate', message }))
+ form.setFocus(issues[0].path)
+ setResult(undefined)
+ return false
+ }
+ if (isConnectionVerified) return true
+ isValidatingRef.current = true
+ setIsValidating(true)
+ setResult(undefined)
+ try {
+ const { validation_failures: failures } = await validateDestination({ data })
+ if (currentSnapshotRef.current !== snapshot) return false
+ const verified = !failures.some((failure) => failure.failure_type === 'critical')
+ setResult({ snapshot, type, failures, verified })
+ // Warnings stay on this step for review before continuing.
+ return verified && failures.length === 0
+ } catch (error) {
+ if (currentSnapshotRef.current === snapshot) {
+ setResult({
+ snapshot,
+ type,
+ verified: false,
+ failures: [
+ {
+ name: 'Failed to validate destination',
+ failure_type: 'critical',
+ reason: error instanceof Error ? error.message : 'Please try again.',
+ },
+ ],
+ })
+ }
+ return false
+ } finally {
+ isValidatingRef.current = false
+ setIsValidating(false)
+ }
+ }
+
+ useLayoutEffect(() => {
+ currentSnapshotRef.current = snapshot
+ }, [snapshot])
+
+ return {
+ validateConnection,
+ resetValidation: () => setResult(undefined),
+ isValidating,
+ isConnectionVerified,
+ failures,
+ }
+}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
index 6018707e8f9..299a46a1c92 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
@@ -1,4 +1,5 @@
-import type { UseFormReturn } from 'react-hook-form'
+import { useEffect, useState } from 'react'
+import { useFormState, type UseFormReturn } from 'react-hook-form'
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, cn } from 'ui'
import { DestinationType } from '../DestinationPanel.types'
@@ -13,15 +14,21 @@ export const AdvancedSettings = ({
type,
form,
group = 'all',
+ revealInvalidSettings = false,
}: {
group?: 'all' | 'connection' | 'data'
+ revealInvalidSettings?: boolean
type: DestinationType
form: UseFormReturn<DestinationPanelSchemaType>
}) => {
+ const [expanded, setExpanded] = useState('')
+ const { errors } = useFormState({ control: form.control })
+ const advancedError =
+ (type === 'BigQuery' && (errors.connectionPoolSize || errors.maxStalenessMins)) ||
+ (type === 'DuckLake' && errors.ducklakePoolSize) ||
+ (type === 'Snowflake' && errors.snowflakeRole)
const shouldShowConnection = group !== 'data'
const shouldShowData = group !== 'connection'
- if (group === 'connection' && type !== 'BigQuery' && type !== 'DuckLake' && type !== 'Snowflake')
- return null
let description = 'Customize how the pipeline syncs and replicates data.'
if (type === 'DuckLake' && group === 'all')
@@ -29,9 +36,16 @@ export const AdvancedSettings = ({
if (group === 'connection') description = `Adjust how data is written to ${type}.`
if (group === 'data') description = 'Adjust initial sync and replication slot behavior.'
+ useEffect(() => {
+ if (revealInvalidSettings && advancedError) setExpanded('item-1')
+ }, [revealInvalidSettings, advancedError])
+
+ if (group === 'connection' && type !== 'BigQuery' && type !== 'DuckLake' && type !== 'Snowflake')
+ return null
+
return (
<div className={cn('w-full', group !== 'all' && 'border-t border-default')}>
- <Accordion type="single" collapsible>
+ <Accordion type="single" collapsible value={expanded} onValueChange={setExpanded}>
<AccordionItem value="item-1" className="border-none">
<AccordionTrigger className="font-normal gap-2 justify-between px-5 py-3 text-sm hover:no-underline">
<div className="flex flex-col items-start gap-0.5">
diff --git a/apps/studio/components/ui/SteppedFlow/SteppedFlow.tsx b/apps/studio/components/ui/SteppedFlow/SteppedFlow.tsx
index 961ec6491e6..a5d795bebe0 100644
--- a/apps/studio/components/ui/SteppedFlow/SteppedFlow.tsx
+++ b/apps/studio/components/ui/SteppedFlow/SteppedFlow.tsx
@@ -110,7 +110,10 @@ export const SteppedFlow = ({
>
{children}
<CardFooter
- className={cn(currentIndex > 0 || showCancel ? 'justify-between' : 'justify-end')}
+ className={cn(
+ 'border-t',
+ currentIndex > 0 || showCancel ? 'justify-between' : 'justify-end'
+ )}
>
{currentIndex > 0 ? (
<Button