Skip to content

Commit 1791333

Browse files
committed
[MTV-2247] Address init wizard setup feedback
Signed-off-by: Jeff Puzzo <[email protected]>
1 parent 14b5555 commit 1791333

File tree

16 files changed

+78
-64
lines changed

16 files changed

+78
-64
lines changed

packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,7 @@
340340
"Multiple NICs on the same network": "Multiple NICs on the same network",
341341
"Name": "Name",
342342
"Name is primarily intended for creation idempotence and configuration definition. Cannot be updated.": "Name is primarily intended for creation idempotence and configuration definition. Cannot be updated.",
343-
<<<<<<< HEAD
344-
=======
345-
"Name is required and must be a unique within a namespace and valid Kubernetes name.": "Name is required and must be a unique within a namespace and valid Kubernetes name.",
346343
"Name your plan and choose the project you would like it to be created in.": "Name your plan and choose the project you would like it to be created in.",
347-
>>>>>>> c1c1c83c ([MTV-2247] Initial new create plan wizard setup)
348344
"Namespace": "Namespace",
349345
"Namespace defines the space within which each name must be unique.\n An empty namespace is equivalent to the \"default\" namespace, but \"default\" is the canonical representation.\n Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty.": "Namespace defines the space within which each name must be unique.\n An empty namespace is equivalent to the \"default\" namespace, but \"default\" is the canonical representation.\n Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty.",
350346
"Namespace defines the space within which each name must be unique.\n An empty namespace is equivalent to the \"default\" namespace, but \"default\" is the canonical representation.\n Not all objects are required to be scoped to a namespace -\n the value of this field for those objects will be empty.": "Namespace defines the space within which each name must be unique.\n An empty namespace is equivalent to the \"default\" namespace, but \"default\" is the canonical representation.\n Not all objects are required to be scoped to a namespace -\n the value of this field for those objects will be empty.",
@@ -444,13 +440,10 @@
444440
"Plan details": "Plan details",
445441
"Plan information": "Plan information",
446442
"Plan name": "Plan name",
447-
<<<<<<< HEAD
443+
"Plan name is required.": "Plan name is required.",
448444
"Plan name must be a unique within a namespace.": "Plan name must be a unique within a namespace.",
449445
"Plan name must contain only lowercase alphanumeric characters or '-'": "Plan name must contain only lowercase alphanumeric characters or '-'",
450446
"Plan name must not be empty": "Plan name must not be empty",
451-
=======
452-
"Plan name is required.": "Plan name is required.",
453-
>>>>>>> c1c1c83c ([MTV-2247] Initial new create plan wizard setup)
454447
"Plans": "Plans",
455448
"Plans for virtualization": "Plans for virtualization",
456449
"Plans wizard": "Plans wizard",

packages/forklift-console-plugin/src/components/FormErrorHelperText.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ import { FieldError } from 'react-hook-form';
33

