From 93b605adb59d0eba081859127e10089190212fe3 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 21 Apr 2025 10:06:06 +0530 Subject: [PATCH 1/2] fix:removed watcher from upload and added status update of project after migration and language mapper bug --- api/src/services/runCli.service.ts | 12 +- package.json | 2 +- .../Actions/LoadLanguageMapper.tsx | 124 +++++++++++------- .../DestinationStack/Actions/LoadStacks.tsx | 3 +- upload-api/package.json | 1 - 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/api/src/services/runCli.service.ts b/api/src/services/runCli.service.ts index 9d7e7699f..f457db1a7 100644 --- a/api/src/services/runCli.service.ts +++ b/api/src/services/runCli.service.ts @@ -354,17 +354,17 @@ export const runCli = async ( } }); - ProjectModelLowdb.write(); + await ProjectModelLowdb.write(); } // Update project status for non-test migrations if (projectIndex > -1 && !isTest) { // Direct modification might be more reliable - ProjectModelLowdb.data.projects[projectIndex].isMigrationCompleted = - true; - ProjectModelLowdb.data.projects[projectIndex].isMigrationStarted = - false; - ProjectModelLowdb.write(); + ProjectModelLowdb.data.projects[projectIndex].isMigrationCompleted = true; + ProjectModelLowdb.data.projects[projectIndex].isMigrationStarted = false; + ProjectModelLowdb.data.projects[projectIndex].current_step = 5; + ProjectModelLowdb.data.projects[projectIndex].status = 5; + await ProjectModelLowdb.write(); console.info( `Project ${projectId} status updated: migration completed` ); diff --git a/package.json b/package.json index 82a4e2939..10a099031 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "postinstall": "(cd ./api && npm install) ; (cd ./ui && npm install) ; (cd ./upload-api && npm install)", "env": "npm start", "api": "cd ./api && npm run dev", - "upload": "cd ./upload-api && npm run dev", + "upload": "cd ./upload-api && npm run start", "ui": "cd ./ui && npm start", "setup:file": "npm i && node fileUpdate.js", "create:env": "node index.js", diff --git a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx index e37a8bb0b..3ee621844 100644 --- a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx @@ -13,7 +13,7 @@ import TableHeader from './tableHeader'; import { useDispatch, useSelector } from 'react-redux'; import { RootState } from '../../../store'; import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice'; -import { INewMigration } from '../../../context/app/app.interface'; +import { IDropDown, INewMigration } from '../../../context/app/app.interface'; export type ExistingFieldType = { [key: string]: { label: string; value: string }; @@ -33,13 +33,15 @@ const Mapper = ({ handleLangugeDelete, options, sourceOptions, - isDisabled + isDisabled, + localeChanged, }: { cmsLocaleOptions: Array<{ label: string; value: string }>; handleLangugeDelete: (index: number, locale: { label: string; value: string }) => void; options: Array<{ label: string; value: string }>; sourceOptions: Array<{ label: string; value: string }>; isDisabled: boolean; + localeChanged: boolean }) => { const [selectedMappings, setSelectedMappings] = useState<{ [key: string]: string }>({}); const [existingField, setExistingField] = useState({}); @@ -92,46 +94,59 @@ const Mapper = ({ }, [selectedCsOptions, selectedSourceOption, options]); useEffect(() => { - setExistingField((prevExisting: ExistingFieldType) => { - const updatedExisting = { ...prevExisting }; - const validLabels = cmsLocaleOptions?.map(locale => locale?.label) || []; - Object?.entries(updatedExisting)?.forEach(([index, entry]) => { - const [labelPart] = entry.label.split('-'); - if (!validLabels?.includes(labelPart)) { - delete updatedExisting?.[index]; - } - }); + const updatedExistingField = {...existingField}; + const updatedExistingLocale = {...existingLocale}; + let updatedSelectedMappings = { ...selectedMappings }; + + const validLabels = cmsLocaleOptions?.map((item)=> item?.label); + + const existingMasterKey = Object?.keys(selectedMappings || {})?.find((key) => + key?.includes('-master_locale') + ); + + const recentMsterLocale = cmsLocaleOptions?.find((item)=>{item?.value === 'master_locale'}) + + Object.keys(updatedExistingField || {})?.forEach((key) => { + if (!validLabels?.includes(updatedExistingField?.[key]?.label) || existingMasterKey !== `${recentMsterLocale}-master_locale`) { + delete updatedExistingField?.[key]; + } + }); + + Object.keys(updatedExistingLocale || {})?.forEach((key) => { - setSelectedMappings((prev) => { - const updated = { ...prev }; - - Object?.keys(updated)?.forEach((key) => { - const [labelPart] = key?.split('-') ?? []; - if (!validLabels?.includes(labelPart)) { - delete updated?.[key]; - } - }); - - return updated; - }); + if ((!validLabels?.includes(updatedExistingLocale?.[key]?.label) && Object?.entries(updatedExistingField)?.length === 0) || existingMasterKey !== `${recentMsterLocale}-master_locale`) { + delete updatedExistingLocale?.[key]; + } + }); - cmsLocaleOptions?.forEach((locale: { label: string; value: string }, index: number) => { - if (locale?.value === 'master_locale' && !updatedExisting?.[index]) { - setSelectedMappings((prev) => ({ - - ...prev, - [`${locale?.label}-master_locale`]: '' - })); - updatedExisting[index] = { - label: locale?.label, - value: `${locale?.label}-master_locale` + cmsLocaleOptions?.map((locale, index)=>{ + if(locale?.value === 'master_locale'){ + if (!updatedExistingField?.[index]) { + updatedExistingField[index] = { + label: `${locale?.label}`, + value: `${locale?.label}-master_locale`, }; } - }); - return updatedExisting; - }); - }, [cmsLocaleOptions]); + + if ( existingMasterKey !== `${locale?.label}-master_locale`) { + setselectedCsOption([]); + setselectedSourceOption([]); + updatedSelectedMappings = { + [`${locale?.label}-master_locale`]: '', + }; + + } + } + }) + + setExistingField(updatedExistingField); + setexistingLocale(updatedExistingLocale); + setSelectedMappings(updatedSelectedMappings); + + + }, [cmsLocaleOptions]); + // function for change select value const handleSelectedCsLocale = ( @@ -284,12 +299,14 @@ const Mapper = ({ handleLangugeDelete(index, locale); }; - + //console.info("cms Locale option ----> ", cmsLocaleOptions, existingLocale) return ( <> - {cmsLocaleOptions?.length > 0 ? ( - cmsLocaleOptions?.map((locale: any, index: number) => ( -
+ {cmsLocaleOptions?.length > 0 ? ( + cmsLocaleOptions?.map((locale: {label:string, value: string}, index: number) => ( + +
+ {locale?.value === 'master_locale' ? (
{ handleSelectedCsLocale(key, index, 'csLocale'); }} @@ -364,7 +381,7 @@ const Mapper = ({ value={ locale?.value && locale?.value !== 'master_locale' ? { label: locale?.value, value: locale?.value } - : existingLocale[locale] + : existingLocale[locale?.label] } onChange={(data: { label: string; value: string }) => handleSelectedSourceLocale(data, index, 'sourceLocale', locale) @@ -421,12 +438,15 @@ const Mapper = ({ ); }; -const LanguageMapper = () => { +const LanguageMapper = ({stack} :{ stack : IDropDown}) => { + const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); + //console.info("again render ", newMigrationData?.destination_stack?.selectedStack?.master_locale) const [options, setoptions] = useState<{ label: string; value: string }[]>([]); const [cmsLocaleOptions, setcmsLocaleOptions] = useState<{ label: string; value: string }[]>([]); const [sourceLocales, setsourceLocales] = useState<{ label: string; value: string }[]>([]); const [isLoading, setisLoading] = useState(false); + const [localeChanged, setlocaleChanged] = useState(false); useEffect(() => { const fetchData = async () => { @@ -446,18 +466,18 @@ const LanguageMapper = () => { setoptions(allLocales); const keys = Object?.keys(newMigrationData?.destination_stack?.localeMapping || {})?.find( key => key === `${newMigrationData?.destination_stack?.selectedStack?.master_locale}-master_locale`); - (Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 || keys !== `${newMigrationData?.destination_stack?.selectedStack?.master_locale}-master_locale` ) && + (Object?.entries(newMigrationData?.destination_stack?.localeMapping)?.length === 0 || !keys ) && newMigrationData?.project_current_step <= 2 && setcmsLocaleOptions((prevList: { label: string; value: string }[]) => { - const newLabel = newMigrationData?.destination_stack?.selectedStack?.master_locale; + const newLabel = stack?.master_locale; const isPresent = prevList?.filter( (item: { label: string; value: string }) => (item?.value === 'master_locale') ); - if(isPresent?.[0]?.label !== newLabel){ + setlocaleChanged(true); return [ - ...prevList?.filter(item => item?.value !== 'master_locale') ?? [], + ...prevList?.filter(item => (item?.value !== 'master_locale' && item?.value !== '')) ?? [], { label: newLabel, value: 'master_locale', @@ -507,16 +527,17 @@ const LanguageMapper = () => { }; fetchData(); - }, [newMigrationData?.destination_stack]); + }, [newMigrationData?.destination_stack?.selectedStack]); // const fetchLocales = async () => { // return await getStackLocales(newMigrationData?.destination_stack?.selectedOrg?.value); // }; const addRowComp = () => { + setlocaleChanged(false); setcmsLocaleOptions((prevList: { label: string; value: string }[]) => [ ...prevList, // Keep existing elements { - label: `${prevList.length + 1}`, // Generate new label + label: `${prevList.length}`, // Generate new label value: '' } ]); @@ -543,6 +564,7 @@ const LanguageMapper = () => { } rowComponent={ { >
- +
)}
diff --git a/upload-api/package.json b/upload-api/package.json index 9ba020418..2b6ef1f63 100644 --- a/upload-api/package.json +++ b/upload-api/package.json @@ -6,7 +6,6 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "tsc && node build/index.js", - "dev": "tsc --watch & node --watch build/index.js", "validation": "tsc && node build/main.js", "prettify": "prettier --write .", "lint": "eslint .", From 1ddb2fa7721b0d8e42a57665f9f7b7d116855339 Mon Sep 17 00:00:00 2001 From: AishDani Date: Mon, 21 Apr 2025 10:11:12 +0530 Subject: [PATCH 2/2] fix:removed console --- .../DestinationStack/Actions/LoadLanguageMapper.tsx | 2 -- ui/src/components/DestinationStack/Actions/LoadStacks.tsx | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx index 3ee621844..aee7bf568 100644 --- a/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx @@ -299,7 +299,6 @@ const Mapper = ({ handleLangugeDelete(index, locale); }; - //console.info("cms Locale option ----> ", cmsLocaleOptions, existingLocale) return ( <> {cmsLocaleOptions?.length > 0 ? ( @@ -441,7 +440,6 @@ const Mapper = ({ const LanguageMapper = ({stack} :{ stack : IDropDown}) => { const newMigrationData = useSelector((state: RootState) => state?.migration?.newMigrationData); - //console.info("again render ", newMigrationData?.destination_stack?.selectedStack?.master_locale) const [options, setoptions] = useState<{ label: string; value: string }[]>([]); const [cmsLocaleOptions, setcmsLocaleOptions] = useState<{ label: string; value: string }[]>([]); const [sourceLocales, setsourceLocales] = useState<{ label: string; value: string }[]>([]); diff --git a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx index 87d3b0803..1818c7a3b 100644 --- a/ui/src/components/DestinationStack/Actions/LoadStacks.tsx +++ b/ui/src/components/DestinationStack/Actions/LoadStacks.tsx @@ -15,7 +15,7 @@ import { RootState } from '../../../store'; import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice'; // Interface -import { IDropDown, INewMigration } from '../../../context/app/app.interface'; +import { DEFAULT_DROPDOWN, IDropDown, INewMigration } from '../../../context/app/app.interface'; import { StackResponse } from '../../../services/api/service.interface'; import { Stack } from '../../../components/Common/AddStack/addStack.interface'; @@ -373,7 +373,7 @@ const LoadStacks = (props: LoadFileFormatProps) => { + stack={selectedStack ?? DEFAULT_DROPDOWN} /> )}