yup#TestOptionsMessage TypeScript Examples
The following examples show how to use
yup#TestOptionsMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterDeploymentHostSelectionStep.tsx From assisted-ui-lib with Apache License 2.0 | 6 votes |
getValidationSchema = (agentClusterInstall: AgentClusterInstallK8sResource) => {
const isSNOCluster = getIsSNOCluster(agentClusterInstall);
const getMinMessage: TestOptionsMessage<{ min: number }> = ({ min }) => {
const message = `Please select at least ${min} hosts for the cluster`;
if (min === 5) {
return message + ' or select just 3 hosts instead.';
}
return `${message}.`;
};
return Yup.lazy<ClusterDeploymentHostsSelectionValues>((values) => {
return Yup.object<ClusterDeploymentHostsSelectionValues>().shape({
hostCount: isSNOCluster ? Yup.number() : hostCountValidationSchema,
useMastersAsWorkers: Yup.boolean().required(),
autoSelectedHostIds: values.autoSelectHosts
? Yup.array<string>().min(values.hostCount).max(values.hostCount)
: Yup.array<string>(),
selectedHostIds: values.autoSelectHosts
? Yup.array<string>()
: isSNOCluster
? Yup.array<string>()
.min(1, 'Please select one host for the cluster.')
.max(1, 'Please select one host for the cluster.') // TODO(jtomasek): replace this with Yup.array().length() after updating Yup
: Yup.array<string>().min(getMinHostsCount(values.selectedHostIds.length), getMinMessage),
});
});
}