diff --git a/ui/package-lock.json b/ui/package-lock.json index 84ea7ab82..aa1bea4b4 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -17,7 +17,7 @@ "@types/react": "^18.2.28", "@types/react-dom": "^18.2.13", "@types/react-redux": "^7.1.33", - "axios": "^1.8.2", + "axios": "^1.7.8", "bootstrap": "5.1.3", "chokidar": "^3.6.0", "final-form": "^4.20.10", @@ -6905,9 +6905,9 @@ } }, "node_modules/axios": { - "version": "1.8.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.3.tgz", - "integrity": "sha512-iP4DebzoNlP/YN2dpwCgb8zoCmhtkajzS48JvwmkSkXvPI3DHc7m+XYL5tGnSlJtR6nImXZmdCuN5aP8dh1d8A==", + "version": "1.7.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.8.tgz", + "integrity": "sha512-Uu0wb7KNqK2t5K+YQyVCLM76prD5sRFjKHbJYCP1J7JFGEQ6nN7HWn9+04LAeiJ3ji54lgS/gZCH1oxyrf1SPw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index e4efceb41..354d0f9f6 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -32,7 +32,7 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { const [isCheckedBoxChecked] = useState( newMigrationData?.legacy_cms?.isFileFormatCheckboxChecked || true ); - const [fileIcon, setFileIcon] = useState(newMigrationData?.legacy_cms?.selectedFileFormat?.title); + const [fileIcon, setFileIcon] = useState(newMigrationDataRef?.current?.legacy_cms?.selectedFileFormat?.title); const [isError, setIsError] = useState(false); const [error, setError] = useState(''); @@ -55,33 +55,13 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { } }; - const getFileExtension = (filePath: string): string => { - const normalizedPath = filePath?.replace(/\\/g, '/')?.replace(/\/$/, ''); - - // Use regex to extract the file extension - const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/); - const ext = match ? match[1]?.toLowerCase() : ''; - - const fileName = filePath?.split('/')?.pop(); - //const ext = fileName?.split('.')?.pop(); - const validExtensionRegex = /\.(pdf|zip|xml|json)$/i; - return ext && validExtensionRegex?.test(`.${ext}`) ? `${ext}` : ''; - }; - - const handleFileFormat = async () => { + const handleFileFormat = async() =>{ try { - const { data } = await getConfig(); - - const cmsType = !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent) - ? newMigrationData?.legacy_cms?.selectedCms?.parent - : data?.cmsType?.toLowerCase(); - const filePath = data?.localPath?.toLowerCase(); - const fileFormat = getFileExtension(filePath); - if ( - !isEmptyString(selectedCard?.fileformat_id) && - selectedCard?.fileformat_id !== fileFormat && - newMigrationData?.project_current_step > 1 - ) { + + const cmsType = !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent) ? newMigrationData?.legacy_cms?.selectedCms?.parent : newMigrationData?.legacy_cms?.uploadedFile?.cmsType; + const filePath = newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath?.toLowerCase(); + const fileFormat: string = newMigrationData?.legacy_cms?.selectedFileFormat?.title?.toLowerCase(); + if(! isEmptyString(selectedCard?.fileformat_id) && selectedCard?.fileformat_id !== fileFormat && newMigrationData?.project_current_step > 1){ setFileIcon(selectedCard?.title); } else { const { all_cms = [] } = migrationData?.legacyCMSData || {}; @@ -103,32 +83,18 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { setIsError(true); setError('File format does not support, please add the correct file format.'); } - + const selectedFileFormatObj = { description: '', fileformat_id: fileFormat, group_name: fileFormat, isactive: true, - title: - fileFormat === 'zip' - ? fileFormat?.charAt(0)?.toUpperCase() + fileFormat?.slice(1) - : fileFormat?.toUpperCase() - }; - - const newMigrationDataObj = { - ...newMigrationDataRef?.current, - legacy_cms: { - ...newMigrationDataRef?.current?.legacy_cms, - selectedFileFormat: selectedFileFormatObj, - } - }; + title: fileFormat === 'zip' ? fileFormat?.charAt?.(0)?.toUpperCase() + fileFormat?.slice?.(1) : fileFormat?.toUpperCase() + } + + + setFileIcon(fileFormat === 'zip' ? fileFormat?.charAt?.(0).toUpperCase() + fileFormat?.slice?.(1) : fileFormat?.toUpperCase()); - setFileIcon( - fileFormat === 'zip' - ? fileFormat?.charAt(0).toUpperCase() + fileFormat.slice(1) - : fileFormat?.toUpperCase() - ); - dispatch(updateNewMigrationData(newMigrationDataObj)); } } catch (error) { return error; @@ -138,13 +104,13 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { /**** ALL USEEffects HERE ****/ useEffect(() => { handleFileFormat(); - //handleBtnClick(); },[]); useEffect(() => { newMigrationDataRef.current = newMigrationData; }, [newMigrationData]); + return (
diff --git a/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx b/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx index d560b92ad..f5927d09d 100644 --- a/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx @@ -1,7 +1,7 @@ import { useEffect, useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { FileDetails, ICMSType, INewMigration } from '../../../context/app/app.interface'; -import { fileValidation, getConfig } from '../../../services/api/upload.service'; +import { fileValidation } from '../../../services/api/upload.service'; import { RootState } from '../../../store'; import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice'; import { Button, CircularLoader, Paragraph } from '@contentstack/venus-components'; @@ -73,12 +73,8 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { const newMigrationDataRef = useRef(newMigrationData); const dispatch = useDispatch(); const [isLoading, setIsLoading] = useState(false); - const [isValidated, setIsValidated] = useState( - newMigrationData?.legacy_cms?.uploadedFile?.isValidated - ); - const [showMessage, setShowMessage] = useState( - newMigrationData?.legacy_cms?.uploadedFile?.isValidated - ); + const [isValidated, setIsValidated] = useState(newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.isValidated); + const [showMessage, setShowMessage] = useState(newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.isValidated); const [validationMessgae, setValidationMessage] = useState(''); const [isValidationAttempted, setIsValidationAttempted] = useState(false); const [isDisabled, setIsDisabled] = useState( @@ -86,10 +82,8 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix) ); const [isConfigLoading, setIsConfigLoading] = useState(false); - const [cmsType, setCmsType] = useState(''); - const [fileDetails, setFileDetails] = useState( - newMigrationData?.legacy_cms?.uploadedFile?.file_details - ); + const [cmsType, setCmsType]= useState(''); + const [fileDetails, setFileDetails] = useState(newMigrationDataRef?.current?.legacy_cms?.uploadedFile?.file_details); const [fileExtension, setFileExtension] = useState(''); const [progressPercentage, setProgressPercentage] = useState(0); const [showProgress, setShowProgress] = useState(false); @@ -142,7 +136,9 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { bucketName: data?.file_details?.awsData?.bucketName, buketKey: data?.file_details?.awsData?.buketKey } - } + }, + cmsType: data?.cmsType + } } }; @@ -222,108 +218,71 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { //function to get config details const getConfigDetails = async () => { try { - setIsConfigLoading(true); - const { data, status } = await getConfig(); - - if ( - !isEmptyString(fileDetails?.localPath) && - data?.localPath !== fileDetails?.localPath && - !isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix) - ) { - setIsDisabled(false); - setShowMessage(true); - setValidationMessage(''); + //setIsConfigLoading(true); + + if (!isEmptyString(fileDetails?.localPath) && newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath !== fileDetails?.localPath && !isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix)) { + setIsDisabled(false); + setShowMessage(true); + setValidationMessage(''); + + } + + const extension = getFileExtension(newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath || ''); + setCmsType(newMigrationData?.legacy_cms?.uploadedFile?.cmsType); + //setFileDetails(data); + setFileExtension(extension); + + + const { all_cms = [] } = migrationData?.legacyCMSData || {}; + let filteredCmsData:ICMSType[] = all_cms; + if (newMigrationData?.legacy_cms?.uploadedFile?.cmsType) { + filteredCmsData = all_cms?.filter((cms: ICMSType) => cms?.parent?.toLowerCase() === newMigrationData?.legacy_cms?.uploadedFile?.cmsType?.toLowerCase()); } - - if (status === 200) { - const extension = getFileExtension(data?.localPath); - setCmsType(data?.cmsType); - setFileDetails(data); - setFileExtension(extension); - - const newMigrationDataObj: INewMigration = { - ...newMigrationDataRef?.current, + + const isFormatValid = filteredCmsData[0]?.allowed_file_formats?.some((format: ICardType) => { + const isValid = format?.fileformat_id?.toLowerCase() === extension; + return isValid; + }); + + + //setIsFormatValid(isFormatValid); + setIsDisabled(!isFormatValid || isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix)); + if(!isFormatValid){ + setValidationMessage(''); + dispatch(updateNewMigrationData({ + ...newMigrationData, legacy_cms: { - ...newMigrationDataRef?.current?.legacy_cms, uploadedFile: { - name: data?.localPath, - url: data?.localPath, - isValidated: newMigrationData?.legacy_cms?.uploadedFile?.isValidated, - reValidate: false, - file_details: { - isLocalPath: data?.isLocalPath, - cmsType: data?.cmsType, - localPath: data?.localPath, - awsData: { - awsRegion: data?.awsData?.awsRegion, - bucketName: data?.awsData?.bucketName, - buketKey: data?.awsData?.buketKey - } - } + isValidated: false, } - } - }; - if (isEmptyString(newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath)) { - dispatch(updateNewMigrationData(newMigrationDataObj)); - } - - const { all_cms = [] } = migrationData?.legacyCMSData || {}; - let filteredCmsData: ICMSType[] = all_cms; - if (data?.cmsType) { - filteredCmsData = all_cms?.filter( - (cms: ICMSType) => cms?.parent?.toLowerCase() === data?.cmsType?.toLowerCase() - ); - } - const isFormatValid = filteredCmsData[0]?.allowed_file_formats?.some( - (format: ICardType) => { - const isValid = format?.fileformat_id?.toLowerCase() === extension; - return isValid; } - ); - - //setIsFormatValid(isFormatValid); - - setIsDisabled( - !isFormatValid || isEmptyString(newMigrationDataRef?.current?.legacy_cms?.affix) - ); - if (!isFormatValid) { - setValidationMessage(''); - dispatch( - updateNewMigrationData({ - ...newMigrationData, - legacy_cms: { - uploadedFile: { - isValidated: false - } - } - }) - ); - } - } - if ( - !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent?.toLowerCase()) && - newMigrationData?.legacy_cms?.selectedCms?.parent.toLowerCase() !== - data?.cmsType.toLowerCase() - ) { - setIsValidated(false); - setValidationMessage('file format is not appropriate'); - setIsValidationAttempted(true); - setShowMessage(true); - setIsLoading(false); - setIsDisabled(true); - } - setIsConfigLoading(false); + })) + + } + + + //} + // if((! isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.parent?.toLowerCase()) && + // newMigrationData?.legacy_cms?.selectedCms?.parent.toLowerCase() !== data?.cmsType.toLowerCase())) + // { + // setIsValidated(false); + // setValidationMessage('file format is not appropriate'); + // setIsValidationAttempted(true); + // setShowMessage(true); + // setIsLoading(false); + // setIsDisabled(true); + // } + setIsConfigLoading(false); + } catch (error) { return error; } }; useEffect(() => { - if (isEmptyString(newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath)) { - getConfigDetails(); - } + getConfigDetails(); }, []); useEffect(() => { @@ -333,7 +292,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { setIsConfigLoading(savedState.isConfigLoading); setIsValidated(savedState?.isValidated); setValidationMessage(savedState?.validationMessage); - setIsDisabled(savedState?.isDisabled); + //setIsDisabled(savedState?.isDisabled); setCmsType(savedState.cmsType); //setFileDetails(savedState.fileDetails); setFileExtension(savedState.fileExtension); @@ -402,10 +361,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { if (newMigrationData?.legacy_cms?.uploadedFile?.reValidate) { setValidationMessage(''); } - if ( - !isEmptyString(newMigrationData?.legacy_cms?.affix) && - !newMigrationData?.legacy_cms?.uploadedFile?.isValidated - ) { + if(!isEmptyString(newMigrationData?.legacy_cms?.affix) && !newMigrationData?.legacy_cms?.uploadedFile?.isValidated && !newMigrationData?.legacy_cms?.uploadedFile?.reValidate){ setIsDisabled(false); } setReValidate(newMigrationData?.legacy_cms?.uploadedFile?.reValidate || false); @@ -429,7 +385,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { const sanitizedCmsType = cmsType?.toLowerCase().replace(/[^\w\s-]/g, ''); const documentationUrl = VALIDATION_DOCUMENTATION_URL?.[sanitizedCmsType]; - + const validationClassName = isValidated ? 'success' : 'error'; const containerClassName = `validation-container ${ @@ -490,7 +446,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => { isLoading={isLoading} loadingColor="#6c5ce7" version="v2" - disabled={isDisabled || isEmptyString(affix) || reValidate} + disabled={!(reValidate || (!isDisabled && !isEmptyString(newMigrationData?.legacy_cms?.affix)))} > Validate File diff --git a/ui/src/components/LegacyCms/index.tsx b/ui/src/components/LegacyCms/index.tsx index 4215fb737..347880869 100644 --- a/ui/src/components/LegacyCms/index.tsx +++ b/ui/src/components/LegacyCms/index.tsx @@ -46,21 +46,24 @@ export interface AutoVerticalStepperRef { handleDynamicStepChange: (stepIndex: number, isLastStep?: boolean) => void; } -const LegacyCMSComponent = forwardRef( - ({ legacyCMSData, isCompleted, handleOnAllStepsComplete }: LegacyCMSComponentProps, ref) => { - //react-redux apis - const migrationData = useSelector((state: RootState) => state?.migration?.migrationData); - const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); - const dispatch = useDispatch(); - - /** ALL HOOKS HERE */ - const [isMigrationLocked, setIsMigrationLocked] = useState(false); - const [isLoading, setIsLoading] = useState(newMigrationData?.isprojectMapped); - const [internalActiveStepIndex, setInternalActiveStepIndex] = useState(-1); - const [stepperKey] = useState('legacy-Vertical-stepper'); - - const [isAllStepsCompleted, setIsAllStepsCompleted] = useState(false); - const autoVerticalStepper = useRef(null); + +const LegacyCMSComponent = forwardRef(({ legacyCMSData, isCompleted, handleOnAllStepsComplete, }: LegacyCMSComponentProps, ref) => { + //react-redux apis + const migrationData = useSelector((state:RootState)=>state?.migration?.migrationData); + const newMigrationData = useSelector((state:RootState)=>state?.migration?.newMigrationData); + const dispatch = useDispatch(); + + + /** ALL HOOKS HERE */ + const [isMigrationLocked, setIsMigrationLocked] = useState(false); + const [isLoading, setIsLoading] = useState(true); + const [internalActiveStepIndex, setInternalActiveStepIndex] = useState(-1); + const [stepperKey] = useState('legacy-Vertical-stepper'); + + const [isAllStepsCompleted, setIsAllStepsCompleted] = useState(false); + const [isProjectMapped, setisProjectMapped] = useState(newMigrationData?.isprojectMapped); + const autoVerticalStepper = useRef(null); + //Handle on all steps are completed const handleAllStepsComplete = (flag = false) => { @@ -151,26 +154,6 @@ const LegacyCMSComponent = forwardRef( ) { setInternalActiveStepIndex(2); } - dispatch(updateNewMigrationData({ - ...newMigrationData, - legacy_cms: { - currentStep: internalActiveStepIndex, - selectedCms: selectedCmsData, - selectedFileFormat: selectedFileFormatData, - uploadedFile: { - file_details:{ - localPath: legacyCMSData?.file_path, - awsData: legacyCMSData?.awsDetails, - isLocalPath: legacyCMSData?.is_localPath - }, - isValidated: legacyCMSData?.is_fileValid, - reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate - }, //need to add backend data once endpoint exposed. - affix: legacyCMSData?.affix ?? '', - isFileFormatCheckboxChecked: true, //need to add backend data once endpoint exposed. - isRestictedKeywordCheckboxChecked: true //need to add backend data once endpoint exposed. - } - })) setIsLoading(false); //Check for migration Status and lock. @@ -220,59 +203,56 @@ const LegacyCMSComponent = forwardRef( setInternalActiveStepIndex(1); } - if ( - !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && - !isEmptyString(newMigrationData?.legacy_cms?.affix) && - newMigrationData?.legacy_cms?.uploadedFile?.isValidated - ) { - setInternalActiveStepIndex(3); - } - }, [newMigrationData]); + if(!isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.cms_id) && !isEmptyString(newMigrationData?.legacy_cms?.affix) && newMigrationData?.legacy_cms?.uploadedFile?.isValidated){ + setInternalActiveStepIndex(3); + } + setisProjectMapped(newMigrationData?.isprojectMapped) - useEffect(() => { - if ( - !isEmptyString(newMigrationData?.legacy_cms?.affix) && - !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.title) && - !isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.title) && - newMigrationData?.legacy_cms?.uploadedFile?.isValidated - ) { - setIsAllStepsCompleted(true); - handleAllStepsComplete(true); - } else { - setIsAllStepsCompleted(false); - handleAllStepsComplete(false); - } - }, [newMigrationData, isAllStepsCompleted]); + },[newMigrationData]); + + useEffect(()=>{ + if(! isEmptyString(newMigrationData?.legacy_cms?.affix) + && !isEmptyString(newMigrationData?.legacy_cms?.selectedFileFormat?.title) && + ! isEmptyString(newMigrationData?.legacy_cms?.selectedCms?.title) && + newMigrationData?.legacy_cms?.uploadedFile?.isValidated){ + setIsAllStepsCompleted(true); + handleAllStepsComplete(true); + } + else{ + setIsAllStepsCompleted(false); + handleAllStepsComplete(false); - return ( - <> - {isLoading || newMigrationData?.isprojectMapped ? ( -
- -
- ) : ( -
-
-
- -
+ } + },[newMigrationData,isAllStepsCompleted]) + + return ( + <> + {isLoading || isProjectMapped ? ( +
+ +
+ ) : ( +
+
+
+
- )} - - ); - } -); +
+ )} + + ); +}); LegacyCMSComponent.displayName = 'LegacyCMSComponent'; export default LegacyCMSComponent; \ No newline at end of file diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index 6feed1a7b..d8b804b6a 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -67,6 +67,7 @@ export interface IFile { file_details?: FileDetails; isValidated: boolean; reValidate: boolean; + cmsType: string } export interface ICMSType extends ICardType { @@ -307,7 +308,8 @@ export const DEFAULT_FILE: IFile = { } }, isValidated: false, - reValidate: false + reValidate: false, + cmsType: '', }; export const DEFAULT_CMS_TYPE: ICMSType = { diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index c49bd7b6a..5971629e7 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -61,6 +61,7 @@ import MigrationExecution from '../../components/MigrationExecution'; import SaveChangesModal from '../../components/Common/SaveChangesModal'; import { getMigratedStacks } from '../../services/api/project.service'; import { getStackLocales } from '../../services/api/stacks.service'; +import { getConfig } from '../../services/api/upload.service'; type StepperComponentRef = { handleStepChange: (step: number) => void; @@ -184,20 +185,71 @@ const Migration = () => { setCurrentStepIndex(stepIndex !== -1 ? stepIndex : 0); }; + const getFileExtension = (filePath: string): string => { + const normalizedPath = filePath?.replace(/\\/g, "/")?.replace(/\/$/, ""); + + // Use regex to extract the file extension + const match = normalizedPath?.match(/\.([a-zA-Z0-9]+)$/); + const ext = match ? match[1]?.toLowerCase() : ""; + + const fileName = filePath?.split('/')?.pop(); + //const ext = fileName?.split('.')?.pop(); + const validExtensionRegex = /\.(pdf|zip|xml|json)$/i; + return ext && validExtensionRegex?.test(`.${ext}`) ? `${ext}` : ''; + }; + + // funcrion to form file format object from config response + const fetchFileFormat = (data:any) => { + const filePath = data?.localPath?.toLowerCase(); + const fileFormat = getFileExtension(filePath); + const selectedFileFormatObj = { + description: "", + fileformat_id: fileFormat, + group_name: fileFormat, + isactive: true, + title: fileFormat === 'zip' ? fileFormat?.charAt(0)?.toUpperCase() + fileFormat?.slice(1) : fileFormat?.toUpperCase() + } + return selectedFileFormatObj; + } + +// funcrion to form upload object from config response + const getFileInfo = (data:any) => { + const newMigrationDataObj = { + name: data?.localPath, + url: data?.localPath, + isValidated: data?.localePath !== newMigrationData?.legacy_cms?.uploadedFile?.file_details?.localPath ? false : newMigrationData?.legacy_cms?.uploadedFile?.isValidated, + file_details: { + isLocalPath: data?.isLocalPath, + cmsType: data?.cmsType, + localPath: data?.localPath, + awsData: { + awsRegion: data?.awsData?.awsRegion, + bucketName: data?.awsData?.bucketName, + buketKey: data?.awsData?.buketKey + } + }, + cmsType: data?.cmsType + }; + return newMigrationDataObj; + } + /** * Fetch the project data */ const fetchProjectData = async () => { if (isEmptyString(selectedOrganisation?.value) || isEmptyString(params?.projectId)) return; setIsProjectMapper(true); - const data = await getMigrationData(selectedOrganisation?.value, params?.projectId ?? ''); + const migrationData = await getMigrationData(selectedOrganisation?.value, params?.projectId ?? ''); const migratedstacks = await getMigratedStacks(selectedOrganisation?.value, projectId ); - - if (data) { + const {data} = await getConfig(); + const fileFormat = fetchFileFormat(data); + const uploadObj = getFileInfo(data); + + if (migrationData) { setIsLoading(false); - setProjectData(data?.data); + setProjectData(migrationData?.data); } - const projectData = data?.data; + const projectData = migrationData?.data; const legacyCmsData: ILegacyCMSComponent = await getCMSDataFromFile(CS_ENTRIES.LEGACY_CMS); @@ -213,7 +265,7 @@ const Migration = () => { ? selectedCmsData.allowed_file_formats?.find( (cms: ICardType) => cms?.fileformat_id === projectData?.legacy_cms?.file_format ) - : newMigrationData?.legacy_cms?.selectedFileFormat; + : fileFormat; const selectedOrganisationData = validateArray(organisationsList) ? organisationsList?.find((org: IDropDown) => org?.value === projectData?.org_id) @@ -253,11 +305,12 @@ const Migration = () => { const projectMapper = { ...newMigrationData, legacy_cms: { - ...newMigrationDataRef?.current?.legacy_cms, + ...newMigrationData?.legacy_cms, selectedCms: selectedCmsData, + selectedFileFormat: selectedFileFormatData, affix: projectData?.legacy_cms?.affix , - uploadedFile: { - ...newMigrationDataRef?.current?.legacy_cms, + uploadedFile: projectData?.legacy_cms?.is_fileValid ? { + ...newMigrationDataRef?.current?.legacy_cms?.uploadedFile, file_details: { localPath: projectData?.legacy_cms?.file_path, awsData: { @@ -269,7 +322,7 @@ const Migration = () => { }, isValidated: projectData?.legacy_cms?.is_fileValid, reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate - }, + } : uploadObj, isFileFormatCheckboxChecked: true, isRestictedKeywordCheckboxChecked: true, projectStatus: projectData?.status, diff --git a/upload-api/migration-sitecore/package.json b/upload-api/migration-sitecore/package.json index a50f05c7e..c7d65d32d 100644 --- a/upload-api/migration-sitecore/package.json +++ b/upload-api/migration-sitecore/package.json @@ -40,4 +40,4 @@ "winston": "^3.7.2", "xml2js": "^0.4.23" } -} +} \ No newline at end of file