Skip to content

Commit

Permalink
Feature: Remove arbitrary maximum integer values. Implements #101
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealo committed Nov 29, 2024
1 parent b3c16bd commit fb96bc8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/common/components/configurationForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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={
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/common/components/configurationForm/totalMemoryInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)"
/>
<Field
Expand Down
15 changes: 8 additions & 7 deletions src/common/components/configurationForm/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
SIZE_UNIT_GB,
HARD_DRIVE_HDD,
HARD_DRIVE_SSD,
HARD_DRIVE_SAN
HARD_DRIVE_SAN,
MAX_NUMERIC_VALUE
} from '@features/configuration/constants'

const MAX_INTEGER = 9999
const MIN_MB_MEMORY = 512

const DB_TYPES = [DB_TYPE_WEB, DB_TYPE_OLTP, DB_TYPE_DW, DB_TYPE_DESKTOP, DB_TYPE_MIXED]
Expand All @@ -32,27 +32,28 @@ export const validationSchema = Yup.object().shape({
.oneOf([SIZE_UNIT_MB, SIZE_UNIT_GB], 'Unsupported unit'),
totalMemory: Yup.number()
.required('Required')
.integer('Must be an integer')
.when('totalMemoryUnit', (totalMemoryUnit, schema) => {
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))
.nullable()
.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}`)
})
2 changes: 2 additions & 0 deletions src/features/configuration/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fb96bc8

Please sign in to comment.