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/DestinationStack/Actions/LoadStacks.tsx b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx index 4acb1b2c..6b48ede3 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={newMigrationData?.project_current_step > 2} error={isLoading ? false : !!isError } diff --git a/ui/src/components/LogScreen/index.tsx b/ui/src/components/LogScreen/index.tsx index 1cde4ac1..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, @@ -155,7 +152,6 @@ const LogViewer = ({ serverPath, sendDataToParent }: LogsType) => { }; dispatch(updateNewMigrationData((newMigrationDataObj))); - } } catch (error) { console.error('Invalid JSON string', error); 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 da0d78e3..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) + (params?.stepId && params?.stepId <= '2' && newMigrationData?.project_current_step?.toString() !== params?.stepId) || finalExecutionStarted } > {stepValue} diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index d7440849..e66aaade 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -136,7 +136,7 @@ export interface MigrationExecution { width: string; } export interface IMigrationExecution { - migration_information: MigrationExecution[]; + migration_information?: MigrationExecution[]; } interface ActionCta { @@ -189,7 +189,8 @@ export interface INewMigration { test_migration: ITestMigration; isprojectMapped: boolean; stackDetails: IDropDown; - project_current_step:number; + migration_execution: IMigrationExecutionStep; + project_current_step: number; } export interface TestStacks { @@ -225,6 +226,10 @@ export interface ITestMigration { isMigrationStarted: boolean; isMigrationComplete: boolean; } + +export interface IMigrationExecutionStep { + migrationStarted: boolean; +} export interface IAppContext { authToken: string; setAuthToken: (token: string) => void; @@ -340,6 +345,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, @@ -349,6 +358,7 @@ export const DEFAULT_NEW_MIGRATION: INewMigration = { isprojectMapped: false, stackDetails: DEFAULT_DROPDOWN, testStacks: [], + migration_execution: DEFAULT_MIGRATION_EXECUTION_STEP, project_current_step: 0, }; diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index 2eadd316..ab6b1478 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(); @@ -237,6 +239,9 @@ const Migration = () => { isMigrationStarted: false, isMigrationComplete: false }, + migration_execution: { + migrationStarted: migrationStarted + }, stackDetails: projectData?.stackDetails, testStacks: projectData?.test_stacks, project_current_step: projectData?.current_step, @@ -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 ( 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,