From fb96bc81d3853215e0461d5eadf4adb54596e14f Mon Sep 17 00:00:00 2001 From: Jeff Mealo Date: Wed, 27 Nov 2024 14:13:19 -0500 Subject: [PATCH 1/2] Feature: Remove arbitrary maximum integer values. Implements #101 --- src/common/components/configurationForm/index.jsx | 11 ++++++----- .../configurationForm/totalMemoryInput.jsx | 8 ++++---- .../components/configurationForm/validation.js | 15 ++++++++------- src/features/configuration/constants.js | 2 ++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/common/components/configurationForm/index.jsx b/src/common/components/configurationForm/index.jsx index 37e00db..97c972e 100644 --- a/src/common/components/configurationForm/index.jsx +++ b/src/common/components/configurationForm/index.jsx @@ -23,7 +23,8 @@ import { HARD_DRIVE_SSD, HARD_DRIVE_SAN, HARD_DRIVE_HDD, - SIZE_UNIT_GB + SIZE_UNIT_GB, + MAX_NUMERIC_VALUE } from '@features/configuration/constants' import './configuration-form.css' @@ -182,9 +183,9 @@ const ConfigurationForm = () => { autoCorrect="off" autoCapitalize="none" min={1} - max={9999} + max={MAX_NUMERIC_VALUE} step={1} - pattern="[0-9]{1,4}" + pattern="[0-9]{1,6}" placeholder="Number of CPUs (optional)" label="Number of CPUs" tooltip={ @@ -203,9 +204,9 @@ const ConfigurationForm = () => { autoCorrect="off" autoCapitalize="none" min={20} - max={9999} + max={MAX_NUMERIC_VALUE} step={1} - pattern="[0-9]{1,4}" + pattern="[0-9]{1,6}" placeholder="Number of Connections (optional)" label="Number of Connections" tooltip="Maximum number of PostgreSQL client connections" diff --git a/src/common/components/configurationForm/totalMemoryInput.jsx b/src/common/components/configurationForm/totalMemoryInput.jsx index 2187759..438ca5e 100644 --- a/src/common/components/configurationForm/totalMemoryInput.jsx +++ b/src/common/components/configurationForm/totalMemoryInput.jsx @@ -4,7 +4,7 @@ import { Field } from 'formik' import Tooltip from '@common/components/form/tooltip' import FormSimpleField from '@common/components/form/simpleField' import FormSimpleDropdown from '@common/components/form/simpleDropdown' -import { SIZE_UNIT_MB, SIZE_UNIT_GB } from '@features/configuration/constants' +import { SIZE_UNIT_MB, SIZE_UNIT_GB, MAX_NUMERIC_VALUE } from '@features/configuration/constants' import './total-memory-input.css' @@ -47,9 +47,9 @@ const TotalMemoryInput = ({ tooltip }) => { autoCapitalize="none" required="required" min={1} - max={9999} - step={1} - pattern="[0-9]{1,4}" + max={MAX_NUMERIC_VALUE} + step="any" + pattern="[0-9]+([.][0-9]+)?" placeholder="Memory size (RAM, required)" /> { if (totalMemoryUnit === SIZE_UNIT_MB) { - return schema.min(MIN_MB_MEMORY, `Must be greater than or equal to ${MIN_MB_MEMORY} MB`) + return schema + .min(MIN_MB_MEMORY, `Must be greater than or equal to ${MIN_MB_MEMORY} MB`) + .integer() } return schema.min(1, 'Must be greater than zero') }) - .max(MAX_INTEGER, `Must be less than or equal to ${MAX_INTEGER}`), + .max(MAX_NUMERIC_VALUE, `Must be less than or equal to ${MAX_NUMERIC_VALUE}`), hdType: Yup.string().required('Required').oneOf(HARD_DRIVE_TYPES, 'Unsupported hard drive'), cpuNum: Yup.number() .transform((value) => (isNaN(value) ? null : value)) @@ -47,12 +48,12 @@ export const validationSchema = Yup.object().shape({ .notRequired() .integer('Must be an integer') .min(1, 'Must be greater than zero') - .max(MAX_INTEGER, `Must be less than or equal to ${MAX_INTEGER}`), + .max(MAX_NUMERIC_VALUE, `Must be less than or equal to ${MAX_NUMERIC_VALUE}`), connectionNum: Yup.number() .transform((value) => (isNaN(value) ? null : value)) .nullable() .notRequired() .integer('Must be an integer') .min(20, 'Must be greater than or equal to 20') - .max(MAX_INTEGER, `Must be less than or equal to ${MAX_INTEGER}`) + .max(MAX_NUMERIC_VALUE, `Must be less than or equal to ${MAX_NUMERIC_VALUE}`) }) diff --git a/src/features/configuration/constants.js b/src/features/configuration/constants.js index 56a8b6b..adc8cbb 100644 --- a/src/features/configuration/constants.js +++ b/src/features/configuration/constants.js @@ -18,3 +18,5 @@ export const SIZE_UNIT_GB = 'GB' export const HARD_DRIVE_SSD = 'ssd' export const HARD_DRIVE_SAN = 'san' export const HARD_DRIVE_HDD = 'hdd' +// maximum value for integer fields +export const MAX_NUMERIC_VALUE = 999999 From 61b0d0bd49d21b4cc567385ee41e7677b9f65651 Mon Sep 17 00:00:00 2001 From: Jeff Mealo Date: Fri, 29 Nov 2024 11:47:38 -0500 Subject: [PATCH 2/2] Remove decimal support --- src/common/components/configurationForm/totalMemoryInput.jsx | 4 ++-- src/common/components/configurationForm/validation.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/common/components/configurationForm/totalMemoryInput.jsx b/src/common/components/configurationForm/totalMemoryInput.jsx index 438ca5e..99e4e09 100644 --- a/src/common/components/configurationForm/totalMemoryInput.jsx +++ b/src/common/components/configurationForm/totalMemoryInput.jsx @@ -48,8 +48,8 @@ const TotalMemoryInput = ({ tooltip }) => { required="required" min={1} max={MAX_NUMERIC_VALUE} - step="any" - pattern="[0-9]+([.][0-9]+)?" + step={1} + pattern="[0-9]{1,6}" placeholder="Memory size (RAM, required)" /> { if (totalMemoryUnit === SIZE_UNIT_MB) { - return schema - .min(MIN_MB_MEMORY, `Must be greater than or equal to ${MIN_MB_MEMORY} MB`) - .integer() + return schema.min(MIN_MB_MEMORY, `Must be greater than or equal to ${MIN_MB_MEMORY} MB`) } return schema.min(1, 'Must be greater than zero') })