mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
30 lines
715 B
TypeScript
30 lines
715 B
TypeScript
|
import { SchemaOf, number, object } from 'yup';
|
||
|
|
||
|
import { ResourceQuotaFormValues } from './types';
|
||
|
|
||
|
type ValidationData = {
|
||
|
maxMemoryLimit: number;
|
||
|
maxCpuLimit: number;
|
||
|
};
|
||
|
|
||
|
export function resourceReservationValidation(
|
||
|
validationData?: ValidationData
|
||
|
): SchemaOf<ResourceQuotaFormValues> {
|
||
|
return object().shape({
|
||
|
memoryLimit: number()
|
||
|
.min(0)
|
||
|
.max(
|
||
|
validationData?.maxMemoryLimit || 0,
|
||
|
`Value must be between 0 and ${validationData?.maxMemoryLimit}`
|
||
|
)
|
||
|
.required(),
|
||
|
cpuLimit: number()
|
||
|
.min(0)
|
||
|
.max(
|
||
|
validationData?.maxCpuLimit || 0,
|
||
|
`Value must be between 0 and ${validationData?.maxCpuLimit}`
|
||
|
)
|
||
|
.required(),
|
||
|
});
|
||
|
}
|