Skip to content

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

fix: number inputs does not allow some editions (#46538)

Gildas Garcia1150d32462ac
diff --git a/apps/design-system/registry/default/example/form-patterns-pagelayout.tsx b/apps/design-system/registry/default/example/form-patterns-pagelayout.tsx
index 5fa534c4054..20cd3d30009 100644
--- a/apps/design-system/registry/default/example/form-patterns-pagelayout.tsx
+++ b/apps/design-system/registry/default/example/form-patterns-pagelayout.tsx
@@ -57,7 +57,15 @@ const formSchema = z
.object({
name: z.string().min(1, 'Name is required'),
description: z.string().optional(),
- maxConnections: z.number().min(1).max(1000),
+ maxConnections: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .gte(1000, 'Max connections should be at least 1000')
+ .lte(10000, 'Max connections should not exceed 10000'),
+ ])
+ .refine((value) => value !== '', 'Max connections is required'),
enableFeature: z.boolean(),
enableRls: z.boolean(),
enableNotifications: z.boolean(),
@@ -67,7 +75,15 @@ const formSchema = z
queueType: z.enum(['basic', 'partitioned']),
expiryDate: z.date().optional(),
password: z.string().min(8, 'Password must be at least 8 characters'),
- duration: z.number().min(5).max(30),
+ duration: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .gte(1000, 'Duration should be at least 5ms')
+ .lte(10000, 'Duration should not exceed 30ms'),
+ ])
+ .refine((value) => value !== '', 'Duration is required'),
redirectUris: z.array(z.object({ value: z.string().url('Must be a valid URL') })),
httpHeaders: z.array(z.object({ key: z.string().trim(), value: z.string().trim() })),
apiKey: z.string().optional(),
@@ -211,13 +227,7 @@ export default function FormPatternsPageLayout() {
description="Numeric input with min/max validation"
>
<FormControl>
- <Input
- {...field}
- type="number"
- min={1}
- max={1000}
- onChange={(e) => field.onChange(Number(e.target.value))}
- />
+ <Input {...field} type="number" min={1} max={1000} />
</FormControl>
</FormItemLayout>
)}
@@ -237,15 +247,9 @@ export default function FormPatternsPageLayout() {
>
<FormControl>
<InputGroup>
- <FormInputGroupInput
- {...field}
- onChange={(e) => field.onChange(Number(e.target.value))}
- type="number"
- min={5}
- max={30}
- />
+ <FormInputGroupInput {...field} type="number" min={5} max={30} />
<InputGroupAddon align="inline-end">
- <InputGroupText className="font-mono">MB</InputGroupText>
+ <InputGroupText className="font-mono">ms</InputGroupText>
</InputGroupAddon>
</InputGroup>
</FormControl>
diff --git a/apps/design-system/registry/default/example/form-patterns-sidepanel.tsx b/apps/design-system/registry/default/example/form-patterns-sidepanel.tsx
index 41e6c2c18a3..15b907d6195 100644
--- a/apps/design-system/registry/default/example/form-patterns-sidepanel.tsx
+++ b/apps/design-system/registry/default/example/form-patterns-sidepanel.tsx
@@ -54,7 +54,15 @@ const formSchema = z
.object({
name: z.string().min(1, 'Name is required'),
description: z.string().optional(),
- maxConnections: z.number().min(1).max(1000),
+ maxConnections: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .gte(1000, 'Max connections should be at least 1000')
+ .lte(10000, 'Max connections should not exceed 10000'),
+ ])
+ .refine((value) => value !== '', 'Max connections is required'),
enableFeature: z.boolean(),
enableRls: z.boolean(),
enableNotifications: z.boolean(),
@@ -64,7 +72,15 @@ const formSchema = z
queueType: z.enum(['basic', 'partitioned']),
expiryDate: z.date().optional(),
password: z.string().min(8, 'Password must be at least 8 characters'),
- duration: z.number().min(5).max(30),
+ duration: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .gte(1000, 'Duration should be at least 5ms')
+ .lte(10000, 'Duration should not exceed 30ms'),
+ ])
+ .refine((value) => value !== '', 'Duration is required'),
redirectUris: z.array(z.object({ value: z.string().url('Must be a valid URL') })),
httpHeaders: z.array(z.object({ key: z.string().trim(), value: z.string().trim() })),
apiKey: z.string().optional(),
@@ -223,13 +239,7 @@ export default function FormPatternsSidePanel() {
description="Numeric input with min/max validation"
>
<FormControl className="col-span-6">
- <Input
- {...field}
- type="number"
- min={1}
- max={1000}
- onChange={(e) => field.onChange(Number(e.target.value))}
- />
+ <Input {...field} type="number" min={1} max={1000} />
</FormControl>
</FormItemLayout>
)}
@@ -253,7 +263,7 @@ export default function FormPatternsSidePanel() {
<InputGroup>
<FormInputGroupInput {...field} type="number" min={5} max={30} />
<InputGroupAddon align="inline-end">
- <InputGroupText>MB</InputGroupText>
+ <InputGroupText>ms</InputGroupText>
</InputGroupAddon>
</InputGroup>
</FormControl>
diff --git a/apps/studio/components/interfaces/Database/Hooks/EditHookPanel.constants.ts b/apps/studio/components/interfaces/Database/Hooks/EditHookPanel.constants.ts
index 8bd6940af1b..d0ed279e3e2 100644
--- a/apps/studio/components/interfaces/Database/Hooks/EditHookPanel.constants.ts
+++ b/apps/studio/components/interfaces/Database/Hooks/EditHookPanel.constants.ts
@@ -57,11 +57,15 @@ export const FormSchema = z
name: z.string().min(1, 'Please provide a name for your webhook'),
table_id: z.string().min(1, 'Please select a table'),
http_method: z.enum(['GET', 'POST']),
- timeout_ms: z.coerce
- .number()
- .int()
- .gte(1000, 'Timeout should be at least 1000ms')
- .lte(10000, 'Timeout should not exceed 10,000ms'),
+ timeout_ms: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .gte(1000, 'Timeout should be at least 1000ms')
+ .lte(10000, 'Timeout should not exceed 10,000ms'),
+ ])
+ .refine((value) => value !== '', 'Timeout is required'),
events: z.array(z.string()).min(1, 'Please select at least one event'),
httpHeaders: httpHeadersSchema,
httpParameters: httpParametersSchema,
diff --git a/apps/studio/components/interfaces/Database/Hooks/HTTPRequestConfig.tsx b/apps/studio/components/interfaces/Database/Hooks/HTTPRequestConfig.tsx
index 2ff55686dbf..a52184fc84f 100644
--- a/apps/studio/components/interfaces/Database/Hooks/HTTPRequestConfig.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/HTTPRequestConfig.tsx
@@ -144,12 +144,7 @@ export const HTTPRequestConfig = ({ form }: HTTPRequestConfigProps) => {
>
<FormControl>
<div className="relative">
- <Input
- {...field}
- type="number"
- onChange={(e) => field.onChange(Number(e.target.value))}
- className="pr-10"
- />
+ <Input {...field} type="number" className="pr-10" />
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-foreground-light text-sm">
ms
</span>
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
index 9749d72a3c2..4954e2d0d7f 100644
--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
@@ -58,8 +58,14 @@ const formSchema = z.object({
// Fields for updatePostgrestConfig
dbSchema: z.array(z.string()),
dbExtraSearchPath: z.array(z.string()),
- maxRows: z.number().max(1000000, "Can't be more than 1,000,000"),
- dbPool: z
+ maxRows: z
+ .union([
+ z.literal(''),
+ z.coerce.number().int().min(1).max(1000000, "Can't be more than 1,000,000"),
+ ])
+ .refine((value) => value !== '', 'Max rows is required')
+ .transform((value) => Number(value)),
+ dbPool: z.coerce
.number()
.min(0, 'Must be more than 0')
.max(1000, "Can't be more than 1000")
@@ -511,7 +517,6 @@ export const PostgrestConfig = () => {
disabled={!canUpdatePostgrestConfig}
{...field}
type="number"
- onChange={(e) => field.onChange(Number(e.target.value))}
/>
<InputGroupAddon align="inline-end">
<InputGroupText>rows</InputGroupText>
diff --git a/apps/studio/components/interfaces/Settings/Database/DiskSizeConfigurationModal.tsx b/apps/studio/components/interfaces/Settings/Database/DiskSizeConfigurationModal.tsx
index 37122e8b739..4ae2e8c5a9d 100644
--- a/apps/studio/components/interfaces/Settings/Database/DiskSizeConfigurationModal.tsx
+++ b/apps/studio/components/interfaces/Settings/Database/DiskSizeConfigurationModal.tsx
@@ -98,11 +98,19 @@ const DiskSizeConfigurationModal = ({
const diskSizeValidationSchema = useMemo(
() =>
z.object({
- 'new-disk-size': z.coerce
- .number({ required_error: 'Please enter a GB amount you want to resize the disk up to.' })
- .min(Number(currentDiskSize ?? 0), `Must be at least ${currentDiskSize} GB`)
- // to do, update with max_disk_volume_size_gb
- .max(Number(maxDiskSize), `Must not be more than ${maxDiskSize} GB`),
+ 'new-disk-size': z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .min(Number(currentDiskSize ?? 0), `Must be at least ${currentDiskSize} GB`)
+ // to do, update with max_disk_volume_size_gb
+ .max(Number(maxDiskSize), `Must not be more than ${maxDiskSize} GB`),
+ ])
+ .refine(
+ (value) => value !== '',
+ 'Please enter a GB amount you want to resize the disk up to'
+ ),
}),
[currentDiskSize]
)
@@ -199,12 +207,7 @@ const DiskSizeConfigurationModal = ({
>
<FormControl>
<InputGroup>
- <FormInputGroupInput
- {...field}
- id="new-disk-size"
- type="number"
- onChange={(e) => field.onChange(Number(e.target.value))}
- />
+ <FormInputGroupInput {...field} id="new-disk-size" type="number" />
<InputGroupAddon align="inline-end">
<InputGroupText>GB</InputGroupText>
</InputGroupAddon>
diff --git a/apps/studio/components/interfaces/Settings/Database/NetworkRestrictions/AddRestrictionModal.tsx b/apps/studio/components/interfaces/Settings/Database/NetworkRestrictions/AddRestrictionModal.tsx
index 59e30653b91..06a417f07ae 100644
--- a/apps/studio/components/interfaces/Settings/Database/NetworkRestrictions/AddRestrictionModal.tsx
+++ b/apps/studio/components/interfaces/Settings/Database/NetworkRestrictions/AddRestrictionModal.tsx
@@ -65,13 +65,18 @@ const AddRestrictionModal = ({
type === 'IPv4' ? IPV4_MAX_CIDR_BLOCK_SIZE : IPV6_MAX_CIDR_BLOCK_SIZE
}`
const formSchema = z.object({
- cidrBlockSize: z.coerce
- .number()
- .min(0, cidrBlockSizeValidationMessage)
- .max(
- type === 'IPv4' ? IPV4_MAX_CIDR_BLOCK_SIZE : IPV6_MAX_CIDR_BLOCK_SIZE,
- cidrBlockSizeValidationMessage
- ),
+ cidrBlockSize: z
+ .union([
+ z.literal(''),
+ z.coerce
+ .number()
+ .min(0, cidrBlockSizeValidationMessage)
+ .max(
+ type === 'IPv4' ? IPV4_MAX_CIDR_BLOCK_SIZE : IPV6_MAX_CIDR_BLOCK_SIZE,
+ cidrBlockSizeValidationMessage
+ ),
+ ])
+ .refine((value) => value !== '', 'Size is required'),
ipAddress: z
.string()
.min(1, `Please enter a valid IP address`)
@@ -219,7 +224,6 @@ const AddRestrictionModal = ({
max={
type === 'IPv4' ? IPV4_MAX_CIDR_BLOCK_SIZE : IPV6_MAX_CIDR_BLOCK_SIZE
}
- onChange={(e) => field.onChange(Number(e.target.value))}
placeholder={
type === 'IPv4'
? IPV4_MAX_CIDR_BLOCK_SIZE.toString()
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 85a78d826b9..43f2ac880e0 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -43,8 +43,10 @@
"vaul": "^1.1.2"
},
"devDependencies": {
+ "@hookform/resolvers": "^3.1.1",
"@testing-library/jest-dom": "^6.6.0",
"@testing-library/react": "^16.0.0",
+ "@testing-library/user-event": "^14.0.0",
"@types/lodash": "4.17.5",
"@types/node": "catalog:",
"@types/react": "catalog:",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 01ab841096e..58f4900a8f2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2454,12 +2454,18 @@ importers:
specifier: ^1.1.2
devDependencies:
+ '@hookform/resolvers':
+ specifier: ^3.1.1
'@testing-library/jest-dom':
specifier: ^6.6.0
version: 6.6.3
'@testing-library/react':
specifier: ^16.0.0
+ '@testing-library/user-event':
+ specifier: ^14.0.0
+ version: 14.6.1(@testing-library/[email protected])
'@types/lodash':
specifier: 4.17.5
version: 4.17.5