The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
refactor(studio): extract destination connection fields for wizard reuse (#51471)
Danny Whitea42433c9bdd2
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsxindex 996cb4366ee..8a339f5183d 100644--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx@@ -8,7 +8,6 @@ import {FormControl,FormField,FormInputGroupInput,- Input,InputGroup,InputGroupAddon,InputGroupText,@@ -20,15 +19,16 @@ import {import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import { DestinationType } from '../DestinationPanel.types'+import { BigQueryConnectionFields } from './BigQuery/ConnectionFields'import { TableOptions } from './BigQuery/TableOptions'import {- DEFAULT_CONNECTION_POOL_SIZE,- DEFAULT_DUCKLAKE_POOL_SIZE,DEFAULT_MAX_COPY_CONNECTIONS_PER_TABLE,DEFAULT_MAX_FILL_MS,DEFAULT_MAX_TABLE_SYNC_WORKERS,} from './DestinationForm.constants'import { type DestinationPanelSchemaType } from './DestinationForm.schema'+import { DuckLakeConnectionFields } from './DuckLake/ConnectionFields'+import { SnowflakeConnectionFields } from './Snowflake/ConnectionFields'const INVALIDATED_SLOT_BEHAVIOR_LABELS = {error: 'Block startup',@@ -63,31 +63,7 @@ export const AdvancedSettings = ({</div></AccordionTrigger><AccordionContent className="pb-0! pt-3 [&>div]:flex [&>div]:flex-col [&>div]:gap-y-4 [&>div]:px-5">- {type === 'DuckLake' && (- <FormField- control={form.control}- name="ducklakePoolSize"- render={({ field }) => (- <FormItemLayout- layout="horizontal"- label="Pool size"- description="Maximum concurrent connections this pipeline opens to the catalog. Choose 1 to 6."- >- <FormControl>- <Input- {...field}- type="number"- min={1}- max={6}- value={field.value ?? ''}- onChange={handleNumberChange(field)}- placeholder={String(DEFAULT_DUCKLAKE_POOL_SIZE)}- />- </FormControl>- </FormItemLayout>- )}- />- )}+ {type === 'DuckLake' && <DuckLakeConnectionFields control={form.control} />}<FormFieldcontrol={form.control}@@ -212,62 +188,7 @@ export const AdvancedSettings = ({{type === 'BigQuery' && (<>- <FormField- control={form.control}- name="connectionPoolSize"- render={({ field }) => (- <FormItemLayout- label="Connection pool size"- layout="horizontal"- description="Number of BigQuery connections used for destination writes."- >- <FormControl>- <InputGroup>- <FormInputGroupInput- {...field}- type="number"- min={1}- step={1}- value={field.value ?? ''}- onChange={handleNumberChange(field)}- placeholder={String(DEFAULT_CONNECTION_POOL_SIZE)}- />- <InputGroupAddon align="inline-end">- <InputGroupText>connections</InputGroupText>- </InputGroupAddon>- </InputGroup>- </FormControl>- </FormItemLayout>- )}- />-- <FormField- control={form.control}- name="maxStalenessMins"- render={({ field }) => (- <FormItemLayout- label="Maximum staleness"- layout="horizontal"- description="Maximum age of BigQuery query results for newly created or recreated tables; leave blank for the freshest results."- >- <FormControl>- <InputGroup>- <FormInputGroupInput- {...field}- type="number"- min={0}- step={1}- value={field.value ?? ''}- onChange={handleNumberChange(field)}- />- <InputGroupAddon align="inline-end">- <InputGroupText>minutes</InputGroupText>- </InputGroupAddon>- </InputGroup>- </FormControl>- </FormItemLayout>- )}- />+ <BigQueryConnectionFields control={form.control} /><div className="flex flex-col gap-y-3"><div className="flex flex-col gap-y-1">@@ -282,24 +203,7 @@ export const AdvancedSettings = ({</>)}- {type === 'Snowflake' && (- <FormField- control={form.control}- name="snowflakeRole"- render={({ field }) => (- <FormItemLayout- label="Role"- labelOptional="Optional"- layout="horizontal"- description="Role for SQL requests. Leave blank to use the service user’s default role."- >- <FormControl>- <Input {...field} placeholder="PIPELINES_ROLE" value={field.value ?? ''} />- </FormControl>- </FormItemLayout>- )}- />- )}+ {type === 'Snowflake' && <SnowflakeConnectionFields control={form.control} />}</AccordionContent></AccordionItem></Accordion>diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.test.tsxnew file mode 100644index 00000000000..106c9830c87--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.test.tsx@@ -0,0 +1,66 @@+import { fireEvent, screen, waitFor } from '@testing-library/react'+import { useForm } from 'react-hook-form'+import { Button, Form } from 'ui'+import { describe, expect, it, vi } from 'vitest'++import type { DestinationPanelSchemaType } from '../DestinationForm.schema'+import { BigQueryConnectionFields } from './ConnectionFields'+import { customRender } from '@/tests/lib/custom-render'++const TestForm = ({ onSubmit }: { onSubmit: (data: DestinationPanelSchemaType) => void }) => {+ const form = useForm<DestinationPanelSchemaType>({+ defaultValues: { connectionPoolSize: 5, maxStalenessMins: 0 },+ })+ return (+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)}>+ <BigQueryConnectionFields control={form.control} />+ <Button type="submit">Submit</Button>+ <Button type="button" onClick={() => form.reset()}>+ Reset+ </Button>+ </form>+ </Form>+ )+}++describe('BigQueryConnectionFields', () => {+ it('keeps both connection settings editable and submits their numeric values', async () => {+ const onSubmit = vi.fn()+ customRender(<TestForm onSubmit={onSubmit} />)+ const pool = screen.getByRole('spinbutton', { name: 'Connection pool size' })+ const staleness = screen.getByRole('spinbutton', { name: 'Maximum staleness' })+ expect(pool).toHaveValue(5)+ expect(staleness).toHaveValue(0)+ fireEvent.change(pool, { target: { value: '8' } })+ fireEvent.change(staleness, { target: { value: '30' } })+ fireEvent.click(screen.getByRole('button', { name: 'Submit' }))+ await waitFor(() =>+ expect(onSubmit).toHaveBeenCalledWith(+ { connectionPoolSize: 8, maxStalenessMins: 30 },+ expect.anything()+ )+ )+ })++ it('preserves empty values and restores defaults on reset', async () => {+ const onSubmit = vi.fn()+ customRender(<TestForm onSubmit={onSubmit} />)+ const pool = screen.getByRole('spinbutton', { name: 'Connection pool size' })+ const staleness = screen.getByRole('spinbutton', { name: 'Maximum staleness' })+ fireEvent.change(pool, { target: { value: '' } })+ fireEvent.change(staleness, { target: { value: '' } })+ expect(pool).toHaveValue(null)+ expect(staleness).toHaveValue(null)+ fireEvent.click(screen.getByRole('button', { name: 'Submit' }))+ await waitFor(() =>+ expect(onSubmit).toHaveBeenCalledWith(+ { connectionPoolSize: '', maxStalenessMins: '' },+ expect.anything()+ )+ )+ fireEvent.click(screen.getByRole('button', { name: 'Reset' }))+ expect(pool).toHaveValue(5)+ expect(staleness).toHaveValue(0)+ })+})diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.tsxnew file mode 100644index 00000000000..6c0384d7c30--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/ConnectionFields.tsx@@ -0,0 +1,87 @@+import type { ChangeEvent } from 'react'+import type { Control } from 'react-hook-form'+import {+ FormControl,+ FormField,+ FormInputGroupInput,+ InputGroup,+ InputGroupAddon,+ InputGroupText,+} from 'ui'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'++import { DEFAULT_CONNECTION_POOL_SIZE } from '../DestinationForm.constants'+import type { DestinationPanelSchemaType } from '../DestinationForm.schema'++export const BigQueryConnectionFields = ({+ control,+}: {+ control: Control<DestinationPanelSchemaType>+}) => {+ const handleNumberChange =+ (field: { onChange: (value: number | '') => void }) => (e: ChangeEvent<HTMLInputElement>) => {+ const parsed = e.target.valueAsNumber+ field.onChange(e.target.value === '' || Number.isNaN(parsed) ? '' : parsed)+ }++ return (+ <>+ <FormField+ control={control}+ name="connectionPoolSize"+ render={({ field }) => (+ <FormItemLayout+ label="Connection pool size"+ layout="horizontal"+ description="Number of BigQuery connections used for destination writes."+ >+ <FormControl>+ <InputGroup>+ <FormInputGroupInput+ {...field}+ type="number"+ min={1}+ step={1}+ value={field.value ?? ''}+ onChange={handleNumberChange(field)}+ placeholder={String(DEFAULT_CONNECTION_POOL_SIZE)}+ />+ <InputGroupAddon align="inline-end">+ <InputGroupText>connections</InputGroupText>+ </InputGroupAddon>+ </InputGroup>+ </FormControl>+ </FormItemLayout>+ )}+ />++ <FormField+ control={control}+ name="maxStalenessMins"+ render={({ field }) => (+ <FormItemLayout+ label="Maximum staleness"+ layout="horizontal"+ description="Maximum age of BigQuery query results for newly created or recreated tables; leave blank for the freshest results."+ >+ <FormControl>+ <InputGroup>+ <FormInputGroupInput+ {...field}+ type="number"+ min={0}+ step={1}+ value={field.value ?? ''}+ onChange={handleNumberChange(field)}+ />+ <InputGroupAddon align="inline-end">+ <InputGroupText>minutes</InputGroupText>+ </InputGroupAddon>+ </InputGroup>+ </FormControl>+ </FormItemLayout>+ )}+ />+ </>+ )+}diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ConnectionFields.test.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ConnectionFields.test.tsxnew file mode 100644index 00000000000..3f769056722--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/ConnectionFields.test.tsx@@ -0,0 +1,77 @@+import { fireEvent, screen, waitFor } from '@testing-library/react'+import { useForm } from 'react-hook-form'+import { Button, Form } from 'ui'+import { describe, expect, it, vi } from 'vitest'++import type { DestinationPanelSchemaType } from './DestinationForm.schema'+import { DuckLakeConnectionFields } from './DuckLake/ConnectionFields'+import { SnowflakeConnectionFields } from './Snowflake/ConnectionFields'+import { customRender } from '@/tests/lib/custom-render'++const cases = [+ {+ name: 'DuckLake',+ Component: DuckLakeConnectionFields,+ role: 'spinbutton',+ label: 'Pool size',+ defaultValues: { ducklakePoolSize: 2 },+ value: '4',+ expectedValues: { ducklakePoolSize: 4 },+ emptyValues: { ducklakePoolSize: '' },+ defaultValue: 2,+ },+ {+ name: 'Snowflake',+ Component: SnowflakeConnectionFields,+ role: 'textbox',+ label: 'Role',+ defaultValues: { snowflakeRole: 'PIPELINES_ROLE' },+ value: 'ANALYST',+ expectedValues: { snowflakeRole: 'ANALYST' },+ emptyValues: { snowflakeRole: '' },+ defaultValue: 'PIPELINES_ROLE',+ },+]++const TestForm = ({+ testCase,+ onSubmit,+}: {+ testCase: (typeof cases)[number]+ onSubmit: (data: DestinationPanelSchemaType) => void+}) => {+ const form = useForm<DestinationPanelSchemaType>({ defaultValues: testCase.defaultValues })+ const { Component } = testCase+ return (+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)}>+ <Component control={form.control} />+ <Button type="submit">Submit</Button>+ <Button type="button" onClick={() => form.reset()}>+ Reset+ </Button>+ </form>+ </Form>+ )+}++describe('destination connection fields', () => {+ it.each(cases)('$name preserves editing, empty values and reset', async (testCase) => {+ const onSubmit = vi.fn()+ customRender(<TestForm testCase={testCase} onSubmit={onSubmit} />)+ const input = screen.getByRole(testCase.role, { name: testCase.label })+ expect(input).toHaveValue(testCase.defaultValue)+ fireEvent.change(input, { target: { value: testCase.value } })+ fireEvent.click(screen.getByRole('button', { name: 'Submit' }))+ await waitFor(() =>+ expect(onSubmit).toHaveBeenLastCalledWith(testCase.expectedValues, expect.anything())+ )+ fireEvent.change(input, { target: { value: '' } })+ fireEvent.click(screen.getByRole('button', { name: 'Submit' }))+ await waitFor(() =>+ expect(onSubmit).toHaveBeenLastCalledWith(testCase.emptyValues, expect.anything())+ )+ fireEvent.click(screen.getByRole('button', { name: 'Reset' }))+ expect(input).toHaveValue(testCase.defaultValue)+ })+})diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DuckLake/ConnectionFields.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DuckLake/ConnectionFields.tsxnew file mode 100644index 00000000000..8d20b690a56--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DuckLake/ConnectionFields.tsx@@ -0,0 +1,45 @@+import type { ChangeEvent } from 'react'+import type { Control } from 'react-hook-form'+import { FormControl, FormField, Input } from 'ui'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'++import { DEFAULT_DUCKLAKE_POOL_SIZE } from '../DestinationForm.constants'+import type { DestinationPanelSchemaType } from '../DestinationForm.schema'++export const DuckLakeConnectionFields = ({+ control,+}: {+ control: Control<DestinationPanelSchemaType>+}) => {+ const handleNumberChange =+ (field: { onChange: (value: number | '') => void }) => (e: ChangeEvent<HTMLInputElement>) => {+ const parsed = e.target.valueAsNumber+ field.onChange(e.target.value === '' || Number.isNaN(parsed) ? '' : parsed)+ }++ return (+ <FormField+ control={control}+ name="ducklakePoolSize"+ render={({ field }) => (+ <FormItemLayout+ layout="horizontal"+ label="Pool size"+ description="Maximum concurrent connections this pipeline opens to the catalog. Choose 1 to 6."+ >+ <FormControl>+ <Input+ {...field}+ type="number"+ min={1}+ max={6}+ value={field.value ?? ''}+ onChange={handleNumberChange(field)}+ placeholder={String(DEFAULT_DUCKLAKE_POOL_SIZE)}+ />+ </FormControl>+ </FormItemLayout>+ )}+ />+ )+}diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/Snowflake/ConnectionFields.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/Snowflake/ConnectionFields.tsxnew file mode 100644index 00000000000..684c0e9b51e--- /dev/null+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/Snowflake/ConnectionFields.tsx@@ -0,0 +1,30 @@+import type { Control } from 'react-hook-form'+import { FormControl, FormField, Input } from 'ui'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'++import type { DestinationPanelSchemaType } from '../DestinationForm.schema'++export const SnowflakeConnectionFields = ({+ control,+}: {+ control: Control<DestinationPanelSchemaType>+}) => {+ return (+ <FormField+ control={control}+ name="snowflakeRole"+ render={({ field }) => (+ <FormItemLayout+ label="Role"+ labelOptional="Optional"+ layout="horizontal"+ description="Role for SQL requests. Leave blank to use the service user’s default role."+ >+ <FormControl>+ <Input {...field} placeholder="PIPELINES_ROLE" value={field.value ?? ''} />+ </FormControl>+ </FormItemLayout>+ )}+ />+ )+}