mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Pipeline review permits starting before the initial cost estimate finishes. Estimate failures and background refresh errors also need to preserve a usable review state. ## Solution Share cost-query state between the wizard and cost display. Disable **Start pipeline** only until the first estimate attempt finishes. After its first failure, show a flush, description-only note and permit starting while retries continue. Retain cached estimates if a background refresh fails, and announce unavailable estimates through a persistent status region. _All “After” states for Review step:_ | Loading | Loaded | Failed | | --- | --- | --- | | <img width="1024" height="686" alt="31887" src="https://github.com/user-attachments/assets/80b8623e-65ab-4bbb-8fcf-1e5e29a0dcd5" /> | <img width="1024" height="686" alt="New Pipeline Supabase" src="https://github.com/user-attachments/assets/ce49550c-d8cf-42b3-98f3-4520ae6b1229" /> | <img width="1024" height="686" alt="62823" src="https://github.com/user-attachments/assets/958b2bb3-e7ee-4214-b900-2e634adca05f" /> | ## To test 1. Enable **Pipeline creation wizard** in Feature Previews and open `/project/<ref>/database/pipelines/new`. Complete Connection and Data to reach Review. With network throttling, **Start pipeline** stays disabled during the initial estimate request; **Back** remains available. 2. Filter Network for `cost-estimate`. Block the GET ending `/replication/<ref>/sources/<id>/publications/<name>/cost-estimate`, then reload and complete the wizard again to clear the in-memory estimate cache. After the first failed request, expect “A cost estimate is unavailable. You can still start the pipeline.” in a full-width note, and an enabled **Start pipeline**. 3. Remove the block and obtain an estimate. Block the request again, go Back and return to Review. A failed background refresh should retain the cached numbers and allow starting. 4. Check desktop and phone widths. Stop before creating the pipeline and remove the request block. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useWatch, type Control } from 'react-hook-form'
|
|
|
|
import type { DestinationPanelSchemaType } from '../DestinationPanel/DestinationForm/DestinationForm.schema'
|
|
import { buildTableSyncCopyConfig } from '../DestinationPanel/DestinationForm/DestinationForm.utils'
|
|
import {
|
|
useReplicationCostEstimateQuery,
|
|
type ReplicationCostEstimateData,
|
|
} from '@/data/replication/cost-estimate-query'
|
|
import type { ReplicationPublicationData } from '@/data/replication/publication-query'
|
|
import { useReplicationSourceId } from '@/data/replication/sources-query'
|
|
import type { TableSyncCopyConfig } from '@/data/replication/types'
|
|
|
|
type PipelineReviewCostsState = { isInitialCostEstimateLoading: boolean } & (
|
|
| { status: 'missing-publication' }
|
|
| { status: 'missing-selection' }
|
|
| {
|
|
status: 'estimate'
|
|
estimate?: ReplicationCostEstimateData
|
|
publicationTables: ReplicationPublicationData['tables']
|
|
tableSyncCopy: TableSyncCopyConfig
|
|
}
|
|
)
|
|
|
|
const getTableSyncCopy = (
|
|
params: Parameters<typeof buildTableSyncCopyConfig>[0]
|
|
): TableSyncCopyConfig | undefined => {
|
|
try {
|
|
return buildTableSyncCopyConfig(params)
|
|
} catch {
|
|
// An incomplete initial sync selection has no estimate to request.
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export const usePipelineReviewCosts = ({
|
|
control,
|
|
publication,
|
|
enabled = true,
|
|
}: {
|
|
control: Control<DestinationPanelSchemaType>
|
|
publication?: ReplicationPublicationData
|
|
enabled?: boolean
|
|
}): PipelineReviewCostsState => {
|
|
const { ref: projectRef } = useParams()
|
|
const sourceId = useReplicationSourceId({ projectRef })
|
|
const [publicationName, mode, ids] = useWatch({
|
|
control,
|
|
name: ['publicationName', 'tableSyncCopyMode', 'tableSyncCopyTableIds'],
|
|
})
|
|
const hasPublication = !!publicationName && publication?.name === publicationName
|
|
|
|
const tableSyncCopy = getTableSyncCopy({ mode, selectedTableIds: ids })
|
|
|
|
const isEstimateEnabled = enabled && hasPublication && tableSyncCopy !== undefined
|
|
const { data, isLoading, failureCount, errorUpdateCount } = useReplicationCostEstimateQuery(
|
|
{ projectRef, sourceId, publicationName },
|
|
{ enabled: isEstimateEnabled }
|
|
)
|
|
const isInitialCostEstimateLoading =
|
|
isEstimateEnabled && isLoading && failureCount === 0 && errorUpdateCount === 0
|
|
|
|
if (!hasPublication) return { status: 'missing-publication', isInitialCostEstimateLoading: false }
|
|
if (tableSyncCopy === undefined)
|
|
return { status: 'missing-selection', isInitialCostEstimateLoading: false }
|
|
|
|
return {
|
|
status: 'estimate',
|
|
isInitialCostEstimateLoading,
|
|
estimate: data,
|
|
publicationTables: publication.tables,
|
|
tableSyncCopy,
|
|
}
|
|
}
|