Files
Danny White 8dd97d75aa refactor(studio): use v2 replication publication APIs (#49844)
## What kind of change does this PR introduce?

Studio data-layer migration.

## What is the current behavior?

Studio loads complete publication details through the original bulk
endpoint and creates publications by executing SQL against the source
database. Publication and source-table data use names where stable table
IDs are available.

## What is the new behavior?

Uses the v2 publication-name, publication-detail, publication mutation,
and source-table endpoints. The existing creation sheet continues to
behave the same, including publishing partition changes through the
parent table by default. Initial-sync selection and Analytics Bucket
associations now consume the selected publication detail. Generated
platform API types and their required nullability updates are included.

The generated Platform contract accounts for roughly 10,000 changed
lines in this PR.

## Dependency

Depends on the v2 source table, table column, and publication endpoints
from
[supabase/platform#37505](https://github.com/supabase/platform/pull/37505),
which are deployed to production.

## To test

1. Open the pipeline creation sheet and select an existing publication.
2. Create a publication with mixed-case schema and table names, then
confirm the table names are shown while stable IDs are submitted.
3. Exercise all four initial-sync policies, including selecting
individual tables.
4. Reopen the publication and table selectors and confirm they refresh
without replacing populated options.
5. Edit and delete a publication.
6. Open an Analytics Bucket associated with a pipeline and confirm its
publication tables resolve correctly.
7. Confirm unlimited WAL retention renders as Unlimited on pipeline
status.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Improved replication publication setup with on-demand table loading,
refresh controls, clearer table labels, and streamlined publication
selection.
- Publication creation and updates now use the latest replication API
and table-based configurations.
- Added clearer handling for tables removed from publications, including
stale-selection warnings.

- **Bug Fixes**
- Prevented table selections from carrying over when switching
publications.
- Improved replication status displays when lag or WAL metrics are
unavailable.
- Updated replication deletion and table management for the latest API
behavior.

- **Tests**
- Expanded coverage for publication creation, table selection, stale
tables, loading states, and replication metrics.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-08 11:37:59 +10:00

137 lines
4.4 KiB
TypeScript

import { Info } from 'lucide-react'
import {
Badge,
cn,
Popover,
PopoverContent,
PopoverTrigger,
Tooltip,
TooltipContent,
TooltipTrigger,
} from 'ui'
import { SlotWalStatus } from './ReplicationPipelineStatus.types'
import { getWalStatusMeta, WAL_STATUS_LEGEND } from './ReplicationPipelineStatus.utils'
import { InlineLink } from '@/components/ui/InlineLink'
import { DOCS_URL } from '@/lib/constants'
export type SlotStatusContext = 'pipeline' | 'table'
const CONNECTION_TEXT: Record<SlotStatusContext, { active: string; inactive: string }> = {
pipeline: {
active: "This pipeline's replication slot is active and being used right now.",
inactive: "This pipeline's replication slot is not active right now.",
},
table: {
active: "This table's replication slot is active and being used right now.",
inactive: "This table's replication slot is not active right now.",
},
}
/**
* Colored badge for a slot's WAL status, with the plain-language meaning on hover.
* Pass `context="table"` in the per-table inline view to show table-specific descriptions.
*/
export const SlotStatusBadge = ({
status,
context = 'pipeline',
}: {
status?: SlotWalStatus | null
context?: SlotStatusContext
}) => {
const meta = getWalStatusMeta(status)
const description = context === 'table' ? meta.tableDescription : meta.description
return (
<Tooltip>
<TooltipTrigger asChild>
<Badge variant={meta.variant} className="cursor-default">
{meta.label}
</Badge>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-[260px]">
{description}
</TooltipContent>
</Tooltip>
)
}
/**
* Info button opening a legend that explains every possible slot status.
*/
export const SlotStatusLegend = () => {
return (
<Popover>
<PopoverTrigger asChild>
<button
type="button"
tabIndex={0}
aria-label="What do the slot statuses mean?"
className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-surface-200 text-foreground-lighter transition-colors hover:bg-surface-300 hover:text-foreground focus-ring"
>
<Info size={12} />
</button>
</PopoverTrigger>
<PopoverContent side="bottom" align="center" className="w-[26rem] p-0">
<div className="px-4 py-3 border-b border-overlay">
<p className="text-sm text-foreground">Slot statuses</p>
<p className="text-xs text-foreground-light">
How safely your database is keeping the changes the pipeline still needs.
</p>
</div>
<ul className="flex flex-col divide-y divide-overlay">
{WAL_STATUS_LEGEND.map((meta) => (
<li key={meta.label} className="flex items-start gap-x-3 px-4 py-2.5">
<div className="flex h-5 w-28 shrink-0 items-center">
<Badge variant={meta.variant}>{meta.label}</Badge>
</div>
<span className="flex-1 text-xs leading-5 text-foreground-light">
{meta.description}
</span>
</li>
))}
</ul>
<div className="border-t border-overlay px-4 py-2.5">
<InlineLink
href={`${DOCS_URL}/guides/database/replication/pipelines-monitoring`}
className="text-xs text-foreground-light"
>
Learn more about monitoring replication
</InlineLink>
</div>
</PopoverContent>
</Popover>
)
}
/**
* Small dot + label indicating whether the slot has a live replication connection.
* Pass `context="table"` in the per-table inline view to show table-specific descriptions.
*/
export const SlotConnectionIndicator = ({
isActive,
context = 'pipeline',
}: {
isActive?: boolean
context?: SlotStatusContext
}) => {
const text = CONNECTION_TEXT[context]
return (
<Tooltip>
<TooltipTrigger asChild>
<span className="flex items-center gap-x-1.5 text-xs text-foreground-light cursor-default">
<span
className={cn(
'h-1.5 w-1.5 rounded-full shrink-0',
isActive ? 'bg-brand' : 'bg-foreground-muted'
)}
/>
{isActive ? 'Connected' : 'Not connected'}
</span>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-[260px]">
{isActive ? text.active : text.inactive}
</TooltipContent>
</Tooltip>
)
}