From fbc5923945eda1d6d244dd884143c8e30e92799a Mon Sep 17 00:00:00 2001 From: RohitKini Date: Mon, 9 Dec 2024 12:18:03 +0530 Subject: [PATCH 1/7] added readme.md file --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4bea9cef..3f7a8f66c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,63 @@ -# migration-v2 +# Migration v2 +## Overview +The migration-v2 project is designed to facilitate the migration of assets and related functionalities from version 1 to version 2. This project includes multiple components such as API, UI, and upload API. -This is the migration V2 Code. \ No newline at end of file +## Installation +Clone the repository: +``` +git clone https://github.com/contentstack-expert-services/migration-v2-ui.git +cd migration-v2 +``` +Install dependencies: +``` +npm install +``` + +## Scripts +- `npm start`: Starts the main server by running index.js. +- `npm run api`: Navigates to the api directory and runs the development server. +- `npm run upload`: Navigates to the upload-api directory and starts the upload API server. +- `npm run ui`: Navigates to the ui directory and starts the UI server. +- `npm run env`: Starts the main server by running npm start. +- `npm run postinstall`: Installs dependencies for the api, ui, and upload-api directories. +- `npm test`: Displays an error message indicating that no tests are specified. + +## Repository +- Type: git +- URL: https://github.com/contentstack-expert-services/migration-v2-ui.git + +## Bugs and Issues +- URL: https://github.com/contentstack-expert-services/migration-v2-ui/issues + +## Homepage +- URL: https://github.com/contentstack-expert-services/migration-v2-ui#readme + +## DevDependencies +- husky: ^4.3.8 +- prettier: ^2.4.1 +- rimraf: ^3.0.2 +- validate-branch-name: ^1.3.0 + +## Husky Configuration +``` +"husky": { + "hooks": {} +} +``` + +- Branch Name Validation +``` +"validate-branch-name": { + "pattern": "^(feature|bugfix|hotfix)/[a-z0-9-]{5,30}$", + "errorMsg": "Please add valid branch name!" +} +``` + +## License +This project is licensed under the ISC License. + +## Author +The author information is not specified. + +## Contact +For further assistance, please contact the project maintainer through the issues page on GitHub. From cccb5a3be6464603b19250ae5a8f33981ac80e2a Mon Sep 17 00:00:00 2001 From: RohitKini <57343193+RohitKini@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:37:26 +0530 Subject: [PATCH 2/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f7a8f66c..4ea94e4ca 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Migration v2 ## Overview -The migration-v2 project is designed to facilitate the migration of assets and related functionalities from version 1 to version 2. This project includes multiple components such as API, UI, and upload API. +The migration-v2 project is designed to facilitate the migration of assets and related functionalities. This project includes multiple components such as API, UI, and upload API. ## Installation Clone the repository: ``` -git clone https://github.com/contentstack-expert-services/migration-v2-ui.git +git clone https://github.com/contentstack/migration-v2.git cd migration-v2 ``` Install dependencies: From fa4089022cf6667229028dd2939bb678de70f42e Mon Sep 17 00:00:00 2001 From: RohitKini <57343193+RohitKini@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:09:49 +0530 Subject: [PATCH 3/7] added readme.md --- README.md | 6 +++--- api/README.md | 20 ++++++++++++++------ ui/README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4ea94e4ca..0b8e2af56 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ npm install ## Repository - Type: git -- URL: https://github.com/contentstack-expert-services/migration-v2-ui.git +- URL: https://github.com/contentstack/migration-v2.git ## Bugs and Issues -- URL: https://github.com/contentstack-expert-services/migration-v2-ui/issues +- URL: https://github.com/contentstack/migration-v2/issues ## Homepage -- URL: https://github.com/contentstack-expert-services/migration-v2-ui#readme +- URL: https://github.com/contentstack/migration-v2#readme ## DevDependencies - husky: ^4.3.8 diff --git a/api/README.md b/api/README.md index f9ff4fbd1..8936bbe3e 100644 --- a/api/README.md +++ b/api/README.md @@ -1,10 +1,18 @@ -# migration-v2-node-server +# migration-v2 -This is the TSO migration V2's node server. +This is the migration V2's node server. ## To start the server -1. Run `npm i` -2. Install & start MongoDB -3. To run dev server, create `./development.env` file and add env variables as per `./example.env` -4. To run prod server, create `./production.env` file and add env variables as per `./example.env` +1. Run `npm i` +2. Install and start MongoDB + +### To start MongoDB + +1. Install MongoDB on your system. +2. Start the MongoDB service. +3. Verify that MongoDB is running by opening a command prompt and running the command `mongo --version`. + +3. To run the development server, create a `./development.env` file and add environment variables as per `./example.env` +4. To run the production server, create a `./production.env` file and add environment variables as per `./example.env` + diff --git a/ui/README.md b/ui/README.md index 7d0d02544..5fe4fea2f 100644 --- a/ui/README.md +++ b/ui/README.md @@ -1,3 +1,51 @@ -# migration-v2-ui +# Migration UI -This is the migration V2's UI. +Migration UI is a web application designed to facilitate the migration of content. It provides a user-friendly interface for managing and migrating content efficiently. + +## Features +- User-friendly interface for content migration +- Integration with Contentstack +- State management with Redux Toolkit +- Comprehensive testing with Testing Library + +## Installation + +1. Clone the repository: + ```sh + git clone https://github.com/contentstack/migration-v2 + ``` + +2. Navigate to the project directory: + ```sh + cd ui + ``` + +3. Install the dependencies: + ```sh + npm install + ``` + +## Usage +Start the development server: +```sh +npm start +``` + +Open your browser and navigate to http://localhost:3000. + +## Dependencies +- @contentstack/json-rte-serializer: ^2.0.5 +- @contentstack/venus-components: ^2.2.4 +- @reduxjs/toolkit: ^2.2.5 +- @testing-library/jest-dom: ^5.17.0 +- @testing-library/react: ^13.4.0 +- @testing-library/user-event: ^13.5.0 +- @types/react: ^18.2.28 +- @types/react-dom: ^18.2.13 +- @types/react-redux: ^7.1.33 + +## Contributing +Contributions are welcome! Please open an issue or submit a pull request for any changes. + +## License +This project is licensed under the MIT License. From 27353b03287c8d3ff8d60203ab71d4021f87aded Mon Sep 17 00:00:00 2001 From: RohitKini <57343193+RohitKini@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:33:59 +0530 Subject: [PATCH 4/7] added readme.md file for upload api --- upload-api/README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 upload-api/README.md diff --git a/upload-api/README.md b/upload-api/README.md new file mode 100644 index 000000000..1b18a9ddc --- /dev/null +++ b/upload-api/README.md @@ -0,0 +1,36 @@ +# Migration v2 upload-api +## Overview +The migration-v2 upload-api project is designed to facilitate the migration of different CMS to Contentstack functionalities. + +## Installation +Clone the repository: +``` +git clone https://github.com/contentstack/migration-v2.git +cd migration-v2/upload-api +``` +Install dependencies: +``` +npm install +``` + +## Environment Variables + +The following environment variables are used in this project: + +- `PORT`: The port number on which the application runs. Default is `4002`. +- `NODE_BACKEND_API`: The backend API endpoint. Default is `http://localhost:5000`. + +Make sure to set these variables in a `.env` file at the root of your project. + +## Repository +- Type: git +- URL: https://github.com/contentstack/migration-v2.git + +## License +This project is licensed under the ISC License. + +## Author +The author information is not specified. + +## Contact +For further assistance, please contact the project maintainer through the issues page on GitHub. From ef912a775f6eae86aa61d7b9fae47997d5d5b255 Mon Sep 17 00:00:00 2001 From: RohitKini <57343193+RohitKini@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:43:10 +0530 Subject: [PATCH 5/7] updated readme file --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 0b8e2af56..8620f2f54 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,26 @@ Install dependencies: npm install ``` +Check for readme.md files and install dependencies for folders + +1. go to api folder + ``` + cd api + npm install + ``` + +2. go to ui folder + ``` + cd ui + npm install + ``` + +3. go to upload-api folder + ``` + cd upload-api + npm install + ``` + ## Scripts - `npm start`: Starts the main server by running index.js. - `npm run api`: Navigates to the api directory and runs the development server. From 591656d166b38366166db24f914661082f52876a Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 9 Dec 2024 17:36:25 +0530 Subject: [PATCH 6/7] refavtor:[CMG-429] and when migration is in-progress then handled disabling all cases --- api/src/models/project-lowdb.ts | 1 + api/src/services/projects.service.ts | 59 ++++++++++--------- api/src/services/runCli.service.ts | 5 ++ .../LogScreen/MigrationLogViewer.tsx | 27 +++++++-- .../components/MigrationExecution/index.tsx | 7 ++- .../components/MigrationFlowHeader/index.tsx | 2 +- .../HorizontalStepper/HorizontalStepper.tsx | 14 ++++- ui/src/components/TestMigration/index.tsx | 5 +- ui/src/pages/Migration/index.tsx | 16 ++--- ui/src/services/api/service.interface.ts | 8 ++- 10 files changed, 92 insertions(+), 52 deletions(-) diff --git a/api/src/models/project-lowdb.ts b/api/src/models/project-lowdb.ts index ca9f96ca0..e995da368 100644 --- a/api/src/models/project-lowdb.ts +++ b/api/src/models/project-lowdb.ts @@ -74,6 +74,7 @@ interface Project { mapperKeys: {}; extract_path: string; isMigrationStarted: boolean; + isMigrationCompleted:boolean; migration_execution: boolean; } diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index 38955c282..f684c90d7 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -127,6 +127,7 @@ const createProject = async (req: Request) => { }, mapperKeys: {}, isMigrationStarted: false, + isMigrationCompleted:false, migration_execution:false, }; @@ -825,35 +826,35 @@ const updateCurrentStep = async (req: Request) => { }); break; } - // case STEPPER_STEPS.MIGRATION: { - // if ( - // project.status === NEW_PROJECT_STATUS[0] || - // !isStepCompleted || - // !project?.destination_stack_id || - // project?.content_mapper?.length === 0 || - // !project?.current_test_stack_id || - // !project?.isMigrationStarted - // ) { - // logger.error( - // getLogMessage( - // srcFunc, - // HTTP_TEXTS.CANNOT_PROCEED_MIGRATION, - // token_payload - // ) - // ); - // throw new BadRequestError( - // HTTP_TEXTS.CANNOT_PROCEED_MIGRATION - // ); - // } - - // ProjectModelLowdb.update((data: any) => { - // data.projects[projectIndex].current_step = - // STEPPER_STEPS.MIGRATION; - // data.projects[projectIndex].status = NEW_PROJECT_STATUS[5]; - // data.projects[projectIndex].updated_at = new Date().toISOString(); - // }); - // break; - // } + case STEPPER_STEPS.MIGRATION: { + if ( + project.status === NEW_PROJECT_STATUS[0] || + !isStepCompleted || + !project?.destination_stack_id || + project?.content_mapper?.length === 0 || + !project?.current_test_stack_id || + !project?.isMigrationCompleted + ) { + logger.error( + getLogMessage( + srcFunc, + HTTP_TEXTS.CANNOT_PROCEED_MIGRATION, + token_payload + ) + ); + throw new BadRequestError( + HTTP_TEXTS.CANNOT_PROCEED_MIGRATION + ); + } + + ProjectModelLowdb.update((data: any) => { + data.projects[projectIndex].current_step = + STEPPER_STEPS.MIGRATION; + data.projects[projectIndex].status = NEW_PROJECT_STATUS[5]; + data.projects[projectIndex].updated_at = new Date().toISOString(); + }); + break; + } } logger.info( getLogMessage( diff --git a/api/src/services/runCli.service.ts b/api/src/services/runCli.service.ts index f47c14066..5cfa18671 100644 --- a/api/src/services/runCli.service.ts +++ b/api/src/services/runCli.service.ts @@ -59,6 +59,11 @@ export const runCli = async (rg: string, user_id: string, stack_uid: any, projec ProjectModelLowdb.write(); } await addCustomMessageInCliLogs(loggerPath, 'info', message); + !isTest && ProjectModelLowdb.update((data:any)=>{ + data.projects[projectIndex].isMigrationCompleted = true; + data.projects[projectIndex].isMigrationStarted = false; + + }) } }); diff --git a/ui/src/components/LogScreen/MigrationLogViewer.tsx b/ui/src/components/LogScreen/MigrationLogViewer.tsx index 8f0d94950..e600b5417 100644 --- a/ui/src/components/LogScreen/MigrationLogViewer.tsx +++ b/ui/src/components/LogScreen/MigrationLogViewer.tsx @@ -1,6 +1,6 @@ // Libraries import React, { useEffect, useState, useRef } from 'react'; -import { Icon, Notification, cbModal, Link } from '@contentstack/venus-components'; +import { Icon, cbModal, Link } from '@contentstack/venus-components'; import io from 'socket.io-client'; import { useSelector, useDispatch } from 'react-redux'; @@ -20,6 +20,8 @@ import useBlockNavigation from '../../hooks/userNavigation'; import './index.scss'; import { MAGNIFY,DEMAGNIFY } from '../../common/assets'; +import { updateCurrentStepData } from '../../services/api/migration.service'; +import { useParams } from 'react-router'; const logStyles: { [key: string]: React.CSSProperties } = { info: { backgroundColor: '#f1f1f1' }, @@ -30,6 +32,7 @@ const logStyles: { [key: string]: React.CSSProperties } = { type LogsType = { serverPath: string; + handleStepChange: (currentStep: number) => void; } /** @@ -41,11 +44,21 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { const [isModalOpen, setIsModalOpen] = useState(false); const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); + const selectedOrganisation = useSelector((state: RootState)=>state?.authentication?.selectedOrganisation); const dispatch = useDispatch(); + const { projectId = '' } = useParams(); + useEffect(() => { - const socket = io(serverPath || ''); // Connect to the server + const socket = io(serverPath || '',{ + reconnection:true, + }); // Connect to the server + + socket.on('disconnect', () => { + console.warn('Disconnected from server. Retrying...'); + setTimeout(() => socket.connect(), 3000); // Retry connection after 3 seconds + }); /** * Event listener for 'logUpdate' event. @@ -144,6 +157,13 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { dispatch(updateNewMigrationData((newMigrationDataObj))); + /** + * Updates the Migration excution step as completed in backend if migration completes. + */ + updateCurrentStepData(selectedOrganisation.value, projectId); + + + return cbModal({ component: (props: ModalObj) => ( { } - {(!newMigrationData?.migration_execution?.migrationStarted) && (
@@ -216,7 +235,7 @@ const MigrationLogViewer = ({ serverPath }: LogsType) => { {DEMAGNIFY}
- )} + ); }; diff --git a/ui/src/components/MigrationExecution/index.tsx b/ui/src/components/MigrationExecution/index.tsx index 8603c3386..af440cf97 100644 --- a/ui/src/components/MigrationExecution/index.tsx +++ b/ui/src/components/MigrationExecution/index.tsx @@ -22,8 +22,11 @@ import MigrationLogViewer from '../LogScreen/MigrationLogViewer'; //stylesheet import './index.scss'; +export type migrationWxecutionProps = { + handleStepChange: (currentStep: number) => void; +} -const MigrationExecution = () => { +const MigrationExecution = ({handleStepChange}: migrationWxecutionProps) => { const dispatch = useDispatch(); const migrationData = useSelector((state:RootState)=>state?.migration?.migrationData); @@ -113,7 +116,7 @@ const MigrationExecution = () => {
Execution Logs
- +
diff --git a/ui/src/components/MigrationFlowHeader/index.tsx b/ui/src/components/MigrationFlowHeader/index.tsx index 8f92f12a5..4c224f157 100644 --- a/ui/src/components/MigrationFlowHeader/index.tsx +++ b/ui/src/components/MigrationFlowHeader/index.tsx @@ -78,7 +78,7 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading, finalExecut const isExecutionStarted = finalExecutionStarted || - newMigrationData?.migration_execution?.migrationStarted; + newMigrationData?.migration_execution?.migrationStarted || newMigrationData?.migration_execution?.migrationCompleted; return (
diff --git a/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx b/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx index 15f5c1297..7128821c9 100644 --- a/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx +++ b/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx @@ -20,6 +20,7 @@ import useBlockNavigation from '../../../hooks/userNavigation'; // CSS import './HorizontalStepper.scss'; +import { MigrationResponse } from '../../../services/api/service.interface'; export enum StepStatus { @@ -45,6 +46,7 @@ export type stepperProps = { testId?: string; handleSaveCT?: () => void; changeDropdownState: () => void; + projectData: MigrationResponse; }; export type HorizontalStepperHandles = { @@ -80,6 +82,8 @@ const HorizontalStepper = forwardRef( const { stepId } = useParams<{ stepId: string }>(); const stepIndex = parseInt(stepId || '', 10) - 1; + + const newMigrationData = useSelector((state:RootState)=> state?.migration?.newMigrationData); const { steps, className, emptyStateMsg, hideTabView, testId } = props; const [showStep, setShowStep] = useState(stepIndex); @@ -89,7 +93,7 @@ const HorizontalStepper = forwardRef( const navigate = useNavigate(); const { projectId = '' } = useParams(); - const newMigrationData = useSelector((state:RootState)=> state?.migration?.newMigrationData); + const handleSaveCT = props?.handleSaveCT const handleDropdownChange = props?.changeDropdownState; @@ -102,6 +106,12 @@ const HorizontalStepper = forwardRef( !newMigrationData?.isprojectMapped && setShowStep(stepIndex); setStepsCompleted(prev => { const updatedStepsCompleted = [...prev]; + if (stepIndex === 4 && (props?.projectData?.isMigrationCompleted || newMigrationData?.migration_execution?.migrationCompleted)) { + + if (!updatedStepsCompleted?.includes(4)) { + updatedStepsCompleted.push(4); + } + } for (let i = 0; i < stepIndex; i++) { if (!updatedStepsCompleted?.includes(i)) { updatedStepsCompleted?.push(i); @@ -111,7 +121,7 @@ const HorizontalStepper = forwardRef( }); } - }, [stepId]); + }, [stepId, newMigrationData?.migration_execution?.migrationCompleted]); useImperativeHandle(ref, () => ({ handleStepChange: (currentStep: number) => { diff --git a/ui/src/components/TestMigration/index.tsx b/ui/src/components/TestMigration/index.tsx index 3f63aa0ac..ee4f8c274 100644 --- a/ui/src/components/TestMigration/index.tsx +++ b/ui/src/components/TestMigration/index.tsx @@ -81,13 +81,14 @@ const TestMigration = () => { */ useEffect(() => { // Check if the stack_api_key exists and evaluate the logic - const shouldDisable = newMigrationData?.test_migration?.stack_api_key + const shouldDisable = newMigrationData?.test_migration?.stack_api_key && !newMigrationData?.migration_execution?.migrationCompleted ? !newMigrationData?.testStacks?.some( (stack) => stack?.stackUid === newMigrationData?.test_migration?.stack_api_key && stack.isMigrated ) || newMigrationData?.test_migration?.isMigrationStarted - : false; + : newMigrationData?.migration_execution?.migrationCompleted || + newMigrationData?.migration_execution?.migrationStarted || false; setDisableCreateStack(shouldDisable); diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index 400d2395f..722160b6d 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -84,14 +84,6 @@ const Migration = () => { },[isProjectMapper]); - /** - * Updates the Migration excution step as completed if migration completes. - */ - useEffect(() => { - if (newMigrationData?.migration_execution?.migrationStarted) { - updateCurrentStepData(selectedOrganisation.value, projectId); - } - }, [newMigrationData?.migration_execution?.migrationStarted]) useBlockNavigation(isModalOpen); @@ -261,7 +253,9 @@ const Migration = () => { isMigrationComplete: newMigrationData?.test_migration?.isMigrationStarted || false }, migration_execution: { - migrationStarted: projectData?.isMigrationStarted + migrationStarted: projectData?.isMigrationStarted, + migrationCompleted: projectData?.isMigrationCompleted, + }, stackDetails: projectData?.stackDetails, testStacks: projectData?.test_stacks, @@ -309,7 +303,7 @@ const Migration = () => { title:'Run Test Migration' }, { - data: , + data: , id:'5', title:'Execute Migration' } @@ -568,7 +562,7 @@ const Migration = () => { }
- +
) diff --git a/ui/src/services/api/service.interface.ts b/ui/src/services/api/service.interface.ts index 96d043a98..711eeb50b 100644 --- a/ui/src/services/api/service.interface.ts +++ b/ui/src/services/api/service.interface.ts @@ -34,6 +34,9 @@ export interface MigrationResponse { updated_at: string; destination_stack_id: string; current_step: number; + isMigrationStarted: boolean; + isMigrationCompleted:boolean; + migration_execution: boolean; } export interface LegacyCms { @@ -59,7 +62,10 @@ export const defaultMigrationResponse: MigrationResponse = { updated_at: '', destination_stack_id: '', prefix: '', - current_step: 1 + current_step: 1, + isMigrationStarted: false, + isMigrationCompleted:false, + migration_execution: false, }; interface data { file_details : FileDetails; From 0aa320bd93bef5775137ccec896c20c5ea64d4b8 Mon Sep 17 00:00:00 2001 From: RohitKini <57343193+RohitKini@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:39:16 +0530 Subject: [PATCH 7/7] updated readme file --- api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/README.md b/api/README.md index 8936bbe3e..e92712735 100644 --- a/api/README.md +++ b/api/README.md @@ -1,4 +1,4 @@ -# migration-v2 +# migration-v2 API This is the migration V2's node server.