Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): allow pipeline number inputs to be cleared (#50078)

Danny White282a2a22cfc8
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
index 23b147e9699..13cfcbae2ac 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.tsx
@@ -40,9 +40,9 @@ export const AdvancedSettings = ({
form: UseFormReturn<DestinationPanelSchemaType>
}) => {
const handleNumberChange =
- (field: { onChange: (value?: number) => void }) => (e: ChangeEvent<HTMLInputElement>) => {
+ (field: { onChange: (value: number | '') => void }) => (e: ChangeEvent<HTMLInputElement>) => {
const parsed = e.target.valueAsNumber
- field.onChange(e.target.value === '' || Number.isNaN(parsed) ? undefined : parsed)
+ field.onChange(e.target.value === '' || Number.isNaN(parsed) ? '' : parsed)
}
return (
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/BigQuery.schema.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/BigQuery.schema.ts
index b6fa2279c49..1777eac3546 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/BigQuery.schema.ts
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/BigQuery/BigQuery.schema.ts
@@ -1,17 +1,29 @@
import * as z from 'zod'
+import {
+ optionalNumberInputSchema,
+ requiredNumberInputSchema,
+} from '../DestinationForm.schema.utils'
+
+const CONNECTION_POOL_SIZE_MIN_ERROR = 'Connection pool size must be greater than 0.'
+
export const BigQueryFormSchema = z.object({
projectId: z.string().optional(),
datasetId: z.string().optional(),
serviceAccountKey: z.string().optional(),
- connectionPoolSize: z
- .number()
- .int()
- .min(1, 'Connection pool size must be greater than 0.')
- .optional(),
- maxStalenessMins: z
- .number()
- .int('Maximum staleness must be a whole number of minutes.')
- .min(0, 'Maximum staleness must be 0 or greater.')
- .optional(),
+ connectionPoolSize: requiredNumberInputSchema(
+ z
+ .number({
+ required_error: CONNECTION_POOL_SIZE_MIN_ERROR,
+ invalid_type_error: CONNECTION_POOL_SIZE_MIN_ERROR,
+ })
+ .int()
+ .min(1, CONNECTION_POOL_SIZE_MIN_ERROR)
+ ),
+ maxStalenessMins: optionalNumberInputSchema(
+ z
+ .number()
+ .int('Maximum staleness must be a whole number of minutes.')
+ .min(0, 'Maximum staleness must be 0 or greater.')
+ ),
})
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.test.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.test.ts
index 374f82c22c2..7d9733fb255 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.test.ts
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.test.ts
@@ -7,9 +7,51 @@ const requiredFields = {
publicationName: 'analytics_publication',
tableSyncCopyMode: 'include_all_tables' as const,
tableSyncCopyTableIds: [],
+ maxFillMs: 10_000,
+ maxTableSyncWorkers: 4,
+ maxCopyConnectionsPerTable: 4,
+ connectionPoolSize: 4,
}
+const requiredNumberFields = [
+ { field: 'maxFillMs', message: 'Batch wait time must be 0 or greater.' },
+ { field: 'maxTableSyncWorkers', message: 'Max table sync workers must be greater than 0.' },
+ {
+ field: 'maxCopyConnectionsPerTable',
+ message: 'Max copy connections per table must be greater than 0.',
+ },
+ { field: 'connectionPoolSize', message: 'Connection pool size must be greater than 0.' },
+] as const
+
describe('DestinationPanelFormSchema', () => {
+ it.each(requiredNumberFields)('uses the existing error for an empty $field field', (testCase) => {
+ const result = DestinationPanelFormSchema.safeParse({
+ ...requiredFields,
+ [testCase.field]: '',
+ })
+
+ expect(result.success).toBe(false)
+ if (!result.success) expect(result.error.issues[0]?.message).toBe(testCase.message)
+ })
+
+ it.each(requiredNumberFields)('rejects a missing $field field', (testCase) => {
+ const { [testCase.field]: _omitted, ...rest } = requiredFields
+
+ const result = DestinationPanelFormSchema.safeParse(rest)
+
+ expect(result.success).toBe(false)
+ })
+
+ it('normalizes an empty maximum staleness to undefined', () => {
+ const result = DestinationPanelFormSchema.safeParse({
+ ...requiredFields,
+ maxStalenessMins: '',
+ })
+
+ expect(result.success).toBe(true)
+ if (result.success) expect(result.data.maxStalenessMins).toBeUndefined()
+ })
+
it.each([0, 1])('accepts a batch wait time of %i milliseconds', (value) => {
const result = DestinationPanelFormSchema.safeParse({
...requiredFields,
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.ts
index dd260642b0f..0ecadb896d0 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.ts
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.ts
@@ -3,9 +3,14 @@ import * as z from 'zod'
import { AnalyticsBucketFormSchema } from './AnalyticsBucket/AnalyticsBucket.schema'
import { BigQueryFormSchema } from './BigQuery/BigQuery.schema'
import { ClickHouseFormSchema } from './ClickHouse/ClickHouse.schema'
+import { requiredNumberInputSchema } from './DestinationForm.schema.utils'
import { DuckLakeFormSchema } from './DuckLake/DuckLake.schema'
import { SnowflakeFormSchema } from './Snowflake/Snowflake.schema'
+const BATCH_WAIT_TIME_MIN_ERROR = 'Batch wait time must be 0 or greater.'
+const MAX_TABLE_SYNC_WORKERS_MIN_ERROR = 'Max table sync workers must be greater than 0.'
+const MAX_COPY_CONNECTIONS_MIN_ERROR = 'Max copy connections per table must be greater than 0.'
+
const CommonFormSchema = z.object({
name: z.string().min(1, 'Name is required.'),
publicationName: z.string().min(1, 'Publication is required.'),
@@ -16,21 +21,33 @@ const CommonFormSchema = z.object({
'skip_tables',
]),
tableSyncCopyTableIds: z.array(z.string()),
- maxFillMs: z
- .number()
- .int('Batch wait time must be a whole number of milliseconds.')
- .min(0, 'Batch wait time must be 0 or greater.')
- .optional(),
- maxTableSyncWorkers: z
- .number()
- .min(1, 'Max table sync workers must be greater than 0.')
- .int('Max table sync workers must be a whole number.')
- .optional(),
- maxCopyConnectionsPerTable: z
- .number()
- .int()
- .min(1, 'Max copy connections per table must be greater than 0.')
- .optional(),
+ maxFillMs: requiredNumberInputSchema(
+ z
+ .number({
+ required_error: BATCH_WAIT_TIME_MIN_ERROR,
+ invalid_type_error: BATCH_WAIT_TIME_MIN_ERROR,
+ })
+ .int('Batch wait time must be a whole number of milliseconds.')
+ .min(0, BATCH_WAIT_TIME_MIN_ERROR)
+ ),
+ maxTableSyncWorkers: requiredNumberInputSchema(
+ z
+ .number({
+ required_error: MAX_TABLE_SYNC_WORKERS_MIN_ERROR,
+ invalid_type_error: MAX_TABLE_SYNC_WORKERS_MIN_ERROR,
+ })
+ .min(1, MAX_TABLE_SYNC_WORKERS_MIN_ERROR)
+ .int('Max table sync workers must be a whole number.')
+ ),
+ maxCopyConnectionsPerTable: requiredNumberInputSchema(
+ z
+ .number({
+ required_error: MAX_COPY_CONNECTIONS_MIN_ERROR,
+ invalid_type_error: MAX_COPY_CONNECTIONS_MIN_ERROR,
+ })
+ .int()
+ .min(1, MAX_COPY_CONNECTIONS_MIN_ERROR)
+ ),
invalidatedSlotBehavior: z.enum(['error', 'recreate']).optional(),
})
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.utils.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.utils.ts
new file mode 100644
index 00000000000..68bc432320a
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema.utils.ts
@@ -0,0 +1,7 @@
+import * as z from 'zod'
+
+export const requiredNumberInputSchema = (schema: z.ZodNumber) =>
+ z.preprocess((value) => (value === '' ? Number.NaN : value), schema)
+
+export const optionalNumberInputSchema = (schema: z.ZodNumber) =>
+ z.preprocess((value) => (value === '' ? undefined : value), schema.optional())
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.utils.test.ts b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.utils.test.ts
index 1e69cba9d97..1d5cf152e3a 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.utils.test.ts
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.utils.test.ts
@@ -22,14 +22,14 @@ const baseDucklakeFormData = {
publicationName: 'pub',
tableSyncCopyMode: 'include_all_tables' as const,
tableSyncCopyTableIds: [],
- maxFillMs: undefined,
- maxTableSyncWorkers: undefined,
- maxCopyConnectionsPerTable: undefined,
+ maxFillMs: 500,
+ maxTableSyncWorkers: 1,
+ maxCopyConnectionsPerTable: 1,
invalidatedSlotBehavior: undefined,
projectId: undefined,
datasetId: undefined,
serviceAccountKey: undefined,
- connectionPoolSize: undefined,
+ connectionPoolSize: 1,
maxStalenessMins: undefined,
warehouseName: undefined,
namespace: undefined,
@@ -55,14 +55,14 @@ const baseSnowflakeFormData = {
publicationName: 'pub',
tableSyncCopyMode: 'include_all_tables' as const,
tableSyncCopyTableIds: [],
- maxFillMs: undefined,
- maxTableSyncWorkers: undefined,
- maxCopyConnectionsPerTable: undefined,
+ maxFillMs: 500,
+ maxTableSyncWorkers: 1,
+ maxCopyConnectionsPerTable: 1,
invalidatedSlotBehavior: undefined,
projectId: undefined,
datasetId: undefined,
serviceAccountKey: undefined,
- connectionPoolSize: undefined,
+ connectionPoolSize: 1,
maxStalenessMins: undefined,
warehouseName: undefined,
namespace: undefined,
@@ -204,14 +204,14 @@ const baseClickHouseFormData = {
publicationName: 'pub',
tableSyncCopyMode: 'include_all_tables' as const,
tableSyncCopyTableIds: [],
- maxFillMs: undefined,
- maxTableSyncWorkers: undefined,
- maxCopyConnectionsPerTable: undefined,
+ maxFillMs: 500,
+ maxTableSyncWorkers: 1,
+ maxCopyConnectionsPerTable: 1,
invalidatedSlotBehavior: undefined,
projectId: undefined,
datasetId: undefined,
serviceAccountKey: undefined,
- connectionPoolSize: undefined,
+ connectionPoolSize: 1,
maxStalenessMins: undefined,
warehouseName: undefined,
namespace: undefined,
diff --git a/apps/studio/tests/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.test.tsx b/apps/studio/tests/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.test.tsx
new file mode 100644
index 00000000000..ea786aad869
--- /dev/null
+++ b/apps/studio/tests/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings.test.tsx
@@ -0,0 +1,86 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { screen, waitFor } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { useForm } from 'react-hook-form'
+import { Form } from 'ui'
+import { describe, expect, it } from 'vitest'
+
+import { AdvancedSettings } from '@/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/AdvancedSettings'
+import {
+ DestinationPanelFormSchema,
+ type DestinationPanelSchemaType,
+} from '@/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/DestinationForm.schema'
+import { customRender } from '@/tests/lib/custom-render'
+
+const numericFields = [
+ { label: 'Batch wait time', initialValue: 10_000 },
+ { label: 'Table sync workers', initialValue: 4 },
+ { label: 'Initial sync connections per table', initialValue: 4 },
+ { label: 'Connection pool size', initialValue: 4 },
+ { label: 'Maximum staleness', initialValue: 10 },
+]
+
+const TestForm = () => {
+ const form = useForm<DestinationPanelSchemaType>({
+ resolver: zodResolver(DestinationPanelFormSchema),
+ mode: 'onChange',
+ reValidateMode: 'onChange',
+ defaultValues: {
+ name: 'Warehouse',
+ publicationName: 'publication',
+ tableSyncCopyMode: 'include_all_tables',
+ tableSyncCopyTableIds: [],
+ maxFillMs: 10_000,
+ maxTableSyncWorkers: 4,
+ maxCopyConnectionsPerTable: 4,
+ connectionPoolSize: 4,
+ maxStalenessMins: 10,
+ },
+ })
+ return (
+ <Form {...form}>
+ <AdvancedSettings type="BigQuery" form={form} />
+ </Form>
+ )
+}
+
+describe('AdvancedSettings', () => {
+ it.each(numericFields)(
+ 'allows $label to be cleared and replaced',
+ async ({ label, initialValue }) => {
+ const user = userEvent.setup()
+ customRender(<TestForm />)
+
+ await user.click(screen.getByRole('button', { name: /Advanced settings/ }))
+
+ const input = screen.getByRole('spinbutton', { name: label })
+ expect(input).toHaveValue(initialValue)
+
+ await user.clear(input)
+ expect(input).toHaveValue(null)
+
+ await user.type(input, '5')
+ expect(input).toHaveValue(5)
+ }
+ )
+
+ it('uses the existing error while an empty required number is being edited', async () => {
+ const user = userEvent.setup()
+ customRender(<TestForm />)
+
+ await user.click(screen.getByRole('button', { name: /Advanced settings/ }))
+ const input = screen.getByRole('spinbutton', { name: 'Table sync workers' })
+
+ await user.clear(input)
+ expect(
+ await screen.findByText('Max table sync workers must be greater than 0.')
+ ).toBeInTheDocument()
+
+ await user.type(input, '5')
+ await waitFor(() => {
+ expect(
+ screen.queryByText('Max table sync workers must be greater than 0.')
+ ).not.toBeInTheDocument()
+ })
+ })
+})