44
import { FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core';
55
import { ExclamationCircleIcon } from '@patternfly/react-icons';
6+
import { isEmpty } from '@utils/helpers';
67

78
type FormErrorHelperTextProps = {
89
error: Partial<FieldError>;
910
};
1011

1112
export const FormErrorHelperText: FC<FormErrorHelperTextProps> = ({ error }) => {
12-
return error ? (
13+
if (isEmpty(error)) {
14+
return null;
15+
}
16+
17+
return (
1318
<FormHelperText>
1419
<HelperText>
1520
<HelperTextItem icon={<ExclamationCircleIcon />} variant="error">
1621
{error?.message?.toString()}
1722
</HelperTextItem>
1823
</HelperText>
1924
</FormHelperText>
20-
) : null;
25+
);
2126
};

packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/NameTemplate/utils/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { produce } from 'immer';
22
import { OnConfirmHookType } from 'src/modules/Providers';
3-
import { setObjectValueByPath, unsetObjectValueByPath } from 'src/utils/utils';
43

54
import { k8sUpdate } from '@openshift-console/dynamic-plugin-sdk';
5+
import { setObjectValueByPath, unsetObjectValueByPath } from '@utils/helpers';
66

77
import { EnhancedPlan } from '../../../utils/types';
88

packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SharedDisksDetailsItem/components/MigrateSharedDisksSwitch/MigrateSharedDisksSwitch.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { FC } from 'react';
22
import { ModalInputComponentType } from 'src/modules/Providers/modals';
3-
import { useForkliftTranslation } from 'src/utils/i18n';
4-
import { safeBoolean } from 'src/utils/utils';
53

64
import { Switch } from '@patternfly/react-core';
5+
import { safeBoolean } from '@utils/helpers';
6+
import { useForkliftTranslation } from '@utils/i18n';
77

88
type SwitchRendererProps = {
99
value: string;

packages/forklift-console-plugin/src/modules/Plans/views/details/components/SettingsSection/components/SharedDisksDetailsItem/utils/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { produce } from 'immer';
22
import { OnConfirmHookType } from 'src/modules/Providers/modals';
3-
import { safeBoolean } from 'src/utils/utils';
43

54
import { V1beta1Plan } from '@kubev2v/types';
65
import { k8sUpdate } from '@openshift-console/dynamic-plugin-sdk';
6+
import { safeBoolean } from '@utils/helpers';
77

88
import { EnhancedPlan } from '../../../utils/types';
99

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.create-plan-wizard__form {
22
width: 66%;
3+
display: flex;
4+
flex-direction: column;
5+
gap: var(--pf-v5-global--spacer--lg);
36
}

packages/forklift-console-plugin/src/plans/create/CreatePlanWizard.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import React, { FC, useState } from 'react';
22
import { FormProvider, useForm } from 'react-hook-form';
3-
import { useForkliftTranslation } from 'src/utils';
43

54
import { Form, Title, Wizard, WizardStep, WizardStepType } from '@patternfly/react-core';
5+
import { isEmpty } from '@utils/helpers';
6+
import { useForkliftTranslation } from '@utils/i18n';
67

78
import { GeneralInformationForm } from './steps/GeneralInformationForm';
8-
import { defaultCurrentStep, planStepIndexes, planStepNames, PlanWizardStepId } from './constants';
9+
import { firstStep, planStepNames, planStepOrder, PlanWizardStepId } from './constants';
910
import { CreatePlanWizardFooter } from './CreatePlanWizardFooter';
1011

1112
import './CreatePlanWizard.style.scss';
1213

1314
export const CreatePlanWizard: FC = () => {
1415
const { t } = useForkliftTranslation();
1516
const form = useForm({ mode: 'onChange' });
16-
const [currentStep, setCurrentStep] = useState<WizardStepType>(defaultCurrentStep);
17-
const { formState, getValues } = form;
18-
const formValues = getValues();
17+
const [currentStep, setCurrentStep] = useState<WizardStepType>(firstStep);
18+
const { formState, watch } = form;
19+
const formValues = watch();
1920

2021
const onSubmit = () => console.log('SUBMITTED: ', formValues);
2122

2223
const getStepProps = (id: PlanWizardStepId) => ({
2324
id,
2425
name: planStepNames[id],
25-
isDisabled:
26-
currentStep?.index < planStepIndexes[id] && Object.keys(formState?.errors).length > 0,
26+
isDisabled: currentStep?.index < planStepOrder[id] && !isEmpty(formState?.errors),
2727
});
2828

2929
return (

packages/forklift-console-plugin/src/plans/create/CreatePlanWizardFooter.tsx

+25-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { FC, MouseEvent } from 'react';
22
import { useFormContext } from 'react-hook-form';
33
import { useHistory } from 'react-router';
44
import { getResourceUrl } from 'src/modules';
5-
import { useForkliftTranslation } from 'src/utils';
65

76
import { PlanModelRef } from '@kubev2v/types';
87
import { useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
@@ -13,6 +12,7 @@ import {
1312
WizardFooterProps,
1413
WizardFooterWrapper,
1514
} from '@patternfly/react-core';
15+
import { useForkliftTranslation } from '@utils/i18n';
1616

1717
import { PlanWizardStepId } from './constants';
1818

@@ -31,17 +31,29 @@ export const CreatePlanWizardFooter: FC<CreatePlanWizardFooterProps> = ({
3131
activeStep.id === PlanWizardStepId.MigrationType ||
3232
activeStep.id === PlanWizardStepId.OtherSettings;
3333

34-
const onNextClick =
35-
(event: MouseEvent<HTMLButtonElement>) => async (goToStep: () => void | Promise<void>) => {
36-
if (onNext) {
37-
return onNext(event);
38-
}
34+
const validate = async () => trigger(null, { shouldFocus: true });
3935

40-
const isValid = await trigger(null, { shouldFocus: true });
41-
if (isValid) {
42-
goToStep();
43-
}
44-
};
36+
const onNextClick = async (event: MouseEvent<HTMLButtonElement>) => {
37+
if (onNext) {
38+
return onNext(event);
39+
}
40+
41+
const isValid = await validate();
42+
if (isValid) {
43+
goToNextStep();
44+
}
45+
};
46+
47+
const onSkipToReviewClick = async (event: MouseEvent<HTMLButtonElement>) => {
48+
if (onNext) {
49+
return onNext(event);
50+
}
51+
52+
const isValid = await validate();
53+
if (isValid) {
54+
goToStepById(PlanWizardStepId.ReviewAndCreate);
55+
}
56+
};
4557

4658
const onCancel = () => {
4759
const plansListURL = getResourceUrl({
@@ -61,19 +73,11 @@ export const CreatePlanWizardFooter: FC<CreatePlanWizardFooterProps> = ({
6173
>
6274
{t('Back')}
6375
</Button>
64-
<Button
65-
variant={ButtonVariant.primary}
66-
onClick={(event) => onNextClick(event)(() => goToNextStep())}
67-
>
76+
<Button variant={ButtonVariant.primary} onClick={onNextClick}>
6877
{nextButtonText || t('Next')}
6978
</Button>
7079
{canSkipToReview && (
71-
<Button
72-
variant={ButtonVariant.tertiary}
73-
onClick={(event) =>
74-
onNextClick(event)(() => goToStepById(PlanWizardStepId.ReviewAndCreate))
75-
}
76-
>
80+
<Button variant={ButtonVariant.tertiary} onClick={onSkipToReviewClick}>
7781
{t('Skip to review')}
7882
</Button>
7983
)}

packages/forklift-console-plugin/src/plans/create/PlanCreatePage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { FC } from 'react';
2-
import { useForkliftTranslation } from 'src/utils';
32

43
import { PageSection, PageSectionTypes, PageSectionVariants, Title } from '@patternfly/react-core';
4+
import { useForkliftTranslation } from '@utils/i18n';
55

66
import { CreatePlanWizard } from './CreatePlanWizard';
77

packages/forklift-console-plugin/src/plans/create/constants.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { t } from 'src/utils/i18n';
1+
import { WizardStepType } from '@patternfly/react-core';
2+
import { t } from '@utils/i18n';
23

34
export enum PlanWizardStepId {
45
BasicSetUp = 'basic-set-up',
@@ -26,17 +27,22 @@ export const planStepNames: Record<PlanWizardStepId, string> = {
2627
[PlanWizardStepId.ReviewAndCreate]: t('Review and create'),
2728
};
2829

29-
export const planStepIndexes = Object.values(PlanWizardStepId).reduce(
30-
(acc, stepId, index) => ({ ...acc, [stepId]: index + 1 }),
31-
{},
32-
);
30+
export const planStepOrder: Record<PlanWizardStepId, number> = {
31+
[PlanWizardStepId.BasicSetUp]: 1,
32+
[PlanWizardStepId.General]: 2,
33+
[PlanWizardStepId.VirtualMachines]: 3,
34+
[PlanWizardStepId.NetworkMapping]: 4,
35+
[PlanWizardStepId.StorageMapping]: 5,
36+
[PlanWizardStepId.MigrationType]: 6,
37+
[PlanWizardStepId.AdditionalSetUp]: 7,
38+
[PlanWizardStepId.OtherSettings]: 8,
39+
[PlanWizardStepId.Hooks]: 9,
40+
[PlanWizardStepId.ReviewAndCreate]: 10,
41+
};
3342

34-
export const defaultCurrentStep = {
43+
export const firstStep: WizardStepType = {
3544
id: PlanWizardStepId.General,
3645
parentId: PlanWizardStepId.BasicSetUp,
3746
name: PlanWizardStepId.General,
38-
index: planStepIndexes[PlanWizardStepId.General],
47+
index: planStepOrder[PlanWizardStepId.General],
3948
};
40-
41-
export const warmMigrationLearnMoreLink =
42-
'https://docs.redhat.com/en/documentation/migration_toolkit_for_virtualization/2.7/html-single/installing_and_using_the_migration_toolkit_for_virtualization/index#warm-migration_mtv';

packages/forklift-console-plugin/src/plans/create/steps/GeneralInformationForm.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import React, { FC } from 'react';
22
import { Controller, useFormContext } from 'react-hook-form';
3-
import { FormErrorHelperText } from 'src/components/FormErrorHelperText';
4-
import { useForkliftTranslation } from 'src/utils';
53

4+
import { FormErrorHelperText } from '@components/FormErrorHelperText';
65
import {
7-
Flex,
86
Form,
97
FormGroup,
108
FormSection,
119
TextInput,
1210
Title,
1311
ValidatedOptions,
1412
} from '@patternfly/react-core';
13+
import { useForkliftTranslation } from '@utils/i18n';
1514

1615
import { GeneralFormFieldId, generalFormFieldLabels } from './constants';
1716

@@ -23,11 +22,7 @@ export const GeneralInformationForm: FC = () => {
2322
} = useFormContext();
2423

2524
return (
26-
<Flex
27-
direction={{ default: 'column' }}
28-
spaceItems={{ default: 'spaceItemsLg' }}
29-
className="create-plan-wizard__form"
30-
>
25+
<div className="create-plan-wizard__form">
3126
<Title headingLevel="h2">{t('General')}</Title>
3227

3328
<Form>
@@ -61,7 +56,7 @@ export const GeneralInformationForm: FC = () => {
6156
</FormGroup>
6257
</FormSection>
6358
</Form>
64-
</Flex>
59+
</div>
6560
);
6661
};
6762

packages/forklift-console-plugin/src/plans/create/steps/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { t } from 'src/utils/i18n';
1+
import { t } from '@utils/i18n';
22

33
export enum GeneralFormFieldId {
44
PlanName = 'plan-name',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const warmMigrationLearnMoreLink =
2+
'https://docs.redhat.com/en/documentation/migration_toolkit_for_virtualization/2.7/html-single/installing_and_using_the_migration_toolkit_for_virtualization/index#warm-migration_mtv';

packages/forklift-console-plugin/src/utils/utils.ts packages/forklift-console-plugin/src/utils/helpers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ export const unsetObjectValueByPath = (obj: object, path: OpenApiJsonPath) => {
4646
delete parent[lastKey];
4747
}
4848
};
49+
50+
export const isEmpty = (value: object | Array<unknown> | undefined): boolean =>
51+
Array.isArray(value) ? value.length === 0 : Object.keys(value || {}).length === 0;

packages/forklift-console-plugin/src/utils/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
22
export * from './constants';
33
export * from './deepCopy';
4+
export * from './docLinks';
45
export * from './enums';
56
export * from './fetch';
7+
export * from './helpers';
68
export * from './i18n';
79
export * from './resources';
810
export * from './types';

packages/forklift-console-plugin/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
"paths": {
2727
"@utils/*": ["./src/utils/*"],
28+
"@components/*": ["./src/components/*"],
2829
"src/*": ["./src/*"],
2930
"common/src/*": ["../common/src/*"]
3031
}
@@ -39,4 +40,4 @@
3940
"module": "commonjs"
4041
}
4142
}
42-
}
43+
}

0 commit comments

Comments
 (0)