Files
supabase/apps/studio/components/interfaces/Database/Replication/CreatePipeline/PipelineDataValidation.utils.ts
T
Danny White 25ede7243e feat(studio): validate pipeline wizard data settings (#51821)
## Problem

The pipeline wizard lets users reach Review without a valid publication
or initial-sync selection. This is a slice of #49243, following the
merged #51818.

## Solution

- Refresh publication metadata on **Continue** and reject unavailable
publications or removed initial-sync tables.
- Validate initial-sync and advanced data settings, reveal invalid
fields and preserve values for retry.
- Block browser-history shortcuts to Review after data settings change.

| Normal State | Error State (Expanded) |
| --- | --- |
| <img width="1486" height="1010" alt="CleanShot 2026-10-16 at 13 18
25@2x"
src="https://github.com/user-attachments/assets/74ec0785-3bd4-407a-aa3c-7fe69c338488"
/> | <img width="1506" height="2516" alt="CleanShot 2026-10-16 at 13 21
27@2x"
src="https://github.com/user-attachments/assets/6193d8c4-ab9d-47ca-9d9d-1a31198145d1"
/> |

Pipeline creation and navigation-out guards remain for later slices.
**Start pipeline** stays disabled.

## Review instructions

1. Open the [Pipelines
preview](https://studio-staging-git-dnywh-featpipeline-data-validation-supabase.vercel.app/dashboard/project/_/database/pipelines),
select a test project and enable **Pipeline creation wizard**. Open the
[wizard
preview](https://studio-staging-git-dnywh-featpipeline-data-validation-supabase.vercel.app/dashboard/project/_/database/pipelines/new),
choose a destination, then enter credentials and test the connection to
reach Data.
2. Click **Continue** without a publication. Check the field error.
Select a publication, choose a selective initial-sync mode and leave its
table selection empty. Check Continue requires at least one table.
Select a table and confirm you can reach Review.
3. Return to Data. Enter a negative **Batch wait time** under **Advanced
settings**, collapse it and click Continue. Check it reopens with the
error. Correct it and continue, then use browser Back, change a data
setting and try browser Forward. Check you stay on Data until you click
Continue again.
4. For a stale-selection check, select an initial-sync table, remove it
from the publication in another tab, then click Continue. Check the
selection is rejected and your other values remain. A failed metadata
request should also keep values and allow retry with Continue.
2026-10-19 10:32:09 +11:00

69 lines
2.4 KiB
TypeScript

import type { FieldPath } from 'react-hook-form'
import {
DestinationPanelFormSchema,
type DestinationPanelSchemaType,
} from '../DestinationPanel/DestinationForm/DestinationForm.schema'
import { buildTableSyncCopyConfig } from '../DestinationPanel/DestinationForm/DestinationForm.utils'
import type { ReplicationPublicationData } from '@/data/replication/publication-query'
const dataSchema = DestinationPanelFormSchema.pick({
publicationName: true,
tableSyncCopyMode: true,
tableSyncCopyTableIds: true,
maxFillMs: true,
maxTableSyncWorkers: true,
maxCopyConnectionsPerTable: true,
invalidatedSlotBehavior: true,
})
export const dataFieldNames = [...Object.keys(dataSchema.shape), 'tableOptions'].filter(
(name): name is keyof DestinationPanelSchemaType => name in DestinationPanelFormSchema.shape
)
export const getDataValidationIssues = (
data: DestinationPanelSchemaType,
type: string,
publication?: ReplicationPublicationData
) => {
const schema =
type === 'BigQuery'
? dataSchema.extend({ tableOptions: DestinationPanelFormSchema.shape.tableOptions })
: dataSchema
const result = schema.safeParse(data)
const issues = result.success
? []
: result.error.issues.map((issue) => ({
path: issue.path.join('.'),
message: issue.message,
}))
if (!publication || publication.name !== data.publicationName) {
issues.push({ path: 'publicationName', message: 'Select an available publication.' })
} else if (
data.tableSyncCopyMode === 'include_tables' ||
data.tableSyncCopyMode === 'skip_tables'
) {
try {
buildTableSyncCopyConfig({
mode: data.tableSyncCopyMode,
selectedTableIds: data.tableSyncCopyTableIds,
})
const ids = new Set(publication.tables.map(({ id }) => String(id)))
if (data.tableSyncCopyTableIds.some((id) => !ids.has(id))) {
issues.push({
path: 'tableSyncCopyTableIds',
message: 'Some selected tables are no longer in the publication. Update your selection.',
})
}
} catch (error) {
issues.push({
path: 'tableSyncCopyTableIds',
message: error instanceof Error ? error.message : 'Select initial sync tables.',
})
}
}
return issues.filter(
(issue): issue is { path: FieldPath<DestinationPanelSchemaType>; message: string } =>
issue.path.split('.')[0] in DestinationPanelFormSchema.shape
)
}