Skip to content
Merged
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
10 changes: 9 additions & 1 deletion api/src/models/project-lowdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ interface LegacyCMS {
is_localPath: boolean;
}

interface StackDetails{
uid: string;
label: string;
master_locale: string;
created_at: string;

}

/**
* Represents an execution log.
*/
Expand Down Expand Up @@ -61,7 +69,7 @@ interface Project {
isDeleted: boolean;
isNewStack: boolean;
newStackId: string;
stackDetails: [];
stackDetails: StackDetails;
mapper_keys: [];
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/projects.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ router.delete("/:projectId", asyncRouter(projectController.deleteProject));
router.patch("/:projectId", asyncRouter(projectController.revertProject));

//update stack details Project Route
router.patch("/:projectId", asyncRouter(projectController.updateStackDetails));
router.patch("/:projectId/stack-details", asyncRouter(projectController.updateStackDetails));

//update content mapper details Project Route
router.patch("/:projectId", asyncRouter(projectController.updateContentMapper));
Expand Down
7 changes: 6 additions & 1 deletion api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ const createProject = async (req: Request) => {
isDeleted: false,
isNewStack: false,
newStackId: "",
stackDetails: [],
stackDetails: {
uid: '',
label: '',
master_locale: '',
created_at: '',
}
};

try {
Expand Down
11 changes: 6 additions & 5 deletions ui/src/components/DestinationStack/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const DestinationStackComponent = ({
handleOnAllStepsComplete,
}: DestinationStackComponentProps) => {
/** ALL HOOKS HERE */
const [isLoading, setIsLoading] = useState<boolean>(true);

// const [isCompleted, setIsCompleted] = useState<boolean>(false);
const [isMigrationLocked, setIsMigrationLocked] = useState<boolean>(false);
const [stepperKey] = useState<string>('destination-Vertical-stepper');
Expand All @@ -50,6 +50,7 @@ const DestinationStackComponent = ({
const selectedOrganisation = useSelector((state:RootState)=>state?.authentication?.selectedOrganisation);
const organisationsList = useSelector((state:RootState)=>state?.authentication?.organisationsList);
const dispatch = useDispatch();
const [isLoading, setIsLoading] = useState<boolean>(newMigrationData?.isprojectMapped);

// const { projectId = '' } = useParams();

Expand Down Expand Up @@ -127,7 +128,7 @@ const DestinationStackComponent = ({
selectedStack: selectedStackData,
stackArray: stackArray
};
dispatch(updateNewMigrationData({ destination_stack: newMigData }));
//dispatch(updateNewMigrationData({ destination_stack: newMigData }));
}
//Update newMigration Data for destination stack

Expand Down Expand Up @@ -183,9 +184,9 @@ const DestinationStackComponent = ({
}, []);


useEffect(() => {
updateDestinationStackData();
}, [selectedOrganisation]);
// useEffect(() => {
// updateDestinationStackData();
// }, [selectedOrganisation]);

useEffect(() => {
if (autoVerticalStepperComponent?.current) {
Expand Down
7 changes: 4 additions & 3 deletions ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
filterCMSData(searchText);
}, []);

useEffect(() => {
filterCMSData(searchText);
}, [cmsFilter]);
// useEffect(() => {
// filterCMSData(searchText);
// }, [cmsFilter]);


return (
<div>
<div className="col-12">
Expand Down
5 changes: 2 additions & 3 deletions ui/src/components/LegacyCms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll

/** ALL HOOKS HERE */
const [isMigrationLocked, setIsMigrationLocked] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [isLoading, setIsLoading] = useState<boolean>(newMigrationData?.isprojectMapped);
const [internalActiveStepIndex, setInternalActiveStepIndex] = useState<number>(-1);
const [stepperKey] = useState<string>('legacy-Vertical-stepper');

Expand Down Expand Up @@ -230,8 +230,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll


}, [internalActiveStepIndex]);



useEffect(()=>{
if (!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id)) {
setInternalActiveStepIndex(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const AutoVerticalStepper = React.forwardRef<
<div>
<div className='orgWrapper'>
<Heading className='stepper-title' tagName='h3' text={data.title} />
{isRequired && <span className="FieldLabel__required-text">(required)</span> }
{isRequired || data?.isRequired && <span className="FieldLabel__required-text">(required)</span> }
{data?.ifReadonly && <span>(read only)</span>}
</div>
<span className="stepper-titleNote">{data.titleNote ? data.titleNote : ''}</span>
Expand Down
4 changes: 3 additions & 1 deletion ui/src/context/app/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export interface INewMigration {
destination_stack: IDestinationStack;
content_mapping: IContentMapper;
test_migration: ITestMigration;
isprojectMapped: boolean;
}

export interface IMigrationData {
Expand Down Expand Up @@ -315,7 +316,8 @@ export const DEFAULT_NEW_MIGRATION: INewMigration = {
legacy_cms: DEFAULT_LEGACY_CMS,
destination_stack: DEFAULT_DESTINATION_STACK,
content_mapping: DEFAULT_CONTENT_MAPPER,
test_migration: DEFAULT_TEST_MIGRATION
test_migration: DEFAULT_TEST_MIGRATION,
isprojectMapped: false,
};

export const DEFAULT_URL_TYPE: IURLType = {
Expand Down
149 changes: 91 additions & 58 deletions ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RootState } from '../../store';
import { updateMigrationData, updateNewMigrationData } from '../../store/slice/migrationDataSlice';

// Services
import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, createTestStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation } from '../../services/api/migration.service';
import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, createTestStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation, updateStackDetails } from '../../services/api/migration.service';
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';

// Utilities
Expand All @@ -18,12 +18,13 @@ import { isEmptyString, validateArray } from '../../utilities/functions';
// Interface
import {
MigrationResponse,
StackResponse,
} from '../../services/api/service.interface';
import {
DEFAULT_IFLOWSTEP,
IFlowStep
} from '../../components/Stepper/FlowStepper/flowStep.interface';
import { INewMigration } from '../../context/app/app.interface';
import { IDropDown, INewMigration } from '../../context/app/app.interface';
import { ContentTypeSaveHandles } from '../../components/ContentMapper/contentMapper.interface';


Expand All @@ -35,13 +36,14 @@ import DestinationStackComponent from '../../components/DestinationStack';
import ContentMapper from '../../components/ContentMapper';
import TestMigration from '../../components/TestMigration';
import MigrationExecution from '../../components/MigrationExecution';
import { Notification } from '@contentstack/venus-components';
import { Notification } from '@contentstack/venus-components';
import { createObject } from '../../utilities/projectDBMapper';

import { ICMSType, ILegacyCMSComponent } from "../../context/app/app.interface";
import { DEFAULT_CMS_TYPE } from "../../context/app/app.interface";
import { ICardType } from "../../components/Common/Card/card.interface";
import { defaultCardType } from "../../components/Common/Card/card.interface";
import { getAllStacksInOrg } from '../../services/api/stacks.service';


type StepperComponentRef = {
Expand All @@ -56,6 +58,7 @@ const Migration = () => {
const [isLoading, setIsLoading] = useState(false);
const [curreentStepIndex, setCurrentStepIndex] = useState(0);
const [isCompleted, setIsCompleted] = useState<boolean>(false);
const [isProjectMapper, setIsProjectMapper] = useState<boolean>(false);

const params: Params<string> = useParams();
const { projectId = '' } = useParams();
Expand All @@ -66,13 +69,23 @@ const Migration = () => {

const selectedOrganisation = useSelector((state: RootState)=>state?.authentication?.selectedOrganisation);
const newMigrationData = useSelector((state:RootState)=> state?.migration?.newMigrationData);
const organisationsList = useSelector((state:RootState)=>state?.authentication?.organisationsList);

const saveRef = useRef<ContentTypeSaveHandles>(null);

useEffect(() => {
fetchData();
}, [params?.stepId, params?.projectId, selectedOrganisation?.value]);

useEffect(()=>{
dispatch(updateNewMigrationData({
...newMigrationData,
isprojectMapped : isProjectMapper

}));

},[isProjectMapper]);

const fetchData = async () => {
setIsLoading(true);

Expand Down Expand Up @@ -107,14 +120,14 @@ const Migration = () => {

//Fetch project data
const fetchProjectData = async () => {
if (isEmptyString(selectedOrganisation?.value) || isEmptyString(params?.projectId)) return;
if (isEmptyString(selectedOrganisation?.value) || isEmptyString(params?.projectId)) return;

const data = await getMigrationData(selectedOrganisation?.value, params?.projectId || '');
if (data) {
setProjectData(data?.data);
setIsLoading(false);
}

const data = await getMigrationData(selectedOrganisation?.value, params?.projectId || '');
if (data) {
setIsLoading(false);
setProjectData(data?.data);
}
setIsProjectMapper(true);
const projectData = data?.data;

const legacyCmsData:ILegacyCMSComponent = await getCMSDataFromFile(CS_ENTRIES.LEGACY_CMS);
Expand All @@ -130,58 +143,68 @@ const Migration = () => {
(cms: ICardType) => cms?.fileformat_id === projectData?.legacy_cms?.file_format
)
: defaultCardType;


const projectMapper = {
...newMigrationData,
legacy_cms: {
selectedCms: selectedCmsData,
selectedFileFormat: selectedFileFormatData,
affix: projectData?.legacy_cms?.affix,
uploadedFile: {
file_details: {
localPath: projectData?.legacy_cms?.file_path,
awsData: {
awsRegion: projectData?.legacy_cms?.awsDetails?.awsRegion,
bucketName: projectData?.legacy_cms?.awsDetails?.bucketName,
buketKey: projectData?.legacy_cms?.awsDetails?.buketKey
},
isLocalPath: projectData?.legacy_cms?.is_localPath
const selectedOrganisationData = validateArray(organisationsList)
? organisationsList?.find((org: IDropDown) => org?.value === projectData?.org_id)
: selectedOrganisation;

let selectedStackData: IDropDown = {
value: projectData?.destination_stack_id,
label: '',
master_locale: '',
locales: [],
created_at: ''
};

selectedStackData = {
label: projectData?.stackDetails?.label,
value: projectData?.stackDetails?.value,
master_locale: projectData?.stackDetails?. master_locale,
created_at: projectData?.stackDetails?.created_at,
locales:[]
};

const projectMapper = {
...newMigrationData,
legacy_cms: {
...newMigrationData?.legacy_cms,
selectedCms: selectedCmsData,
selectedFileFormat: selectedFileFormatData,
affix: projectData?.legacy_cms?.affix,
uploadedFile: {
file_details: {
localPath: projectData?.legacy_cms?.file_path,
awsData: {
awsRegion: projectData?.legacy_cms?.awsDetails?.awsRegion,
bucketName: projectData?.legacy_cms?.awsDetails?.bucketName,
buketKey: projectData?.legacy_cms?.awsDetails?.buketKey
},
isValidated: projectData?.legacy_cms?.is_fileValid || newMigrationData?.legacy_cms?.uploadedFile?.isValidated
isLocalPath: projectData?.legacy_cms?.is_localPath
},
isFileFormatCheckboxChecked: true,
isRestictedKeywordCheckboxChecked: true,
projectStatus: projectData?.status
isValidated: projectData?.legacy_cms?.is_fileValid || newMigrationData?.legacy_cms?.uploadedFile?.isValidated
},
destination_stack: {
selectedOrg: {
value: projectData?.org_id,
label: projectData?.org_name
},
selectedStack: {
value: projectData?.destination_stack_id,
label: projectData?.destination_stack_name,
master_locale: projectData?.destination_stack_master_locale
},
stackArray:{
value: projectData?.destination_stack_id,
label: projectData?.destination_stack_name,
master_locale: projectData?.destination_stack_master_locale,
created_at: projectData?.destination_stack_created_at,
}
},
content_mapping: {
isDropDownChanged: false
},
stackDetails: projectData?.stackDetails,
mapper_keys: projectData?.mapper_keys,
};
dispatch(updateNewMigrationData(projectMapper));
};
isFileFormatCheckboxChecked: true,
isRestictedKeywordCheckboxChecked: true,
projectStatus: projectData?.status,
currentStep: -1,
},
destination_stack: {
selectedOrg: selectedOrganisationData,
selectedStack: selectedStackData,
stackArray:[]
},
content_mapping: {
isDropDownChanged: false
},
stackDetails: projectData?.stackDetails,
mapper_keys: projectData?.mapper_keys,
};

dispatch(updateNewMigrationData(projectMapper));
setIsProjectMapper(false);
};

//getContentTypes


const createStepper = (projectData: MigrationResponse,handleStepChange: (currentStep: number) => void) => {
const steps = [
Expand Down Expand Up @@ -322,6 +345,13 @@ const Migration = () => {
await updateDestinationStack(selectedOrganisation?.value, projectId, {
stack_api_key: newMigrationData?.destination_stack?.selectedStack?.value
});

await updateStackDetails(selectedOrganisation?.value, projectId,{
label:newMigrationData?.destination_stack?.selectedStack?.label,
value:newMigrationData?.destination_stack?.selectedStack?.value,
master_locale:newMigrationData?.destination_stack?.selectedStack?.master_locale,
created_at:newMigrationData?.destination_stack?.selectedStack?.created_at
})
handleStepChange(2);
const res = await updateCurrentStepData(selectedOrganisation?.value, projectId);
if (res) {
Expand Down Expand Up @@ -399,15 +429,18 @@ const Migration = () => {
}

return (


<div className='migration-steps-wrapper'>
<MigrationFlowHeader handleOnClick={handleOnClickFunctions[curreentStepIndex]} isLoading={isLoading} isCompleted={isCompleted} legacyCMSRef={legacyCMSRef} />

<div className='steps-wrapper'>
{ projectData &&
{ projectData &&
<HorizontalStepper ref={stepperRef} steps={createStepper(projectData, handleClick)} handleSaveCT={saveRef?.current?.handleSaveContentType} changeDropdownState={changeDropdownState } />
}
</div>
</div>


)
}

Expand Down
Loading