Skip to content

Commit 35356c2

Browse files
committed
refactor:CMG-506:refactored user flow when content mapper not generated by enabling save and continue button
1 parent 803503a commit 35356c2

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

ui/src/components/ContentMapper/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const Fields: MappingFields = {
215215

216216
}
217217
type contentMapperProps = {
218-
handleStepChange: (currentStep: number) => void;
218+
handleStepChange: (step: number) => void;
219219
}
220220

221221
const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: React.ForwardedRef<ContentTypeSaveHandles>) => {
@@ -2410,7 +2410,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
24102410
...newMigrationData?.legacy_cms,
24112411
uploadedFile:{
24122412
...newMigrationData?.legacy_cms?.uploadedFile,
2413-
reValidate: true
2413+
reValidate: true,
2414+
file_revalidated: true
24142415
}
24152416
}
24162417
}

ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
137137
buketKey: data?.file_details?.awsData?.buketKey
138138
}
139139
},
140-
cmsType: data?.cmsType
140+
cmsType: data?.cmsType,
141+
file_revalidated: true
141142

142143
}
143144
}

ui/src/components/MigrationFlowHeader/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const MigrationFlowHeader = ({
3636
}: MigrationFlowHeaderProps) => {
3737
const [projectName, setProjectName] = useState('');
3838
const [currentStep, setCurrentStep] = useState<number>(0);
39+
const [contentMapperLength, setcontentMapperLength] = useState<number>();
3940

4041
const navigate = useNavigate();
4142
const params: Params<string> = useParams();
@@ -56,6 +57,7 @@ const MigrationFlowHeader = ({
5657
const fetchProject = async () => {
5758
setProjectName(projectData?.name);
5859
setCurrentStep(projectData?.current_step);
60+
setcontentMapperLength(projectData?.content_mapper?.length)
5961

6062
//Navigate to lastest or active Step
6163
const url = `/projects/${params?.projectId}/migration/steps/${projectData?.current_step}`;
@@ -94,6 +96,8 @@ const MigrationFlowHeader = ({
9496
newMigrationData?.destination_stack?.selectedStack?.value
9597
);
9698

99+
const enableButton = contentMapperLength === 0 && newMigrationData?.project_current_step === 3 && params?.stepId === '1' && (!newMigrationData?.legacy_cms?.uploadedFile?.reValidate || newMigrationData?.legacy_cms?.uploadedFile?.reValidate) && newMigrationData?.legacy_cms?.uploadedFile?.file_revalidated
100+
97101
return (
98102
<div className="d-flex align-items-center justify-content-between migration-flow-header">
99103
<div className="d-flex align-items-center">
@@ -112,7 +116,7 @@ const MigrationFlowHeader = ({
112116
aria-label="Save and Continue"
113117
isLoading={isLoading || newMigrationData?.isprojectMapped}
114118
disabled={
115-
isStep4AndNotMigrated || isStepInvalid || isExecutionStarted || destinationStackMigrated
119+
(isStep4AndNotMigrated || isStepInvalid || isExecutionStarted || destinationStackMigrated) && !enableButton
116120
}
117121
>
118122
{stepValue}

ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type stepperProps = {
5050
};
5151

5252
export type HorizontalStepperHandles = {
53-
handleStepChange: (currentStep: number) => void;
53+
handleStepChange: (stepIndex: number) => void;
5454
};
5555

5656
const showNotification = (currentIndex: number) => {

ui/src/context/app/app.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export interface IFile {
6868
file_details?: FileDetails;
6969
isValidated: boolean;
7070
reValidate: boolean;
71-
cmsType: string
71+
cmsType: string;
72+
file_revalidated: boolean;
7273
}
7374

7475
export interface ICMSType extends ICardType {
@@ -311,6 +312,7 @@ export const DEFAULT_FILE: IFile = {
311312
isValidated: false,
312313
reValidate: false,
313314
cmsType: '',
315+
file_revalidated: false
314316
};
315317

316318
export const DEFAULT_CMS_TYPE: ICMSType = {

ui/src/pages/Migration/index.tsx

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ const Migration = () => {
324324
isLocalPath: projectData?.legacy_cms?.is_localPath
325325
},
326326
isValidated: projectData?.legacy_cms?.is_fileValid,
327-
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate
327+
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate,
328+
file_revalidated: newMigrationData?.legacy_cms?.uploadedFile?.file_revalidated
328329
} : uploadObj,
329330
isFileFormatCheckboxChecked: true,
330331
isRestictedKeywordCheckboxChecked: true,
@@ -373,7 +374,7 @@ const Migration = () => {
373374
*/
374375
const createStepper = (
375376
projectData: MigrationResponse,
376-
handleStepChange: (currentStep: number) => void
377+
handleStepChange: (step: number) => void
377378
) => {
378379
const steps = [
379380
{
@@ -450,7 +451,7 @@ const Migration = () => {
450451
const handleOnClickLegacyCms = async (event: MouseEvent) => {
451452
setIsLoading(true);
452453

453-
if (isCompleted) {
454+
if (isCompleted && newMigrationData?.project_current_step === 1) {
454455
event.preventDefault();
455456

456457
//Update Data in backend
@@ -493,6 +494,26 @@ const Migration = () => {
493494
type: 'error'
494495
});
495496
}
497+
}
498+
else if(newMigrationData?.project_current_step > 1 && (!newMigrationData?.legacy_cms?.uploadedFile?.reValidate || newMigrationData?.legacy_cms?.uploadedFile?.reValidate)){
499+
if(!newMigrationData?.legacy_cms?.uploadedFile?.file_revalidated){
500+
setIsLoading(false);
501+
Notification({
502+
notificationContent: {
503+
text: 'Please reValidate the file to procced furthur'
504+
},
505+
type: 'warning'
506+
});
507+
}
508+
else{
509+
setIsLoading(false);
510+
handleStepChange(2);
511+
const url = `/projects/${projectId}/migration/steps/3`;
512+
navigate(url, { replace: true });
513+
514+
}
515+
516+
496517
} else {
497518
setIsLoading(false);
498519

@@ -623,12 +644,21 @@ const Migration = () => {
623644
}
624645
});
625646
} else {
626-
event.preventDefault();
627-
const url = `/projects/${projectId}/migration/steps/4`;
628-
navigate(url, { replace: true });
629647

630-
await updateCurrentStepData(selectedOrganisation.value, projectId);
631-
handleStepChange(3);
648+
const res = await updateCurrentStepData(selectedOrganisation.value, projectId);
649+
if (res?.status === 200) {
650+
setIsLoading(false);
651+
event.preventDefault();
652+
const url = `/projects/${projectId}/migration/steps/4`;
653+
navigate(url, { replace: true });
654+
} else {
655+
setIsLoading(false);
656+
Notification({
657+
notificationContent: { text: res?.data?.error?.message },
658+
type: 'error'
659+
});
660+
}
661+
632662
}
633663
};
634664

@@ -722,7 +752,7 @@ const Migration = () => {
722752
<div className="steps-wrapper">
723753
<HorizontalStepper
724754
ref={stepperRef}
725-
steps={createStepper(projectData ?? defaultMigrationResponse, handleClick)}
755+
steps={createStepper(projectData ?? defaultMigrationResponse, handleStepChange)}
726756
handleSaveCT={saveRef?.current?.handleSaveContentType}
727757
changeDropdownState={changeDropdownState}
728758
projectData={projectData || defaultMigrationResponse}

ui/src/services/api/service.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface MigrationResponse {
3737
isMigrationStarted: boolean;
3838
isMigrationCompleted: boolean;
3939
migration_execution: boolean;
40+
content_mapper: []
4041
}
4142

4243
export interface LegacyCms {
@@ -65,7 +66,8 @@ export const defaultMigrationResponse: MigrationResponse = {
6566
current_step: 1,
6667
isMigrationStarted: false,
6768
isMigrationCompleted: false,
68-
migration_execution: false
69+
migration_execution: false,
70+
content_mapper: []
6971
};
7072
interface data {
7173
file_details: FileDetails;

0 commit comments

Comments
 (0)