fix(app): NaN validation for autoscaling [EE-6714] (#11237)

pull/11246/head
Ali 2024-02-22 17:36:44 +13:00 committed by GitHub
parent 90451bfd47
commit 8856bae5c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -1,5 +1,7 @@
import { SchemaOf, boolean, number, object } from 'yup';
import { nanNumberSchema } from '@/react-tools/yup-schemas';
import { AutoScalingFormValues } from './types';
type ValidationData = {
@ -14,7 +16,7 @@ export function autoScalingValidation(
isUsed: boolean().required(),
minReplicas: number().when('isUsed', (isUsed: boolean) =>
isUsed
? number()
? nanNumberSchema('Minimum instances is required.')
.required('Minimum instances is required.')
.min(1, 'Minimum instances must be greater than 0.')
.test(
@ -33,7 +35,7 @@ export function autoScalingValidation(
),
maxReplicas: number().when('isUsed', (isUsed: boolean) =>
isUsed
? number()
? nanNumberSchema('Maximum instances is required.')
.required('Maximum instances is required.')
.test(
'minReplicas',
@ -58,7 +60,7 @@ export function autoScalingValidation(
'isUsed',
(isUsed: boolean) =>
isUsed
? number()
? nanNumberSchema('Target CPU utilization percentage is required.')
.min(0, 'Target CPU usage must be greater than 0.')
.max(100, 'Target CPU usage must be smaller than 100.')
.required('Target CPU utilization percentage is required.')

View File

@ -23,8 +23,8 @@ export function resourceReservationValidation(
validationData?: ValidationData
): SchemaOf<ResourceQuotaFormValues> {
return object().shape({
memoryLimit: nanNumberSchema()
.min(0, 'Value must be greater than or equal to 0')
memoryLimit: nanNumberSchema('Memory limit is required.')
.min(0, 'Value must be greater than or equal to 0.')
.test(
'exhaused',
`The memory capacity for this namespace has been exhausted, so you cannot deploy the application.${
@ -37,7 +37,7 @@ export function resourceReservationValidation(
.max(
validationData?.maxMemoryLimit || 0,
({ value }) =>
`Value must be between 0 and ${validationData?.maxMemoryLimit}MB now - the previous value of ${value} exceeds this`
`Value must be between 0 and ${validationData?.maxMemoryLimit}MB now - the previous value of ${value} exceeds this.`
)
.test(
'hasSuitableNode',
@ -56,7 +56,7 @@ export function resourceReservationValidation(
);
}
)
.required(),
.required('Memory limit is required.'),
cpuLimit: number()
.min(0)
.test(
@ -71,7 +71,7 @@ export function resourceReservationValidation(
.max(
validationData?.maxCpuLimit || 0,
({ value }) =>
`Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this`
`Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this.`
)
.test(
'hasSuitableNode',