From c9eb883490c960a932e40ff0291bee3467dd2eb7 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Tue, 22 Oct 2024 11:53:30 +0530 Subject: [PATCH 1/2] Migration Execution api integration done --- .../DestinationStack/Actions/LoadStacks.tsx | 15 +++---- ui/src/components/LogScreen/index.tsx | 1 - .../components/MigrationFlowHeader/index.tsx | 2 +- ui/src/context/app/app.interface.ts | 14 ++++++- ui/src/pages/Migration/index.tsx | 41 ++++++++++++++++++- 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx index c2da08f8..2f1b34bd 100644 --- a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx @@ -116,7 +116,7 @@ const LoadStacks = (props: LoadFileFormatProps) => { updatedStackArray.sort( (a: IDropDown, b: IDropDown) => new Date(b?.created_at)?.getTime() - new Date(a?.created_at)?.getTime() - ); + ); setAllStack(updatedStackArray); @@ -215,30 +215,27 @@ const LoadStacks = (props: LoadFileFormatProps) => { setIsError(true); setErrorMessage("Please create new stack there is no stack available"); } + if(selectedStackData){ setSelectedStack(selectedStackData); setNewStackCreated(false); const newMigrationDataObj: INewMigration = { - ...newMigrationDataRef?.current, + // ...newMigrationDataRef?.current, + ...newMigrationData, destination_stack: { - ...newMigrationDataRef?.current?.destination_stack, + ...newMigrationData?.destination_stack, selectedStack: selectedStackData, stackArray: stackArray } }; // Dispatch the updated migration data to Redux dispatch(updateNewMigrationData(newMigrationDataObj)); - } } - } catch (error) { return error; - } - }; - const handleCreateNewStack = () => { cbModal({ @@ -288,7 +285,7 @@ const LoadStacks = (props: LoadFileFormatProps) => { // placeholder='Select a stack' placeholder={placeholder} - isClearable={newMigrationData?.destination_stack?.stackArray?.length > 0 && !emptyStackValue} + isClearable={allStack?.length > 0 && !emptyStackValue} // hideSelectedOptions={true} // isDisabled={props?.stepComponentProps?.isSummary || false} error={isLoading ? false : !!isError } diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 1cde4ac1..3715398d 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -155,7 +155,6 @@ const LogViewer = ({ serverPath, sendDataToParent }: LogsType) => { }; dispatch(updateNewMigrationData((newMigrationDataObj))); - } } catch (error) { console.error('Invalid JSON string', error); diff --git a/ui/src/components/MigrationFlowHeader/index.tsx b/ui/src/components/MigrationFlowHeader/index.tsx index 8d80a1f5..653f636f 100644 --- a/ui/src/components/MigrationFlowHeader/index.tsx +++ b/ui/src/components/MigrationFlowHeader/index.tsx @@ -70,7 +70,7 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading }: Migration version="v2" aria-label='Save and Continue' isLoading={isLoading} - disabled={params?.stepId === '4' && !newMigrationData?.test_migration?.isMigrationComplete} + disabled={(params?.stepId === '4' && !newMigrationData?.test_migration?.isMigrationComplete) || newMigrationData?.migration_execution?.migrationStarted} > {stepValue} diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index f540b53a..074a5148 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -132,7 +132,7 @@ export interface MigrationExecution { width: string; } export interface IMigrationExecution { - migration_information: MigrationExecution[]; + migration_information?: MigrationExecution[]; } interface ActionCta { @@ -185,6 +185,7 @@ export interface INewMigration { test_migration: ITestMigration; isprojectMapped: boolean; stackDetails: IDropDown; + migration_execution: IMigrationExecutionStep; } export interface TestStacks { @@ -220,6 +221,10 @@ export interface ITestMigration { isMigrationStarted: boolean; isMigrationComplete: boolean; } + +export interface IMigrationExecutionStep { + migrationStarted: boolean; +} export interface IAppContext { authToken: string; setAuthToken: (token: string) => void; @@ -334,6 +339,10 @@ export const DEFAULT_TEST_MIGRATION: ITestMigration = { isMigrationComplete: false }; +export const DEFAULT_MIGRATION_EXECUTION_STEP: IMigrationExecutionStep = { + migrationStarted: false +} + export const DEFAULT_NEW_MIGRATION: INewMigration = { mapperKeys: {}, legacy_cms: DEFAULT_LEGACY_CMS, @@ -342,7 +351,8 @@ export const DEFAULT_NEW_MIGRATION: INewMigration = { test_migration: DEFAULT_TEST_MIGRATION, isprojectMapped: false, stackDetails: DEFAULT_DROPDOWN, - testStacks: [] + testStacks: [], + migration_execution: DEFAULT_MIGRATION_EXECUTION_STEP }; export const DEFAULT_URL_TYPE: IURLType = { diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index 7fd03b56..a2c59d19 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -9,7 +9,7 @@ import { RootState } from '../../store'; import { updateMigrationData, updateNewMigrationData } from '../../store/slice/migrationDataSlice'; // Services -import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation, updateStackDetails, getExistingContentTypes, getExistingGlobalFields } from '../../services/api/migration.service'; +import { getMigrationData, updateCurrentStepData, updateLegacyCMSData, updateDestinationStack, updateAffixData, fileformatConfirmation, updateFileFormatData, affixConfirmation, updateStackDetails, getExistingContentTypes, getExistingGlobalFields, startMigration } from '../../services/api/migration.service'; import { getCMSDataFromFile } from '../../cmsData/cmsSelector'; // Utilities @@ -51,6 +51,8 @@ const Migration = () => { const [isCompleted, setIsCompleted] = useState(false); const [isProjectMapper, setIsProjectMapper] = useState(false); + const [migrationStarted, setMigrationStarted] = useState(false); + const params: Params = useParams(); const { projectId = '' } = useParams(); const navigate = useNavigate(); @@ -238,6 +240,9 @@ const Migration = () => { isMigrationStarted: false, isMigrationComplete: false }, + migration_execution: { + migrationStarted: migrationStarted + }, stackDetails: projectData?.stackDetails, testStacks: projectData?.test_stacks }; @@ -458,6 +463,37 @@ const Migration = () => { handleStepChange(4); } + const handleOnClickMigrationExecution = async () => { + setIsLoading(true); + + try { + const migrationRes = await startMigration(newMigrationData?.destination_stack?.selectedOrg?.value, projectId); + + console.log("migrationRes", migrationRes); + + if (migrationRes?.status === 200) { + setIsLoading(false); + setMigrationStarted(true) + Notification({ + notificationContent: { text: 'Migration Execution process started' }, + notificationProps: { + position: 'bottom-center', + hideProgressBar: false + }, + type: 'message' + }); + } + } catch (error) { + return error; + } + + const newMigrationDataObj: INewMigration = { + ...newMigrationData, + migration_execution: {migrationStarted: true} + }; + dispatch(updateNewMigrationData((newMigrationDataObj))); + } + const changeDropdownState = () =>{ const newMigrationDataObj: INewMigration = { ...newMigrationData, @@ -471,7 +507,8 @@ const Migration = () => { handleOnClickLegacyCms, handleOnClickDestinationStack, handleOnClickContentMapper, - handleOnClickTestMigration + handleOnClickTestMigration, + handleOnClickMigrationExecution ]; return ( From e2fd621729139cdc4fd99faa8d605cb11872db85 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Thu, 24 Oct 2024 13:17:31 +0530 Subject: [PATCH 2/2] Start button disabled after migration started --- api/src/models/project-lowdb.ts | 1 + api/src/services/migration.service.ts | 8 ++++++++ api/src/services/projects.service.ts | 3 ++- ui/src/components/LogScreen/index.tsx | 3 --- ui/src/components/MigrationExecution/index.tsx | 3 ++- ui/src/components/MigrationFlowHeader/index.tsx | 11 ++++++----- upload-api/src/controllers/sitecore/index.ts | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/api/src/models/project-lowdb.ts b/api/src/models/project-lowdb.ts index 6279d4c8..f2fb6d81 100644 --- a/api/src/models/project-lowdb.ts +++ b/api/src/models/project-lowdb.ts @@ -73,6 +73,7 @@ interface Project { stackDetails: []; mapperKeys: {}; extract_path: string; + isMigrationStarted: boolean; } interface ProjectDocument { diff --git a/api/src/services/migration.service.ts b/api/src/services/migration.service.ts index c886b213..b53c0054 100644 --- a/api/src/services/migration.service.ts +++ b/api/src/services/migration.service.ts @@ -236,6 +236,14 @@ const startMigration = async (req: Request): Promise => { const { region, user_id } = req?.body?.token_payload ?? {}; await ProjectModelLowdb.read(); const project = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value(); + + const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value(); + if (index > -1) { + ProjectModelLowdb.update((data: any) => { + data.projects[index].isMigrationStarted = true; + }); + } + const packagePath = project?.extract_path; if (packagePath && project?.destination_stack_id) { const loggerPath = path.join(process.cwd(), 'logs', projectId, `${project?.destination_stack_id}.log`); diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index db644bf0..3fc39673 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -125,7 +125,8 @@ const createProject = async (req: Request) => { created_at: '', isNewStack: false }, - mapperKeys: {} + mapperKeys: {}, + isMigrationStarted: false }; try { diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 3715398d..b1da010e 100644 --- a/ui/src/components/LogScreen/index.tsx +++ b/ui/src/components/LogScreen/index.tsx @@ -25,7 +25,6 @@ const logStyles: { [key: string]: React.CSSProperties } = { type LogsType = { serverPath: string; - isMigrationStarted?: boolean; sendDataToParent?: (isMigrationStarted: boolean) => void | undefined; } @@ -35,7 +34,6 @@ type LogsType = { */ const LogViewer = ({ serverPath, sendDataToParent }: LogsType) => { const [logs, setLogs] = useState(["Loading logs..."]); - const [isMigrationComplete, setIsMigrationComplete] = useState(false); const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); @@ -147,7 +145,6 @@ const LogViewer = ({ serverPath, sendDataToParent }: LogsType) => { type: 'success' }); sendDataToParent?.(false); - setIsMigrationComplete(true); const newMigrationDataObj: INewMigration = { ...newMigrationData, diff --git a/ui/src/components/MigrationExecution/index.tsx b/ui/src/components/MigrationExecution/index.tsx index e31031ab..a8f19803 100644 --- a/ui/src/components/MigrationExecution/index.tsx +++ b/ui/src/components/MigrationExecution/index.tsx @@ -7,7 +7,7 @@ import { getCMSDataFromFile } from '../../cmsData/cmsSelector'; // Redux import { RootState } from '../../store'; -import { setMigrationData, updateMigrationData } from '../../store/slice/migrationDataSlice'; +import { updateMigrationData } from '../../store/slice/migrationDataSlice'; // Utilities import { CS_ENTRIES } from '../../utilities/constants'; @@ -22,6 +22,7 @@ import LogViewer from '../LogScreen'; //stylesheet import './index.scss'; + const MigrationExecution = () => { const dispatch = useDispatch(); diff --git a/ui/src/components/MigrationFlowHeader/index.tsx b/ui/src/components/MigrationFlowHeader/index.tsx index f8be059e..df1a773d 100644 --- a/ui/src/components/MigrationFlowHeader/index.tsx +++ b/ui/src/components/MigrationFlowHeader/index.tsx @@ -17,10 +17,11 @@ type MigrationFlowHeaderProps = { isLoading: boolean; isCompleted: boolean; legacyCMSRef: React.MutableRefObject; - projectData:MigrationResponse + projectData:MigrationResponse; + finalExecutionStarted?: boolean; }; -const MigrationFlowHeader = ({projectData, handleOnClick, isLoading }: MigrationFlowHeaderProps) => { +const MigrationFlowHeader = ({projectData, handleOnClick, isLoading, finalExecutionStarted }: MigrationFlowHeaderProps) => { const [projectName, setProjectName] = useState(''); const [currentStep, setCurrentStep] = useState(0); @@ -53,7 +54,7 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading }: Migration } else { stepValue = 'Save and Continue'; } - + return (
@@ -69,9 +70,9 @@ const MigrationFlowHeader = ({projectData, handleOnClick, isLoading }: Migration onClick={handleOnClick} version="v2" aria-label='Save and Continue' - isLoading={isLoading} + isLoading={isLoading || newMigrationData?.isprojectMapped} disabled={(params?.stepId === '4' && !newMigrationData?.test_migration?.isMigrationComplete) || - (params?.stepId && params?.stepId <= '2' && currentStep.toString() !== params?.stepId) || newMigrationData?.migration_execution?.migrationStarted + (params?.stepId && params?.stepId <= '2' && newMigrationData?.project_current_step?.toString() !== params?.stepId) || finalExecutionStarted } > {stepValue} diff --git a/upload-api/src/controllers/sitecore/index.ts b/upload-api/src/controllers/sitecore/index.ts index 2e4b5ac3..c78bdd37 100644 --- a/upload-api/src/controllers/sitecore/index.ts +++ b/upload-api/src/controllers/sitecore/index.ts @@ -32,7 +32,7 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s fieldMapping.contentTypes.push(element); } } - console.log("🚀 ~ createSitecoreMapper ~ fieldMapping:", fieldMapping) + // console.log("🚀 ~ createSitecoreMapper ~ fieldMapping:", fieldMapping) const config = { method: 'post', maxBodyLength: Infinity,