From f83b017f70410112f198d454ea52100790bfe1e0 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Mon, 7 Oct 2024 20:41:43 +0530 Subject: [PATCH 1/2] Legacy CMS undefined step blocker issue and test stack details updated with redux --- .../LegacyCms/Actions/LoadFileFormat.tsx | 62 +++++++++---------- ui/src/components/LegacyCms/index.tsx | 4 +- ui/src/pages/Migration/index.tsx | 33 +++++----- ui/src/utilities/constants.ts | 8 +++ 4 files changed, 58 insertions(+), 49 deletions(-) diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index 6cfab901..efe596d0 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -66,7 +66,6 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { } }; - const getFileExtension = (filePath: string): string => { const fileName = filePath?.split('/')?.pop(); const ext = fileName?.split('.')?.pop(); @@ -85,44 +84,41 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { } else{ const { all_cms = [] } = migrationData?.legacyCMSData || {}; - let filteredCmsData:ICMSType[] = all_cms; - if (cmsType) { - filteredCmsData = all_cms?.filter((cms) => cms?.parent?.toLowerCase() === cmsType?.toLowerCase()); - } - - const isFormatValid = filteredCmsData[0]?.allowed_file_formats?.find((format:ICardType)=>{ - const isValid = format?.fileformat_id?.toLowerCase() === fileFormat?.toLowerCase(); - return isValid; - }); + let filteredCmsData:ICMSType[] = all_cms; + if (cmsType) { + filteredCmsData = all_cms?.filter((cms) => cms?.parent?.toLowerCase() === cmsType?.toLowerCase()); + } + + const isFormatValid = filteredCmsData[0]?.allowed_file_formats?.find((format:ICardType)=>{ + const isValid = format?.fileformat_id?.toLowerCase() === fileFormat?.toLowerCase(); + return isValid; + }); - if(! isFormatValid){ - setIsError(true); - setError('File format does not support, please add the correct file format.'); - } + if(!isFormatValid){ + setIsError(true); + setError('File format does not support, please add the correct file format.'); + } - const selectedFileFormatObj = { - description: "", - fileformat_id: fileFormat, - group_name: fileFormat, - isactive: true, - title: fileFormat === 'zip' ? fileFormat?.charAt(0)?.toUpperCase() + fileFormat?.slice(1) : fileFormat?.toUpperCase() - } - - - const newMigrationDataObj = { - ...newMigrationData, - legacy_cms: { - ...newMigrationData?.legacy_cms, - selectedFileFormat: selectedFileFormatObj + const selectedFileFormatObj = { + description: "", + fileformat_id: fileFormat, + group_name: fileFormat, + isactive: true, + title: fileFormat === 'zip' ? fileFormat?.charAt(0)?.toUpperCase() + fileFormat?.slice(1) : fileFormat?.toUpperCase() } - }; + + const newMigrationDataObj = { + ...newMigrationData, + legacy_cms: { + ...newMigrationData?.legacy_cms, + selectedFileFormat: selectedFileFormatObj + } + }; - setFileIcon(fileFormat === 'zip' ? fileFormat?.charAt(0).toUpperCase() + fileFormat.slice(1) : fileFormat?.toUpperCase()); - dispatch(updateNewMigrationData(newMigrationDataObj)); + setFileIcon(fileFormat === 'zip' ? fileFormat?.charAt(0).toUpperCase() + fileFormat.slice(1) : fileFormat?.toUpperCase()); + dispatch(updateNewMigrationData(newMigrationDataObj)); } - - } /**** ALL USEEffects HERE ****/ diff --git a/ui/src/components/LegacyCms/index.tsx b/ui/src/components/LegacyCms/index.tsx index dc925de8..74222bfd 100644 --- a/ui/src/components/LegacyCms/index.tsx +++ b/ui/src/components/LegacyCms/index.tsx @@ -174,7 +174,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll legacy_cms: { currentStep: internalActiveStepIndex, selectedCms: selectedCmsData, - selectedFileFormat: selectedFileFormatData || newMigrationData?.legacy_cms?.selectedFileFormat , + selectedFileFormat: selectedFileFormatData, uploadedFile: { file_details:{ localPath: legacyCMSData?.file_path, @@ -264,7 +264,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll return ( <> - {isLoading ? ( + {isLoading || newMigrationData?.isprojectMapped ? (
diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index e948de89..d740e15f 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -2,6 +2,7 @@ import { useEffect, useState, useRef } from 'react'; import { Params, useNavigate, useParams } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; +import { cbModal, Notification } from '@contentstack/venus-components'; // Redux files import { RootState } from '../../store'; @@ -12,11 +13,11 @@ import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDes import { getCMSDataFromFile } from '../../cmsData/cmsSelector'; // Utilities -import { CS_ENTRIES } from '../../utilities/constants'; +import { CS_ENTRIES, CS_URL } from '../../utilities/constants'; import { isEmptyString, validateArray } from '../../utilities/functions'; // Interface -import { MigrationResponse } from '../../services/api/service.interface'; +import { defaultMigrationResponse, MigrationResponse } from '../../services/api/service.interface'; import { DEFAULT_IFLOWSTEP, IFlowStep @@ -24,6 +25,7 @@ import { import { IDropDown, INewMigration, ICMSType, ILegacyCMSComponent, DEFAULT_CMS_TYPE } from '../../context/app/app.interface'; import { ContentTypeSaveHandles } from '../../components/ContentMapper/contentMapper.interface'; import { ICardType, defaultCardType } from "../../components/Common/Card/card.interface"; +import { ModalObj } from '../../components/Modal/modal.interface'; // Components import MigrationFlowHeader from '../../components/MigrationFlowHeader'; @@ -33,9 +35,7 @@ import DestinationStackComponent from '../../components/DestinationStack'; import ContentMapper from '../../components/ContentMapper'; import TestMigration from '../../components/TestMigration'; import MigrationExecution from '../../components/MigrationExecution'; -import { cbModal, Notification } from '@contentstack/venus-components'; import SaveChangesModal from '../../components/Common/SaveChangesModal'; -import { ModalObj } from '../../components/Modal/modal.interface'; type StepperComponentRef = { handleStepChange: (step: number) => void; @@ -179,6 +179,7 @@ const Migration = () => { const existingContentTypes = await fetchExistingContentTypes(); const existingGlobalFields = await fetchExistingGlobalFields(); + const stackLink = `${CS_URL[projectData?.region]}/stack/${projectData?.current_test_stack_id}/dashboard`; const projectMapper = { ...newMigrationData, @@ -215,12 +216,16 @@ const Migration = () => { existingCT: existingContentTypes, existingGlobal: existingGlobalFields }, + test_migration: { + stack_link: stackLink, + stack_api_key: projectData?.current_test_stack_id + }, stackDetails: projectData?.stackDetails, testStacks: projectData?.test_stacks }; - dispatch(updateNewMigrationData(projectMapper)); - setIsProjectMapper(false); + dispatch(updateNewMigrationData(projectMapper)); + setIsProjectMapper(false); }; @@ -289,6 +294,8 @@ const Migration = () => { setIsLoading(true); if(isCompleted){ event.preventDefault(); + console.log("======= isCompleted", isCompleted); + //Update Data in backend await updateLegacyCMSData(selectedOrganisation?.value, projectId, { @@ -323,7 +330,9 @@ const Migration = () => { } } - else{ + else { + console.log("inside else"); + setIsLoading(false); if (legacyCMSRef?.current) { @@ -454,16 +463,12 @@ const Migration = () => { return (
{projectData && - <> - + + }
- +
- - }
- - ) } diff --git a/ui/src/utilities/constants.ts b/ui/src/utilities/constants.ts index 01cdf591..56a7beeb 100644 --- a/ui/src/utilities/constants.ts +++ b/ui/src/utilities/constants.ts @@ -29,6 +29,14 @@ export const REGIONS = { GCP_NA: 'GCP_NA', }; +export const CS_URL: ObjectType = { + NA: "https://app.contentstack.com/#!", + EU: "https://eu-app.contentstack.com/#!", + AZURE_NA: "https://azure-na-app.contentstack.com/#!", + AZURE_EU: "https://azure-eu-app.contentstack.com/#!", + GCP_NA: "https://gcp-na-app.contentstack.com/#!", +} + export const HEADERS = { 'Content-Type': 'application/json', Authorization: `${TOKEN}` From a4645d7e71bf6e56ff31efaf6d9b0f3ed0342281 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Mon, 7 Oct 2024 21:12:08 +0530 Subject: [PATCH 2/2] Removed console --- ui/src/pages/Migration/index.tsx | 66 +++++++++++++++----------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index d740e15f..411bea72 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -292,47 +292,43 @@ const Migration = () => { // handle on proceed to destination stack const handleOnClickLegacyCms = async (event: MouseEvent ) => { setIsLoading(true); - if(isCompleted){ + + if (isCompleted) { event.preventDefault(); - console.log("======= isCompleted", isCompleted); - - //Update Data in backend - await updateLegacyCMSData(selectedOrganisation?.value, projectId, { - legacy_cms: newMigrationData?.legacy_cms?.selectedCms?.cms_id - }); - await updateAffixData(selectedOrganisation?.value, projectId, { affix: newMigrationData?.legacy_cms?.affix }); - await fileformatConfirmation(selectedOrganisation?.value, projectId, { - fileformat_confirmation: true - }); - - await affixConfirmation(selectedOrganisation?.value, projectId, { - affix_confirmation: true - }) - await updateFileFormatData(selectedOrganisation?.value, projectId, { - file_format: newMigrationData?.legacy_cms?.selectedCms?.allowed_file_formats[0]?.fileformat_id?.toString() , - file_path: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath, - is_fileValid: newMigrationData?.legacy_cms?.uploadedFile?.isValidated, - is_localPath: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.isLocalPath, - awsDetails:{ - awsRegion: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.awsRegion, - bucketName: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.bucketName, - buketKey: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.buketKey - } - }); - const res = await updateCurrentStepData(selectedOrganisation.value, projectId); - handleStepChange(1); - if (res) { - setIsLoading(false); + //Update Data in backend + await updateLegacyCMSData(selectedOrganisation?.value, projectId, { + legacy_cms: newMigrationData?.legacy_cms?.selectedCms?.cms_id + }); + await updateAffixData(selectedOrganisation?.value, projectId, { affix: newMigrationData?.legacy_cms?.affix }); + await fileformatConfirmation(selectedOrganisation?.value, projectId, { + fileformat_confirmation: true + }); - const url = `/projects/${projectId}/migration/steps/2`; - navigate(url, { replace: true }); - } + await affixConfirmation(selectedOrganisation?.value, projectId, { + affix_confirmation: true + }); + await updateFileFormatData(selectedOrganisation?.value, projectId, { + file_format: newMigrationData?.legacy_cms?.selectedCms?.allowed_file_formats[0]?.fileformat_id?.toString() , + file_path: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath, + is_fileValid: newMigrationData?.legacy_cms?.uploadedFile?.isValidated, + is_localPath: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.isLocalPath, + awsDetails:{ + awsRegion: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.awsRegion, + bucketName: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.bucketName, + buketKey: newMigrationData?.legacy_cms?.uploadedFile?.file_details?.awsData?.buketKey + } + }); + const res = await updateCurrentStepData(selectedOrganisation.value, projectId); + handleStepChange(1); + if (res) { + setIsLoading(false); + const url = `/projects/${projectId}/migration/steps/2`; + navigate(url, { replace: true }); + } } else { - console.log("inside else"); - setIsLoading(false); if (legacyCMSRef?.current) {