Skip to content
Merged

Dev #305

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f4f8cb5
removed csdx utilities code
RohitKini Sep 12, 2024
817163a
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
RohitKini Sep 16, 2024
f14ecdd
added updated code
umeshmore45 Sep 16, 2024
049724c
Merge branch 'feature/merge_two' of https://github.com/contentstack/m…
RohitKini Sep 16, 2024
1c49aa6
added uid
umeshmore45 Sep 17, 2024
61d9485
logger functionality
RohitKini Sep 18, 2024
c8206fd
Merge branch 'feature/merge_two' of https://github.com/contentstack/m…
RohitKini Sep 18, 2024
4ff1b0a
logger functionality
RohitKini Sep 18, 2024
3bf2249
logger functionality
RohitKini Sep 18, 2024
461362d
added updated code
umeshmore45 Sep 19, 2024
5c605e6
added cli code
umeshmore45 Sep 19, 2024
74d321d
added bin
umeshmore45 Sep 19, 2024
a26cd52
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
RohitKini Sep 24, 2024
c456e3e
stacks limit check
RohitKini Sep 26, 2024
175eab7
Merge pull request #296 from contentstack/feature/rohit-updates
RohitKini Sep 26, 2024
1e11f79
Merge pull request #297 from contentstack/feature/merge_two
umeshmore45 Sep 30, 2024
e30acee
added create test route
RohitKini Sep 30, 2024
57ca484
Merge pull request #299 from contentstack/feature/rohit-updates
RohitKini Sep 30, 2024
10819d2
[CMG-311], [CMG-326]
sayalijoshi27 Oct 1, 2024
a0ae36f
Done changes in Contentmapper removed existing ct and global field st…
sayalijoshi27 Oct 1, 2024
ff43e2e
added test
umeshmore45 Oct 2, 2024
ff2deea
[CMG-82] - Create Project modal validation behaviour separated for na…
sayalijoshi27 Oct 3, 2024
ba89476
code added
umeshmore45 Oct 3, 2024
47bedd7
Merge pull request #300 from contentstack/feature/test-mig2
umeshmore45 Oct 3, 2024
418bb4d
Test Migration API integrated
sayalijoshi27 Oct 3, 2024
cd0581c
Merge pull request #301 from contentstack/bugfix/content-mapper
RohitKini Oct 4, 2024
cf19a63
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
sayalijoshi27 Oct 4, 2024
e5bd5e9
Test Migration API integrated
sayalijoshi27 Oct 3, 2024
bdcb680
rebased
umeshmore45 Oct 4, 2024
0e59657
Merge pull request #302 from contentstack/rebase
sayalijoshi27 Oct 4, 2024
8d34f28
Test migration button disabld and loader aaded
sayalijoshi27 Oct 4, 2024
1fc3d70
Merge pull request #303 from contentstack/feature/test-migration
RohitKini Oct 4, 2024
b5cf124
addded test ture boolean code
umeshmore45 Oct 4, 2024
561e04f
Merge pull request #304 from contentstack/feature/lowdb-fix
umeshmore45 Oct 4, 2024
2899517
Test Migration button disable changes
sayalijoshi27 Oct 4, 2024
8956f37
Merge pull request #306 from contentstack/feature/test-migration
sayalijoshi27 Oct 4, 2024
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
Prev Previous commit
Next Next commit
Test Migration API integrated
  • Loading branch information
sayalijoshi27 authored and umeshmore45 committed Oct 4, 2024
commit e5bd5e95dd54c1959b418a41068eefc4d78f35e8
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type HorizontalStepperHandles = {
handleStepChange: (currentStep: number) => void;
};

