The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
refactor(studio): share pipeline region and selection copy for wizard review (#51540)
Danny Whitef2d8eba7364d
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.test.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.test.tsnew file mode 100644index 00000000000..3aa7b939cb8--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.test.ts@@ -0,0 +1,14 @@+import { expect, it } from 'vitest'++import { getTableSyncSelectionDescription } from './DestinationFormFieldCopy'++it.each<{ mode: 'include_tables' | 'skip_tables'; action: string }>([+ { mode: 'include_tables', action: 'run' },+ { mode: 'skip_tables', action: 'skip' },+])('preserves the $mode selection description', ({ mode, action }) => {+ for (const selectedCount of [0, 2]) {+ expect(getTableSyncSelectionDescription({ mode, selectedCount, tableCount: 2 })).toBe(+ `${selectedCount} of 2 publication tables will ${action} initial sync. Ongoing replication will still include every publication table.`+ )+ }+})diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.tsindex 4f42eb2277f..642350fc9a4 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.ts+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationFormFieldCopy.ts@@ -69,3 +69,34 @@ export const CLICKHOUSE_ENGINE_FIELD_COPY = {label: 'Table engine',description: 'Controls how ClickHouse stores and queries replicated changes.',} as const++export const INITIAL_SYNC_LABELS = {+ include_all_tables: 'All tables',+ skip_all_tables: 'No tables',+ include_tables: 'Selected tables only',+ skip_tables: 'All except selected tables',+}++export const INITIAL_SYNC_FIELD_COPY = {+ label: 'Initial sync',+ description:+ 'Choose which publication tables sync their existing rows. Ongoing replication includes new changes from every publication table, even when initial sync is skipped.',+}++export const PUBLICATION_FIELD_COPY = {+ label: 'Publication',+ description: 'Tables in the selected publication will be replicated to this destination.',+}++export const getTableSyncSelectionDescription = ({+ mode,+ selectedCount,+ tableCount,+}: {+ mode: 'include_tables' | 'skip_tables'+ selectedCount: number+ tableCount: number+}) =>+ mode === 'skip_tables'+ ? `${selectedCount} of ${tableCount} publication tables will skip initial sync. Ongoing replication will still include every publication table.`+ : `${selectedCount} of ${tableCount} publication tables will run initial sync. Ongoing replication will still include every publication table.`diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.test.tsxindex 0afb0d83473..6f751d0a569 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.test.tsx+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.test.tsx@@ -5,6 +5,7 @@ import {getPipelineRegionDescription,PIPELINE_REGION,PipelineRegionField,+ PipelineRegionReadonly,} from './PipelineRegionField'import { customRender } from '@/tests/lib/custom-render'@@ -34,3 +35,12 @@ describe('PipelineRegionField', () => {expect(screen.queryByRole('combobox')).not.toBeInTheDocument()})})++test('reuses the region display without a form label or description', () => {+ customRender(<PipelineRegionReadonly className="w-full" />)+ expect(screen.getByText(PIPELINE_REGION.displayName)).toBeInTheDocument()+ expect(screen.getByText(PIPELINE_REGION.code)).toBeInTheDocument()+ expect(screen.queryByText('Pipeline region')).not.toBeInTheDocument()+ expect(screen.queryByRole('combobox')).not.toBeInTheDocument()+ expect(screen.getByText(PIPELINE_REGION.code).parentElement).toHaveClass('w-full', 'px-3')+})diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.tsxindex 9cd0941cbf9..a374b135bc9 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.tsx+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PipelineRegionField.tsx@@ -42,18 +42,22 @@ export const PipelineRegionField = ({label="Pipeline region"description={getPipelineRegionDescription(destinationType)}>- <div- className={cn(- 'flex h-9 min-w-0 items-center gap-x-2 rounded-md border bg-surface-200 px-3 text-sm',- className- )}- >- <RegionFlag className="w-5 shrink-0" region={PIPELINE_REGION.code} />- <span className="min-w-0 truncate text-foreground">{PIPELINE_REGION.displayName}</span>- <span className="shrink-0 font-mono text-xs text-foreground-lighter">- {PIPELINE_REGION.code}- </span>- </div>+ <PipelineRegionReadonly className={className} /></FormItemLayout>)}++export const PipelineRegionReadonly = ({ className }: { className?: string }) => (+ <div+ className={cn(+ 'flex h-9 min-w-0 items-center gap-x-2 rounded-md border bg-surface-200 px-3 text-sm',+ className+ )}+ >+ <RegionFlag className="w-5 shrink-0" region={PIPELINE_REGION.code} />+ <span className="min-w-0 truncate text-foreground">{PIPELINE_REGION.displayName}</span>+ <span className="shrink-0 font-mono text-xs text-foreground-lighter">+ {PIPELINE_REGION.code}+ </span>+ </div>+)diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsxindex 63afeaa54c3..6c9fcdd8df7 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/PublicationSelection.tsx@@ -5,6 +5,7 @@ import { Admonition } from 'ui-patterns/Admonition'import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import type { DestinationPanelSchemaType } from './DestinationForm.schema'+import { PUBLICATION_FIELD_COPY } from './DestinationFormFieldCopy'import { PublicationsComboBox } from './PublicationsComboBox'import { useReplicationPublicationNamesQuery } from '@/data/replication/publication-names-query'import { useReplicationPublicationQuery } from '@/data/replication/publication-query'@@ -56,7 +57,7 @@ export const PublicationSelection = ({}const publicationDescription = [- 'Tables in the selected publication will be replicated to this destination.',+ PUBLICATION_FIELD_COPY.description,isPartitionHandlingLoading ? 'Loading partition handling...' : partitionHandlingMessage,].filter(Boolean)@@ -69,7 +70,7 @@ export const PublicationSelection = ({render={({ field }) => (<FormItemLayoutlayout="horizontal"- label="Publication"+ label={PUBLICATION_FIELD_COPY.label}description={publicationDescription}><span role="status" className="sr-only">diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/TableCopySelection.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/TableCopySelection.tsxindex 1bd47525563..94cab32ce9f 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/TableCopySelection.tsx+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/TableCopySelection.tsx@@ -6,6 +6,11 @@ import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { MultiSelector } from 'ui-patterns/multi-select'import type { DestinationPanelSchemaType } from './DestinationForm.schema'+import {+ getTableSyncSelectionDescription,+ INITIAL_SYNC_FIELD_COPY,+ INITIAL_SYNC_LABELS,+} from './DestinationFormFieldCopy'import {isMetadataListErrorVisible,isMetadataListLoading,@@ -21,13 +26,6 @@ interface TableCopySelectionProps {editMode: boolean}-const INITIAL_SYNC_LABELS = {- include_all_tables: 'All tables',- skip_all_tables: 'No tables',- include_tables: 'Selected tables only',- skip_tables: 'All except selected tables',-}-const isSelectiveMode = (mode: DestinationPanelSchemaType['tableSyncCopyMode']) =>mode === 'include_tables' || mode === 'skip_tables'@@ -90,33 +88,33 @@ export const TableCopySelection = ({ form, editMode }: TableCopySelectionProps)render={({ field }) => (<FormItemLayoutlayout="horizontal"- label="Initial sync"- description="Choose which publication tables sync their existing rows. Ongoing replication includes new changes from every publication table, even when initial sync is skipped."+ label={INITIAL_SYNC_FIELD_COPY.label}+ description={INITIAL_SYNC_FIELD_COPY.description}><FormControl><Select value={field.value} onValueChange={field.onChange}><SelectTrigger>{INITIAL_SYNC_LABELS[field.value]}</SelectTrigger><SelectContent side="bottom" collisionPadding={16}><SelectItem value="include_all_tables" className="[&>span]:top-2.5">- <p>All tables</p>+ <p>{INITIAL_SYNC_LABELS.include_all_tables}</p><p className="text-foreground-lighter">Run initial sync for every publication table.</p></SelectItem><SelectItem value="skip_tables" className="[&>span]:top-2.5">- <p>All except selected tables</p>+ <p>{INITIAL_SYNC_LABELS.skip_tables}</p><p className="text-foreground-lighter">Skip initial sync for selected tables.</p></SelectItem><SelectItem value="include_tables" className="[&>span]:top-2.5">- <p>Selected tables only</p>+ <p>{INITIAL_SYNC_LABELS.include_tables}</p><p className="text-foreground-lighter">Run initial sync only for selected tables.</p></SelectItem><SelectItem value="skip_all_tables" className="[&>span]:top-2.5">- <p>No tables</p>+ <p>{INITIAL_SYNC_LABELS.skip_all_tables}</p><p className="text-foreground-lighter">Skip initial sync and replicate new changes only.</p>@@ -146,11 +144,11 @@ export const TableCopySelection = ({ form, editMode }: TableCopySelectionProps)label={`${tableSyncCopyMode === 'skip_tables' ? 'Tables to exclude' : 'Tables to include'}${editMode ? '*' : ''}`}- description={- tableSyncCopyMode === 'skip_tables'- ? `${selectedPublicationCount} of ${tableCount} publication tables will skip initial sync. Ongoing replication will still include every publication table.`- : `${selectedPublicationCount} of ${tableCount} publication tables will run initial sync. Ongoing replication will still include every publication table.`- }+ description={getTableSyncSelectionDescription({+ mode: tableSyncCopyMode === 'skip_tables' ? 'skip_tables' : 'include_tables',+ selectedCount: selectedPublicationCount,+ tableCount,+ })}><FormControl><MultiSelector