Skip to content
Merged

Dev #311

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const LoadFileFormat = (props: LoadFileFormatProps) => {
}
};


const getFileExtension = (filePath: string): string => {
const fileName = filePath?.split('/')?.pop();
const ext = fileName?.split('.')?.pop();
Expand All @@ -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 ****/
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/LegacyCms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -264,7 +264,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll

return (
<>
{isLoading ? (
{isLoading || newMigrationData?.isprojectMapped ? (
<div className="row">
<div className="col-12 text-center center-align">
<CircularLoader />
Expand Down
91 changes: 46 additions & 45 deletions ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -12,18 +13,19 @@ 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
} from '../../components/Stepper/FlowStepper/flowStep.interface';
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';
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
};


Expand Down Expand Up @@ -287,43 +292,43 @@ const Migration = () => {
// handle on proceed to destination stack
const handleOnClickLegacyCms = async (event: MouseEvent ) => {
setIsLoading(true);
if(isCompleted){

if (isCompleted) {
event.preventDefault();

//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{
else {
setIsLoading(false);

if (legacyCMSRef?.current) {
Expand Down Expand Up @@ -454,16 +459,12 @@ const Migration = () => {
return (
<div className='migration-steps-wrapper'>
{projectData &&
<>
<MigrationFlowHeader projectData={projectData} handleOnClick={handleOnClickFunctions[curreentStepIndex]} isLoading={isLoading} isCompleted={isCompleted} legacyCMSRef={legacyCMSRef} />
<MigrationFlowHeader projectData={projectData} handleOnClick={handleOnClickFunctions[curreentStepIndex]} isLoading={isLoading} isCompleted={isCompleted} legacyCMSRef={legacyCMSRef} />
}
<div className='steps-wrapper'>
<HorizontalStepper ref={stepperRef} steps={createStepper(projectData, handleClick)} handleSaveCT={saveRef?.current?.handleSaveContentType} changeDropdownState={changeDropdownState } />
<HorizontalStepper ref={stepperRef} steps={createStepper(projectData ?? defaultMigrationResponse, handleClick)} handleSaveCT={saveRef?.current?.handleSaveContentType} changeDropdownState={changeDropdownState } />
</div>
</>
}
</div>


)
}

Expand Down
8 changes: 8 additions & 0 deletions ui/src/utilities/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down