const showNotification = (currentIndex:number) =>{
const showNotification = (currentIndex:number) => {

let result;
switch (currentIndex ) {
Expand Down Expand Up @@ -97,6 +97,9 @@ const HorizontalStepper = forwardRef(

useEffect(() => {
const stepIndex = parseInt(stepId || '', 10) - 1;

console.log("stepIndex", stepIndex);


if (!Number.isNaN(stepIndex) && stepIndex >= 0 && stepIndex < steps?.length) {
setShowStep(stepIndex);
Expand Down Expand Up @@ -184,19 +187,18 @@ const HorizontalStepper = forwardRef(
const StepsTitleCreator: React.FC = () => (
<div className="stepper stepper-position">
{steps?.map(({ id, title }, idx: number) => {


const completedClass = stepsCompleted?.includes(idx) ? 'completed' : '';
const activeClass = idx === showStep && !stepsCompleted?.includes(idx)? 'active' : '';
const disableClass =
!stepsCompleted.includes(idx) && idx !== showStep && !stepsCompleted?.includes(idx - 1)
? 'disableEvents'
: '';
const completeDisable = stepsCompleted?.includes(idx) && idx < steps?.length - 1 ? 'completed disableEvents' : '';
return (
<React.Fragment key={id}>
<div className="stepWrapperContainer">
<div
className={`stepWrapper ${completedClass} ${activeClass} ${disableClass}`}
className={`stepWrapper ${completedClass} ${activeClass} ${disableClass} ${completeDisable}`}
onClick={() => handleTabStep(idx)}
>
<div className="circle-title-wrapper">
Expand Down
85 changes: 74 additions & 11 deletions ui/src/components/TestMigration/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { useEffect, useState } from 'react';
import { Field, FieldLabel, TextInput, Link, Icon, Tooltip, Button } from '@contentstack/venus-components';
import { useSelector } from 'react-redux';
import { useEffect, useState, useRef } from 'react';
import { useParams } from 'react-router';
import { Field, FieldLabel, TextInput, Link, Icon, Tooltip, Button, Notification } from '@contentstack/venus-components';
import { useSelector, useDispatch } from 'react-redux';

// Redux files
import { RootState } from '../../store';
import { updateNewMigrationData } from '../../store/slice/migrationDataSlice';


// Services
import { getCMSDataFromFile } from '../../cmsData/cmsSelector';
import { getOrgDetails, createTestStack, createTestMigration } from '../../services/api/migration.service';
import { getAllStacksInOrg } from '../../services/api/stacks.service';

// Utilities
import { CS_ENTRIES } from '../../utilities/constants';

// Interface
import { MigrationType } from './testMigration.interface';
import { INewMigration } from '../../context/app/app.interface';


// Component
import LogViewer from '../LogScreen';
Expand All @@ -22,9 +29,12 @@ import './index.scss';

const TestMigration = () => {
const [data, setData] = useState<MigrationType>({});
const [showLogs, setShowLogs] = useState<boolean>(false);

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

const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData);
const selectedOrganisation = useSelector((state: RootState)=>state?.authentication?.selectedOrganisation);
const { projectId = '' } = useParams();
const dispatch = useDispatch();

/********** ALL USEEFFECT HERE *************/
useEffect(() => {
Expand All @@ -37,6 +47,60 @@ const TestMigration = () => {
});
}, []);

console.log("projectId", projectId);


// Method to create test stack
const handleCreateTestStack = async () => {
//get org plan details
const orgDetails = await getOrgDetails(selectedOrganisation?.value);
const stacks_details_key = Object.keys(orgDetails?.data?.organization?.plan?.features).find(key => orgDetails?.data?.organization?.plan?.features[key].uid === 'stacks') || '';

const max_stack_limit = orgDetails?.data?.organization?.plan?.features[stacks_details_key]?.max_limit;

const stackData = await getAllStacksInOrg(selectedOrganisation?.value, ''); // org id will always be there

const stack_count = stackData?.data?.stacks?.length;

if (stack_count >= max_stack_limit) {
// setIsLoading(false);
Notification({
notificationContent: { text: 'You have reached the maximum limit of stacks for your organization' },
type: 'warning'
});
return;
}

const data = {
name: newMigrationData?.destination_stack?.selectedStack?.label,
description: 'test migration stack',
master_locale: newMigrationData?.destination_stack?.selectedStack?.master_locale
};

const res = await createTestStack(
newMigrationData?.destination_stack?.selectedOrg?.value,
projectId,
data
);

const newMigrationDataObj: INewMigration = {
...newMigrationData,
test_migration: { stack_link: res?.data?.data?.url, stack_api_key: res?.data?.data?.data?.stack?.api_key }
};

dispatch(updateNewMigrationData((newMigrationDataObj)));
}

const handleTestMigration = async () => {
const testRes = await createTestMigration(
newMigrationData?.destination_stack?.selectedOrg?.value,
projectId
);

console.log("testRes", testRes);

}

return (
<div className='migration-step-container'>
<div className='content-block'>
Expand All @@ -45,7 +109,7 @@ const TestMigration = () => {
<p>Test Migration is a step where some content types are migrated in a test stack for review. A user can verify the stack and data. If the data is migrated properly then it can proceed with the final Migration Execution process.</p>
<Button
className="mt-3"
// onClick={handleSaveContentType}
onClick={handleCreateTestStack}
version="v2"
// size="medium"
>
Expand Down Expand Up @@ -85,10 +149,10 @@ const TestMigration = () => {
)}

<Button
className="mt-3"
// onClick={handleSaveContentType}
className="ml-8"
onClick={handleTestMigration}
version="v2"
// size="medium"
// size="medium"
>
Start Test Migration
</Button>
Expand All @@ -97,11 +161,10 @@ const TestMigration = () => {
}
</div>
</div>

<div className='content-block'>
<div className='content-header'>Execution Logs</div>
<div>
<LogViewer serverPath="http://localhost:5001" />
<LogViewer serverPath={process.env.REACT_APP_BASE_API_URL ?? ''} />
</div>
</div>
</div>
Expand Down
81 changes: 6 additions & 75 deletions ui/src/pages/Migration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,26 +390,7 @@ const Migration = () => {
const handleOnClickContentMapper = async (event: MouseEvent) => {
setIsModalOpen(true);

//get org plan details
const orgDetails = await getOrgDetails(selectedOrganisation?.value);
const stacks_details_key = Object.keys(orgDetails?.data?.organization?.plan?.features).find(key => orgDetails?.data?.organization?.plan?.features[key].uid === 'stacks') || '';

const max_stack_limit = orgDetails?.data?.organization?.plan?.features[stacks_details_key]?.max_limit;

const stackData = await getAllStacksInOrg(selectedOrganisation?.value, ''); // org id will always be there

const stack_count = stackData?.data?.stacks?.length;

if (stack_count >= max_stack_limit) {
setIsLoading(false);
Notification({
notificationContent: { text: 'You have reached the maximum limit of stacks for your organization' },
type: 'warning'
});
return;
}

if(newMigrationData?.content_mapping?.isDropDownChanged){
if(newMigrationData?.content_mapping?.isDropDownChanged) {
return cbModal({
component: (props: ModalObj) => (
<SaveChangesModal
Expand All @@ -418,36 +399,12 @@ const Migration = () => {
otherCmsTitle={newMigrationData?.content_mapping?.otherCmsTitle}
saveContentType={saveRef?.current?.handleSaveContentType}
changeStep={async () => {
setIsLoading(true);
const data = {
name: newMigrationData?.destination_stack?.selectedStack?.label,
description: 'test migration stack',
master_locale: newMigrationData?.destination_stack?.selectedStack?.master_locale
};

const res = await createTestStack(
newMigrationData?.destination_stack?.selectedOrg?.value,
projectId,
data
);

if (res?.status) {
setIsLoading(false);
const newMigrationDataObj: INewMigration = {
...newMigrationData,
content_mapping: { ...newMigrationData?.content_mapping, isDropDownChanged: false },

test_migration: { stack_link: res?.data?.data?.url, stack_api_key: res?.data?.data?.data?.stack?.api_key }
};

dispatch(updateNewMigrationData((newMigrationDataObj)));

const url = `/projects/${projectId}/migration/steps/4`;
navigate(url, { replace: true });

await updateCurrentStepData(selectedOrganisation.value, projectId);
handleStepChange(3);
}}}
}}
dropdownStateChange={changeDropdownState}
/>
),
Expand All @@ -460,38 +417,12 @@ const Migration = () => {
}
else{
event.preventDefault();
setIsLoading(true);
const data = {
name: newMigrationData?.destination_stack?.selectedStack?.label,
description: 'test migration stack',
master_locale: newMigrationData?.destination_stack?.selectedStack?.master_locale
};

const res = await createTestStack(
newMigrationData?.destination_stack?.selectedOrg?.value,
projectId,
data
);

const newMigrationDataObj: INewMigration = {
...newMigrationData,
test_migration: { stack_link: res?.data?.data?.url, stack_api_key: res?.data?.data?.data?.stack?.api_key }
};

dispatch(updateNewMigrationData((newMigrationDataObj)));
if (res?.status) {
setIsLoading(false);

const url = `/projects/${projectId}/migration/steps/4`;
navigate(url, { replace: true });

await updateCurrentStepData(selectedOrganisation.value, projectId);
handleStepChange(3);
}
const url = `/projects/${projectId}/migration/steps/4`;
navigate(url, { replace: true });

await updateCurrentStepData(selectedOrganisation.value, projectId);
handleStepChange(3);
}



}

Expand Down
33 changes: 20 additions & 13 deletions ui/src/services/api/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,6 @@ export const resetToInitialMapping = async (
}
};

export const createTestStack = async (orgId: string, projectId: string, data: ObjectType) => {
try {
return await postCall(
`${API_VERSION}/migration/test-stack/${orgId}/${projectId}`,
data,
options
);
} catch (error) {
return error;
}
};

export const fetchExistingContentType = async (projectId: string, contentTypeUid: string) => {
try {
return await getCall(`${API_VERSION}/mapper/${projectId}/${contentTypeUid}`, options);
Expand Down Expand Up @@ -303,4 +291,23 @@ export const getOrgDetails = async(orgId: string) => {
}
}

// const { orgId } = req.params;
export const createTestStack = async (orgId: string, projectId: string, data: ObjectType) => {
try {
return await postCall(
`${API_VERSION}/migration/create-test-stack/${orgId}/${projectId}`,
data,
options
);
} catch (error) {
return error;
}
};

export const createTestMigration = async (orgId: string, projectId: string) => {
try {
return await postCall(
`${API_VERSION}/migration/test-stack/${orgId}/${projectId}`, options);
} catch (error) {
return error;
}
};