Files
Danny White d458429081 fix(studio): clarify pipeline validation feedback (#52055)
## Problem

Pipeline review shows validation failures below the cost estimate, far
from the settings that need changes. Publication-loading failures also
appear in several places with conflicting retry instructions.

## Solution

Attach full-width errors and warnings to their Connection or Data
sections. Keep the current scroll position and show description-only
guidance above the footer. Consolidate publication-loading failures into
one Data-step error with Continue to retry, preserving the existing
sheet behaviour.

_The main fix, spreading out the error and warnings to their respective
sections:_

| Before | After |
| --- | --- |
| <img width="1280" height="1522" alt="New Pipeline Supabase"
src="https://github.com/user-attachments/assets/36df1814-e73f-4440-b338-79b672431c60"
/> | <img width="1280" height="1522" alt="15619"
src="https://github.com/user-attachments/assets/08e39cdd-0e69-4318-b992-dfa81ad8a6c2"
/> |
| _All at bottom_ | _Attached to each section_ |

_Misc fixes for API blocks:_

| Before | After |
| --- | --- |
| <img width="1516" height="1350" alt="CleanShot 2026-10-21 at 15 19
24@2x"
src="https://github.com/user-attachments/assets/56ac9cf7-9c30-4129-8fbc-2708f35a51b9"
/> | <img width="1520" height="1232" alt="CleanShot 2026-10-21 at 15 22
56@2x"
src="https://github.com/user-attachments/assets/c4f4b039-38de-4af0-9bb9-b487ff6ddb63"
/> |

## To test

1. Enable **Pipeline creation wizard** in Feature Previews and open
`/project/<ref>/database/pipelines/new`. Complete Connection and Data to
reach Review.
2. In Chrome DevTools → Network, right-click a captured POST ending
`/replication/<ref>/destinations/validate` (Connection) or
`/replication/<ref>/pipelines/validate` (Data), then select **Override
content**. Reach Review before enabling the destination override. Keep
HTTP status **200** and save:

```json
{"validation_failures":[{"name":"Test validation issue","reason":"Test failure for the review screen.","failure_type":"critical"}]}
```

3. Click **Start pipeline**. Expect a flush Admonition at the bottom of
the matching section and danger guidance above the footer, without
automatic scrolling. Change `critical` to `warning` to check warning
guidance and **Start pipeline anyway**. Edit and retry to confirm values
persist.
4. On Data, block the GET ending
`/replication/v2/<ref>/sources/<id>/publications/<name>`. Expect one
flush publication-loading failure above the footer, including with
Advanced settings open. **Continue** retries; remove the block and retry
to recover.
5. Check desktop and phone widths. Stop before confirming creation, then
remove overrides and request blocks.
2026-10-22 00:07:06 +00:00

106 lines
3.9 KiB
TypeScript

import { useRef, useState } from 'react'
import { useWatch, type UseFormReturn } from 'react-hook-form'
import type { DestinationPanelSchemaType } from '../DestinationPanel/DestinationForm/DestinationForm.schema'
import { dataFieldNames, getDataValidationIssues } from './PipelineDataValidation.utils'
import { useReplicationPublicationNamesQuery } from '@/data/replication/publication-names-query'
import { useReplicationPublicationQuery } from '@/data/replication/publication-query'
export const usePipelineDataValidation = ({
projectRef,
sourceId,
type,
form,
}: {
projectRef?: string
sourceId?: number
type: string
form: UseFormReturn<DestinationPanelSchemaType>
}) => {
const values = useWatch({ control: form.control, name: dataFieldNames })
const publicationName = useWatch({ control: form.control, name: 'publicationName' })
const snapshot = JSON.stringify([type, ...values])
const currentSnapshot = useRef(snapshot)
currentSnapshot.current = snapshot
const [verifiedSnapshot, setVerifiedSnapshot] = useState<string>()
const [isValidatingData, setIsValidatingData] = useState(false)
const isValidatingRef = useRef(false)
const [dataErrorState, setDataErrorState] = useState<{ snapshot: string; message: string }>()
const setDataError = (message?: string) =>
setDataErrorState(message ? { snapshot, message } : undefined)
const dataError = dataErrorState?.snapshot === snapshot ? dataErrorState.message : undefined
const names = useReplicationPublicationNamesQuery({ projectRef, sourceId })
const publication = useReplicationPublicationQuery({ projectRef, sourceId, publicationName })
const isSelectedPublicationMissing =
names.isSuccess && !names.data.some(({ name }) => name === publicationName)
const hasPublicationLoadError =
!!publicationName && (names.isError || (publication.isError && !isSelectedPublicationMissing))
const isDataVerified =
verifiedSnapshot === JSON.stringify([snapshot, publication.data]) &&
names.isSuccess &&
publication.isSuccess &&
names.data.some(({ name }) => name === publicationName) &&
publication.data.name === publicationName
const validateData = async () => {
if (isValidatingRef.current) return false
form.clearErrors(dataFieldNames)
setDataError(undefined)
setVerifiedSnapshot(undefined)
isValidatingRef.current = true
setIsValidatingData(true)
try {
if (!projectRef || sourceId === undefined || !publicationName) {
form.setError('publicationName', { message: 'Select an available publication.' })
return false
}
const [freshNames, freshPublication] = await Promise.all([
names.refetch(),
publication.refetch(),
])
if (currentSnapshot.current !== snapshot) return false
if (freshNames.isSuccess && !freshNames.data.some(({ name }) => name === publicationName)) {
form.setError('publicationName', { message: 'Select an available publication.' })
form.setFocus('publicationName')
return false
}
if (freshNames.isError || freshPublication.isError) {
setDataError('Publication tables could not be loaded. Click Continue to try again.')
return false
}
const selected = freshNames.data?.some(({ name }) => name === publicationName)
? freshPublication.data
: undefined
const issues = getDataValidationIssues(form.getValues(), type, selected)
issues.forEach(({ path, message }) => form.setError(path, { type: 'validate', message }))
if (issues.length > 0) {
setDataError(issues[0].message)
form.setFocus(issues[0].path)
return false
}
setVerifiedSnapshot(JSON.stringify([snapshot, freshPublication.data]))
return true
} finally {
isValidatingRef.current = false
setIsValidatingData(false)
}
}
return {
validateData,
isValidatingData,
isDataVerified,
dataError,
hasPublicationLoadError,
publication: publication.data,
}
}