diff --git a/api/src/models/project-lowdb.ts b/api/src/models/project-lowdb.ts index e5c03ce9c..a00675836 100644 --- a/api/src/models/project-lowdb.ts +++ b/api/src/models/project-lowdb.ts @@ -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. */ @@ -61,7 +69,7 @@ interface Project { isDeleted: boolean; isNewStack: boolean; newStackId: string; - stackDetails: []; + stackDetails: StackDetails; mapper_keys: []; } diff --git a/api/src/routes/projects.routes.ts b/api/src/routes/projects.routes.ts index 0150500a7..3e737f783 100644 --- a/api/src/routes/projects.routes.ts +++ b/api/src/routes/projects.routes.ts @@ -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)); diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index 57593b4d3..74019304d 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -119,7 +119,12 @@ const createProject = async (req: Request) => { isDeleted: false, isNewStack: false, newStackId: "", - stackDetails: [], + stackDetails: { + uid: '', + label: '', + master_locale: '', + created_at: '', + } }; try { diff --git a/ui/src/components/DestinationStack/index.tsx b/ui/src/components/DestinationStack/index.tsx index f048a708a..4758ad0f8 100644 --- a/ui/src/components/DestinationStack/index.tsx +++ b/ui/src/components/DestinationStack/index.tsx @@ -36,7 +36,7 @@ const DestinationStackComponent = ({ handleOnAllStepsComplete, }: DestinationStackComponentProps) => { /** ALL HOOKS HERE */ - const [isLoading, setIsLoading] = useState(true); + // const [isCompleted, setIsCompleted] = useState(false); const [isMigrationLocked, setIsMigrationLocked] = useState(false); const [stepperKey] = useState('destination-Vertical-stepper'); @@ -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(newMigrationData?.isprojectMapped); // const { projectId = '' } = useParams(); @@ -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 @@ -183,9 +184,9 @@ const DestinationStackComponent = ({ }, []); - useEffect(() => { - updateDestinationStackData(); - }, [selectedOrganisation]); + // useEffect(() => { + // updateDestinationStackData(); + // }, [selectedOrganisation]); useEffect(() => { if (autoVerticalStepperComponent?.current) { diff --git a/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx b/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx index 070aede17..44c918a0a 100644 --- a/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx @@ -162,10 +162,11 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => { filterCMSData(searchText); }, []); - useEffect(() => { - filterCMSData(searchText); - }, [cmsFilter]); + // useEffect(() => { + // filterCMSData(searchText); + // }, [cmsFilter]); + return (
diff --git a/ui/src/components/LegacyCms/index.tsx b/ui/src/components/LegacyCms/index.tsx index e78a863df..816ab9408 100644 --- a/ui/src/components/LegacyCms/index.tsx +++ b/ui/src/components/LegacyCms/index.tsx @@ -58,7 +58,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll /** ALL HOOKS HERE */ const [isMigrationLocked, setIsMigrationLocked] = useState(false); - const [isLoading, setIsLoading] = useState(true); + const [isLoading, setIsLoading] = useState(newMigrationData?.isprojectMapped); const [internalActiveStepIndex, setInternalActiveStepIndex] = useState(-1); const [stepperKey] = useState('legacy-Vertical-stepper'); @@ -230,8 +230,7 @@ const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAll }, [internalActiveStepIndex]); - - + useEffect(()=>{ if (!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id)) { setInternalActiveStepIndex(0); diff --git a/ui/src/components/Stepper/VerticalStepper/AutoVerticalStepper.tsx b/ui/src/components/Stepper/VerticalStepper/AutoVerticalStepper.tsx index d69e858c9..d50a592f6 100644 --- a/ui/src/components/Stepper/VerticalStepper/AutoVerticalStepper.tsx +++ b/ui/src/components/Stepper/VerticalStepper/AutoVerticalStepper.tsx @@ -84,7 +84,7 @@ const AutoVerticalStepper = React.forwardRef<
- {isRequired && (required) } + {isRequired || data?.isRequired && (required) } {data?.ifReadonly && (read only)}
{data.titleNote ? data.titleNote : ''} diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index 8bfb62830..d1067b832 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -177,6 +177,7 @@ export interface INewMigration { destination_stack: IDestinationStack; content_mapping: IContentMapper; test_migration: ITestMigration; + isprojectMapped: boolean; } export interface IMigrationData { @@ -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 = { diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index e3fbf1201..e2cfa2aa7 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -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 @@ -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'; @@ -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 = { @@ -56,6 +58,7 @@ const Migration = () => { const [isLoading, setIsLoading] = useState(false); const [curreentStepIndex, setCurrentStepIndex] = useState(0); const [isCompleted, setIsCompleted] = useState(false); + const [isProjectMapper, setIsProjectMapper] = useState(false); const params: Params = useParams(); const { projectId = '' } = useParams(); @@ -66,6 +69,7 @@ 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(null); @@ -73,6 +77,15 @@ const Migration = () => { fetchData(); }, [params?.stepId, params?.projectId, selectedOrganisation?.value]); + useEffect(()=>{ + dispatch(updateNewMigrationData({ + ...newMigrationData, + isprojectMapped : isProjectMapper + + })); + + },[isProjectMapper]); + const fetchData = async () => { setIsLoading(true); @@ -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); @@ -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 = [ @@ -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) { @@ -399,15 +429,18 @@ const Migration = () => { } return ( + +
-
- { projectData && + { projectData && }
+ + ) } diff --git a/ui/src/services/api/migration.service.ts b/ui/src/services/api/migration.service.ts index 485bf0344..f32c44068 100644 --- a/ui/src/services/api/migration.service.ts +++ b/ui/src/services/api/migration.service.ts @@ -1,7 +1,7 @@ import { ObjectType } from '../../utilities/constants.interface'; import { API_VERSION } from '../../utilities/constants'; import { getDataFromLocalStorage } from '../../utilities/functions'; -import { getCall, postCall, putCall } from './service'; +import { getCall, patchCall, postCall, putCall } from './service'; const options = { headers: { @@ -238,3 +238,17 @@ export const removeContentMapper = async(orgId: string, projectId: string) => { } } + +export const updateStackDetails = async(orgId: string, projectId: string, data:any)=>{ + try { + const Data = { + stack_details:data + + }; + return await patchCall(`${API_VERSION}/org/${orgId}/project/${projectId}/stack-details`, Data,options) + + } catch (error) { + return error; + + } +} \ No newline at end of file