Files
supabase/apps/studio/components/interfaces/Database/Replication/CreatePipeline/usePipelineCreationSubmission.ts
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

100 lines
3.0 KiB
TypeScript

import { useLayoutEffect, useRef, useState } from 'react'
import { useWatch, type UseFormReturn } from 'react-hook-form'
import {
DestinationPanelFormSchema,
type DestinationPanelSchemaType,
} from '../DestinationPanel/DestinationForm/DestinationForm.schema'
import { useDestinationForm } from '../DestinationPanel/DestinationForm/useDestinationForm'
import type { DestinationType } from '../DestinationPanel/DestinationPanel.types'
export const usePipelineCreationSubmission = ({
type,
form,
validateData,
onCreated,
}: {
type: DestinationType
form: UseFormReturn<DestinationPanelSchemaType>
validateData: () => Promise<boolean>
onCreated: () => void
}) => {
const {
validateConfiguration,
submitPipeline,
destinationValidationFailures,
pipelineValidationFailures,
resetValidation,
} = useDestinationForm({ selectedType: type })
const [isSubmitting, setIsSubmitting] = useState(false)
const isSubmittingRef = useRef(false)
const hasCreated = useRef(false)
const warningSnapshot = useRef<string | undefined>(undefined)
const values = useWatch({
control: form.control,
name: DestinationPanelFormSchema.keyof().options,
})
const configurationSnapshot = JSON.stringify([type, values])
const failures = [...destinationValidationFailures, ...pipelineValidationFailures]
const createPipeline = async (data: DestinationPanelSchemaType) => {
await submitPipeline({
data,
onSuccess: () => {},
// Wait for the start attempt before navigating: leaving the document earlier
// can interrupt its request. A committed create must never be retried here.
onClose: () => {
hasCreated.current = true
},
})
if (hasCreated.current) onCreated()
}
const runSubmission = async (action: () => Promise<void>) => {
if (isSubmittingRef.current) return
isSubmittingRef.current = true
setIsSubmitting(true)
try {
await action()
} finally {
if (!hasCreated.current) {
isSubmittingRef.current = false
setIsSubmitting(false)
}
}
}
const handleSubmit = () =>
runSubmission(async () => {
const data = form.getValues()
if (warningSnapshot.current === configurationSnapshot) {
await createPipeline(data)
return
}
resetValidation()
if (!(await validateData())) return
const result = await validateConfiguration({ data, onValidationFail: () => {} })
if (!result.canContinue) return
if (result.warnings.length > 0) {
warningSnapshot.current = configurationSnapshot
return
}
await createPipeline(data)
})
useLayoutEffect(() => {
resetValidation()
warningSnapshot.current = undefined
}, [configurationSnapshot, resetValidation])
return {
handleSubmit,
isSubmitting,
destinationValidationFailures,
pipelineValidationFailures,
submitLabel:
failures.length > 0 && failures.every(({ failure_type }) => failure_type === 'warning')
? 'Start pipeline anyway'
: 'Start pipeline',
}
}