Skip to content

Commit

Permalink
Resolve other Yup issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyselov authored and rawagner committed Mar 28, 2024
1 parent ee70bc3 commit 2c59430
Show file tree
Hide file tree
Showing 25 changed files with 204 additions and 189 deletions.
4 changes: 2 additions & 2 deletions libs/ui-lib/lib/cim/components/Agent/BMCForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ const getValidationSchema = (usedHostnames: string[], origHostname: string, t: T
Yup.object().shape(
{
macAddress: macAddressValidationSchema.when('name', {
is: (val) => !!val,
is: (name: string) => !!name,
then: () => macAddressValidationSchema.required(t('ai:MAC has to be specified')),
}),
name: Yup.string().when('macAddress', {
is: (val) => !!val,
is: (name: string) => !!name,
then: () => Yup.string().required(t('ai:Name has to be specified')),
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,22 @@ const getInitialValues = ({
const getValidationSchema = (agentClusterInstall: AgentClusterInstallK8sResource, t: TFunction) => {
const isSNOCluster = getIsSNOCluster(agentClusterInstall);

return Yup.lazy<ClusterDeploymentHostsSelectionValues>(
(values: ClusterDeploymentHostsSelectionValues) => {
return Yup.object<ClusterDeploymentHostsSelectionValues>().shape({
hostCount: isSNOCluster ? Yup.number() : hostCountValidationSchema(t),
useMastersAsWorkers: Yup.boolean().required(t('ai:Required field')),
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, t('ai:Please select one host for the cluster.'))
.max(1, t('ai:Please select one host for the cluster.')) // TODO(jtomasek): replace this with Yup.array().length() after updating Yup
: Yup.array<string>().min(3, t('ai:Please select at least 3 hosts for the cluster.')),
});
},
);
return Yup.lazy((values: ClusterDeploymentHostsSelectionValues) => {
return Yup.object<ClusterDeploymentHostsSelectionValues>({
hostCount: isSNOCluster ? Yup.number() : hostCountValidationSchema(t),
useMastersAsWorkers: Yup.boolean().required(t('ai:Required field')),
autoSelectedHostIds: values.autoSelectHosts
? Yup.array(Yup.string()).min(values.hostCount).max(values.hostCount)
: Yup.array(Yup.string()),
selectedHostIds: values.autoSelectHosts
? Yup.array(Yup.string())
: isSNOCluster
? Yup.array(Yup.string())
.min(1, t('ai:Please select one host for the cluster.'))
.max(1, t('ai:Please select one host for the cluster.')) // TODO(jtomasek): replace this with Yup.array().length() after updating Yup
: Yup.array(Yup.string()).min(3, t('ai:Please select at least 3 hosts for the cluster.')),
});
});
};

type UseHostsSelectionFormikArgs = {
Expand All @@ -110,7 +108,7 @@ export const useHostsSelectionFormik = ({
t,
}: UseHostsSelectionFormikArgs): [
ClusterDeploymentHostsSelectionValues,
Yup.Lazy<ClusterDeploymentHostsSelectionValues>,
Yup.Lazy<Yup.AnyObject>,
] => {
const initialValues = React.useMemo(
() => getInitialValues({ agents, clusterDeployment, agentClusterInstall }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const getNetworkConfigurationValidationSchema = (
initialValues: NetworkConfigurationValues,
hostSubnets: HostSubnets,
) =>
Yup.lazy<NetworkConfigurationValues>((values: NetworkConfigurationValues) =>
Yup.lazy((values: NetworkConfigurationValues) =>
Yup.object<NetworkConfigurationValues>().shape({
clusterNetworkHostPrefix: hostPrefixValidationSchema(values.clusterNetworkCidr),
clusterNetworkCidr: ipBlockValidationSchema(values.serviceNetworkCidr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getNetworkConfigurationValidationSchema = (
initialValues: ClusterDeploymentNetworkingValues,
hostSubnets: HostSubnets,
) =>
Yup.lazy<ClusterDeploymentNetworkingValues>((values: ClusterDeploymentNetworkingValues) =>
Yup.lazy((values: ClusterDeploymentNetworkingValues) =>
Yup.object<ClusterDeploymentNetworkingValues>().shape({
clusterNetworkHostPrefix: hostPrefixValidationSchema(values.clusterNetworkCidr),
clusterNetworkCidr: ipBlockValidationSchema(values.serviceNetworkCidr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TFunction } from 'i18next';
import { NodePoolK8sResource } from '../../types';

const validationSchema = (clusterName: string, nodePools: NodePoolK8sResource[], t: TFunction) =>
Yup.lazy<HostsFormValues>((values: HostsFormValues) =>
Yup.lazy((values: HostsFormValues) =>
Yup.object<HostsFormValues>().shape({
agentNamespace: Yup.string().required(t('ai:Required field')),
nodePools: Yup.array().of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useTranslation } from '../../../../../common/hooks/use-translation-wrapper';

const getValidationSchema = (t: TFunction) =>
Yup.lazy<NetworkFormValues>((values: NetworkFormValues) =>
Yup.lazy((values: NetworkFormValues) =>
Yup.object<NetworkFormValues>().shape({
sshPublicKey: sshPublicKeyValidationSchema.required(t('ai:Required field')),
clusterNetworkCidr: values.isAdvanced
Expand Down
6 changes: 3 additions & 3 deletions libs/ui-lib/lib/cim/components/InfraEnv/InfraEnvFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type EnvironmentStepFormValues = {
};

const validationSchema = (usedNames: string[], t: TFunction) =>
Yup.lazy<EnvironmentStepFormValues>((values: EnvironmentStepFormValues) =>
Yup.lazy((values: EnvironmentStepFormValues) =>
Yup.object<EnvironmentStepFormValues>().shape({
name: richNameValidationSchema(t, usedNames),
location: locationValidationSchema(t).required(t('ai:Location is a required field.')),
Expand All @@ -88,8 +88,8 @@ const validationSchema = (usedNames: string[], t: TFunction) =>
.test(
'label-equals-validation',
'Label selector needs to be in a `key=value` form',
(values: string[]) =>
values.every((value) => {
(values) =>
(values as string[]).every((value) => {
const parts = value.split('=');
return parts.length === 2;
}),
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-lib/lib/cim/components/modals/EditProxyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { getErrorMessage } from '../../../common/utils';
import { getWarningMessage } from './utils';

const validationSchema = () =>
Yup.lazy<ProxyFieldsType>((values: ProxyFieldsType) =>
Yup.lazy((values: ProxyFieldsType) =>
Yup.object<ProxyFieldsType>().shape({
httpProxy: httpProxyValidationSchema({
values,
Expand Down
10 changes: 5 additions & 5 deletions libs/ui-lib/lib/cim/components/modals/ScaleUpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const getAgentsToAdd = (
);

const getValidationSchema = (agentsCount: number) => {
return Yup.lazy<ScaleUpFormValues>((values: ScaleUpFormValues) => {
return Yup.lazy((values: ScaleUpFormValues) => {
return Yup.object<ScaleUpFormValues>().shape({
hostCount: Yup.number().min(1).max(agentsCount),
autoSelectedHostIds: values.autoSelectHosts
? Yup.array<string>().min(1).max(agentsCount)
: Yup.array<string>(),
? Yup.array(Yup.string()).min(1).max(agentsCount)
: Yup.array(Yup.string()),
selectedHostIds: values.autoSelectHosts
? Yup.array<string>()
: Yup.array<string>().min(1).max(agentsCount),
? Yup.array(Yup.string())
: Yup.array(Yup.string()).min(1).max(agentsCount),
});
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const StaticIPInfo = ({ docVersion }: { docVersion?: string }) => {
export type DiscoveryImageFormValues = ImageCreateParams & ProxyFieldsType;

const getValidationSchema = (allowEmpty: boolean) =>
Yup.lazy<DiscoveryImageFormValues>((values: DiscoveryImageFormValues) =>
Yup.lazy((values: DiscoveryImageFormValues) =>
Yup.object<DiscoveryImageFormValues>().shape({
sshPublicKey: sshPublicKeyValidationSchema,
httpProxy: httpProxyValidationSchema({ values, pairValueName: 'httpsProxy', allowEmpty }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ClusterWizardStepProps = {
navigation?: React.ReactNode;
};

const ClusterWizardStep = ({
export const ClusterWizardStep = ({
navigation,
footer,
children,
Expand All @@ -29,4 +29,4 @@ const ClusterWizardStep = ({
);
};

export default ClusterWizardStep;
// export default ClusterWizardStep;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Yup from 'yup';
import { TFunction } from 'i18next';
import { Cluster, ManagedDomain } from '@openshift-assisted/types/assisted-installer-service';
import {
Cluster,
DiskEncryption,
ManagedDomain,
} from '@openshift-assisted/types/assisted-installer-service';
import { getDefaultCpuArchitecture, OpenshiftVersionOptionType } from '../../types';
import { TangServer } from '../clusterConfiguration/DiskEncryptionFields/DiskEncryptionValues';
import {
Expand Down Expand Up @@ -98,7 +102,7 @@ export const getClusterDetailsValidationSchema = ({
t: TFunction;
newFeatureSupportLevels?: NewFeatureSupportLevelData;
}) =>
Yup.lazy<{ baseDnsDomain: string }>((values: { baseDnsDomain: string }) => {
Yup.lazy((values: { baseDnsDomain: string }) => {
const validateName = () =>
nameValidationSchema(t, usedClusterNames, values.baseDnsDomain, validateUniqueName, isOcm);
if (pullSecretSet) {
Expand All @@ -117,7 +121,10 @@ export const getClusterDetailsValidationSchema = ({
pullSecret: pullSecretValidationSchema.required('Required.'),
SNODisclaimer: Yup.boolean().when(['highAvailabilityMode', 'openshiftVersion'], {
// The disclaimer is required only if SNO is enabled and SNO feature is not fully supported in that version
is: (highAvailabilityMode, openshiftVersion) => {
is: (
highAvailabilityMode: Cluster['highAvailabilityMode'],
openshiftVersion: Cluster['openshiftVersion'],
) => {
const selectedVersion = (ocpVersions || []).find((v) => v.value === openshiftVersion);
if (newFeatureSupportLevels) {
return (
Expand All @@ -139,7 +146,7 @@ export const getClusterDetailsValidationSchema = ({
),
}),
diskEncryptionTangServers: Yup.array().when('diskEncryptionMode', {
is: (diskEncryptionMode) => {
is: (diskEncryptionMode: DiskEncryption['mode']) => {
return diskEncryptionMode === 'tang';
},
then: () =>
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-lib/lib/common/components/clusterWizard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as ClusterWizardStepHeader } from './ClusterWizardStepHeader';
export { default as ClusterWizardStep } from './ClusterWizardStep';
export { ClusterWizardStep } from './ClusterWizardStep';
export { default as ClusterWizardStepValidationsAlert } from './ClusterWizardStepValidationsAlert';
export { default as ReviewHostsInventory } from './ReviewHostsInventory';
export { ClusterValidations, HostsValidations } from './ReviewValidations';
Expand Down
Loading

0 comments on commit 2c59430

Please sign in to comment.