import { Link } from '@tanstack/react-router' import { useParams } from 'common' import { Button } from 'ui' import { Admonition } from 'ui-patterns/Admonition' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import { isWarehouseProvisioned, isWarehouseSettingUp, type WarehouseSetupStatus, } from '../Integrations/Warehouse/Warehouse.utils' import { WarehouseConnectionCard } from '../Integrations/Warehouse/WarehouseConnectSection' import { AlertError } from '@/components/ui/AlertError' import { checkLocalPipelinesNotSetUp } from '@/data/replication/utils' import { useWarehouseSetupStatusQuery } from '@/data/warehouse/warehouse-setup-status-query' const getNotProvisionedContent = (setupStatus?: WarehouseSetupStatus) => { if (isWarehouseSettingUp(setupStatus)) { return { type: 'default' as const, title: 'Warehouse is being set up', description: 'Connection details appear here once the first backfill finishes.', action: 'View progress', } } if (setupStatus === 'error') { return { type: 'warning' as const, title: 'Warehouse setup failed', description: 'Review the error and retry setup to get connection details.', action: 'View Warehouse', } } return { type: 'default' as const, title: 'Warehouse is not set up', description: 'Choose which schemas or tables to replicate in order to connect to Warehouse.', action: 'Choose tables', } } /** * Read-only view of the Warehouse connection details. Setting Warehouse up, changing which tables * replicate, and disabling it all live on the Warehouse integration instead. */ export const WarehouseTab = () => { const { ref: projectRef } = useParams() const { data, isPending, isFetching, isError, error, refetch } = useWarehouseSetupStatusQuery({ projectRef, }) const hasLiveTables = data?.tables.some((table) => table.state === 'live') ?? false const canShowConnectionDetails = data?.setup_status !== 'error' && (isWarehouseProvisioned(data?.setup_status) || hasLiveTables) let content: React.ReactNode if (isPending) content = // Warehouse rides on the replication API, which isn't wired up in local development. Same // treatment Pipelines gives it, so a local dev doesn't read this as a broken build. else if (isError && checkLocalPipelinesNotSetUp(error)) { content = ( ) } else if (isError) { content = ( refetch()}> Retry } /> ) } else if (!canShowConnectionDetails) { const { type, title, description, action } = getNotProvisionedContent(data?.setup_status) content = ( {action} , ]} /> ) } else { return (
{isWarehouseSettingUp(data?.setup_status) && (
View progress , ]} />
)}
) } return
{content}
}