Skip to content

Commit 3036d08

Browse files
committed
[CMG-584] - Destination stack | language mapper | The second row of the Contentstack language dropdown displays the master locale, which was already selected in the first row.
2 parents d283063 + 6b907bb commit 3036d08

File tree

8 files changed

+103
-71
lines changed

8 files changed

+103
-71
lines changed

api/src/services/contentful.service.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function makeChunks(assetData: any) {
8484
return chunks;
8585
}
8686

87-
const mapLocales = ({ masterLocale, locale, locales }: any) => {
87+
const mapLocales = ({ masterLocale, locale, locales, isNull = false }: any) => {
8888
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
8989
return Object?.keys(locales?.masterLocale)?.[0]
9090
}
@@ -93,7 +93,11 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
9393
return key;
9494
}
9595
}
96-
return locale.toLowerCase();
96+
if (isNull !== true) {
97+
return locale?.toLowerCase?.();
98+
} else {
99+
return null;
100+
}
97101
}
98102

99103
const transformCloudinaryObject = (input: any) => {
@@ -842,7 +846,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
842846
for await (const [localeKey, localeValues] of Object.entries(
843847
values as { [key: string]: any }
844848
)) {
845-
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper });
849+
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper, isNull: true });
846850
const chunks = makeChunks(localeValues);
847851
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
848852
const message = getLogMessage(
@@ -854,15 +858,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
854858
}
855859
const refs: { [key: string]: any } = {};
856860
let chunkIndex = 1;
857-
const filePath = path.join(
858-
entriesSave,
859-
ctName, localeCode
860-
);
861-
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
862-
refs[chunkIndex++] = `${chunkId}-entries.json`;
863-
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
861+
if (localeCode) {
862+
const filePath = path.join(
863+
entriesSave,
864+
ctName,
865+
localeCode
866+
);
867+
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
868+
refs[chunkIndex++] = `${chunkId}-entries.json`;
869+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
870+
}
871+
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
864872
}
865-
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
866873
}
867874
}
868875
} else {
@@ -957,7 +964,8 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
957964
)
958965
await customLogger(projectId, destination_stack_id, 'info', message);
959966
} else {
960-
if (project?.locales?.[localeData?.code]) {
967+
const newValueLocale = getKeyByValue(project?.locales, localeData?.code);
968+
if (newValueLocale) {
961969
allLocales[title] = newLocale;
962970
const message = getLogMessage(
963971
srcFunc,

api/src/services/migration.service.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@ const startTestMigration = async (req: Request): Promise<any> => {
254254
break;
255255
}
256256
case CMS.CONTENTFUL: {
257-
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId, project);
258-
await contentfulService?.createRefrence(file_path, project?.current_test_stack_id, projectId);
259-
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
260-
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
261-
await contentfulService?.createAssets(file_path, project?.current_test_stack_id, projectId, true);
262-
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
257+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
258+
await contentfulService?.createLocale(cleanLocalPath, project?.current_test_stack_id, projectId, project);
259+
await contentfulService?.createRefrence(cleanLocalPath, project?.current_test_stack_id, projectId);
260+
await contentfulService?.createWebhooks(cleanLocalPath, project?.current_test_stack_id, projectId);
261+
await contentfulService?.createEnvironment(cleanLocalPath, project?.current_test_stack_id, projectId);
262+
await contentfulService?.createAssets(cleanLocalPath, project?.current_test_stack_id, projectId, true);
263+
await contentfulService?.createEntry(cleanLocalPath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
263264
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
264265
break;
265266
}
@@ -330,12 +331,13 @@ const startMigration = async (req: Request): Promise<any> => {
330331
break;
331332
}
332333
case CMS.CONTENTFUL: {
333-
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId, project);
334-
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);
335-
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
336-
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
337-
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
338-
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
334+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
335+
await contentfulService?.createLocale(cleanLocalPath, project?.destination_stack_id, projectId, project);
336+
await contentfulService?.createRefrence(cleanLocalPath, project?.destination_stack_id, projectId);
337+
await contentfulService?.createWebhooks(cleanLocalPath, project?.destination_stack_id, projectId);
338+
await contentfulService?.createEnvironment(cleanLocalPath, project?.destination_stack_id, projectId);
339+
await contentfulService?.createAssets(cleanLocalPath, project?.destination_stack_id, projectId);
340+
await contentfulService?.createEntry(cleanLocalPath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
339341
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
340342
break;
341343
}
@@ -419,7 +421,6 @@ export const createSourceLocales = async (req: Request) => {
419421

420422
const projectId = req?.params?.projectId;
421423
const locales = req?.body?.locale;
422-
console.info("🚀 ~ createSourceLocales ~ locales:", locales);
423424

424425
try {
425426
// Find the project with the specified projectId

api/src/services/projects.service.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const createProject = async (req: Request) => {
135135
//Add logic to create Project from DB
136136
await ProjectModelLowdb.read();
137137

138-
ProjectModelLowdb.update((data: any) => {
138+
await ProjectModelLowdb.update((data: any) => {
139139
data.projects.push(projectData);
140140
});
141141

@@ -204,7 +204,7 @@ const updateProject = async (req: Request) => {
204204

205205
try {
206206
// Update the project fields
207-
ProjectModelLowdb.update((data: any) => {
207+
await ProjectModelLowdb.update((data: any) => {
208208
data.projects[projectIndex].name = updateData?.name;
209209
data.projects[projectIndex].description = updateData?.description;
210210
if (
@@ -308,7 +308,7 @@ const updateLegacyCMS = async (req: Request) => {
308308
// }
309309

310310
try {
311-
ProjectModelLowdb.update((data: any) => {
311+
await ProjectModelLowdb.update((data: any) => {
312312
data.projects[projectIndex].legacy_cms.cms = legacy_cms;
313313
data.projects[projectIndex].current_step = STEPPER_STEPS.LEGACY_CMS;
314314
data.projects[projectIndex].status = NEW_PROJECT_STATUS[0];
@@ -368,7 +368,7 @@ const updateAffix = async (req: Request) => {
368368
true
369369
)) as number;
370370

371-
ProjectModelLowdb.update((data: any) => {
371+
await ProjectModelLowdb.update((data: any) => {
372372
data.projects[projectIndex].legacy_cms.affix = affix;
373373
data.projects[projectIndex].updated_at = new Date().toISOString();
374374
});
@@ -405,7 +405,7 @@ const affixConfirmation = async (req: Request) => {
405405
true
406406
)) as number;
407407

408-
ProjectModelLowdb.update((data: any) => {
408+
await ProjectModelLowdb.update((data: any) => {
409409
data.projects[projectIndex].legacy_cms.affix_confirmation =
410410
affix_confirmation;
411411
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -477,7 +477,7 @@ const updateFileFormat = async (req: Request) => {
477477
// }
478478

479479
try {
480-
ProjectModelLowdb.update((data: any) => {
480+
await ProjectModelLowdb.update((data: any) => {
481481
data.projects[projectIndex].legacy_cms.file_format = file_format;
482482
data.projects[projectIndex].legacy_cms.file_path = file_path;
483483
data.projects[projectIndex].legacy_cms.is_fileValid = is_fileValid;
@@ -546,7 +546,7 @@ const fileformatConfirmation = async (req: Request) => {
546546
)) as number;
547547

548548
if (!fileformat_confirmation) {
549-
ProjectModelLowdb.update((data: any) => {
549+
await ProjectModelLowdb.update((data: any) => {
550550
data.projects[projectIndex].legacy_cms.file_format_confirmation =
551551
fileformat_confirmation;
552552
data.projects[projectIndex].updated_at = new Date().toISOString();
@@ -643,7 +643,7 @@ const updateDestinationStack = async (req: Request) => {
643643
if (!res.data.stacks.find((stack: any) => stack.api_key === stack_api_key))
644644
throw new BadRequestError(HTTP_TEXTS.DESTINATION_STACK_NOT_FOUND);
645645

646-
ProjectModelLowdb.update((data: any) => {
646+
await ProjectModelLowdb.update((data: any) => {
647647
data.projects[projectIndex].destination_stack_id = stack_api_key;
648648
data.projects[projectIndex].current_step =
649649
STEPPER_STEPS.DESTINATION_STACK;
@@ -713,11 +713,6 @@ const updateCurrentStep = async (req: Request) => {
713713
const isStepCompleted =
714714
project?.legacy_cms?.cms && project?.legacy_cms?.file_format;
715715

716-
console.info((project.status === NEW_PROJECT_STATUS[0] ||
717-
!isStepCompleted ||
718-
!project?.destination_stack_id ||
719-
project?.content_mapper?.length === 0 ||
720-
!project?.current_test_stack_id) || !project?.migration_execution);
721716

722717
switch (project.current_step) {
723718
case STEPPER_STEPS.LEGACY_CMS: {
@@ -732,7 +727,7 @@ const updateCurrentStep = async (req: Request) => {
732727
throw new BadRequestError(HTTP_TEXTS.CANNOT_PROCEED_LEGACY_CMS);
733728
}
734729

735-
ProjectModelLowdb.update((data: any) => {
730+
await ProjectModelLowdb.update((data: any) => {
736731
data.projects[projectIndex].current_step =
737732
STEPPER_STEPS.DESTINATION_STACK;
738733
data.projects[projectIndex].status =
@@ -760,7 +755,7 @@ const updateCurrentStep = async (req: Request) => {
760755
);
761756
}
762757

763-
ProjectModelLowdb.update((data: any) => {
758+
await ProjectModelLowdb.update((data: any) => {
764759
data.projects[projectIndex].current_step =
765760
STEPPER_STEPS.CONTENT_MAPPING;
766761
data.projects[projectIndex].status = NEW_PROJECT_STATUS[3];
@@ -789,7 +784,7 @@ const updateCurrentStep = async (req: Request) => {
789784
);
790785
}
791786

792-
ProjectModelLowdb.update((data: any) => {
787+
await ProjectModelLowdb.update((data: any) => {
793788
data.projects[projectIndex].current_step =
794789
STEPPER_STEPS.TESTING;
795790
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -818,7 +813,7 @@ const updateCurrentStep = async (req: Request) => {
818813
);
819814
}
820815

821-
ProjectModelLowdb.update((data: any) => {
816+
await ProjectModelLowdb.update((data: any) => {
822817
data.projects[projectIndex].current_step =
823818
STEPPER_STEPS.MIGRATION;
824819
data.projects[projectIndex].status = NEW_PROJECT_STATUS[4];
@@ -847,7 +842,7 @@ const updateCurrentStep = async (req: Request) => {
847842
);
848843
}
849844

850-
ProjectModelLowdb.update((data: any) => {
845+
await ProjectModelLowdb.update((data: any) => {
851846
data.projects[projectIndex].current_step =
852847
STEPPER_STEPS.MIGRATION;
853848
data.projects[projectIndex].status = NEW_PROJECT_STATUS[5];
@@ -913,7 +908,7 @@ const deleteProject = async (req: Request) => {
913908
await ContentTypesMapperModelLowdb.read();
914909
await FieldMapperModel.read();
915910
if (!isEmpty(content_mapper_id)) {
916-
content_mapper_id.map((item: any) => {
911+
content_mapper_id.map(async (item: any) => {
917912
const contentMapperData = ContentTypesMapperModelLowdb.chain
918913
.get("ContentTypesMappers")
919914
.find({ id: item, projectId: projectId })
@@ -940,17 +935,17 @@ const deleteProject = async (req: Request) => {
940935
.get("ContentTypesMappers")
941936
.findIndex({ id: item, projectId: projectId })
942937
.value();
943-
ContentTypesMapperModelLowdb.update((Cdata: any) => {
938+
await ContentTypesMapperModelLowdb.update((Cdata: any) => {
944939
delete Cdata.ContentTypesMappers[contentMapperID];
945940
});
946941
});
947942
}
948943
//delete Project
949-
ProjectModelLowdb.update((Pdata: any) => {
944+
await ProjectModelLowdb.update((Pdata: any) => {
950945
delete Pdata.projects[projectIndex];
951946
});
952947
} else {
953-
ProjectModelLowdb.update((data: any) => {
948+
await ProjectModelLowdb.update((data: any) => {
954949
data.projects[projectIndex].isDeleted = true;
955950
});
956951
}
@@ -1000,7 +995,7 @@ const revertProject = async (req: Request) => {
1000995
if (!projects) {
1001996
throw new NotFoundError(HTTP_TEXTS.PROJECT_NOT_FOUND);
1002997
} else {
1003-
ProjectModelLowdb.update((data: any) => {
998+
await ProjectModelLowdb.update((data: any) => {
1004999
data.projects[projectIndex].isDeleted = false;
10051000
});
10061001
logger.info(
@@ -1047,7 +1042,7 @@ const updateStackDetails = async (req: Request) => {
10471042
)) as number;
10481043

10491044
try {
1050-
ProjectModelLowdb.update((data: any) => {
1045+
await ProjectModelLowdb.update((data: any) => {
10511046
data.projects[projectIndex].stackDetails = stack_details;
10521047
data.projects[projectIndex].updated_at = new Date().toISOString();
10531048
});
@@ -1109,7 +1104,7 @@ const updateContentMapper = async (req: Request) => {
11091104
)) as number;
11101105

11111106
try {
1112-
ProjectModelLowdb.update((data: any) => {
1107+
await ProjectModelLowdb.update((data: any) => {
11131108
data.projects[projectIndex].mapperKeys = content_mapper;
11141109
data.projects[projectIndex].updated_at = new Date().toISOString();
11151110
});
@@ -1170,7 +1165,7 @@ const updateMigrationExecution = async (req: Request) => {
11701165
try {
11711166

11721167
// Update the project in the `ProjectModelLowdb` database
1173-
ProjectModelLowdb.update((data: any) => {
1168+
await ProjectModelLowdb.update((data: any) => {
11741169
data.projects[projectIndex].migration_execution = true; // Set migration execution to true
11751170
data.projects[projectIndex].updated_at = new Date().toISOString(); // Update the `updated_at` timestamp
11761171
});

ui/src/components/ContentMapper/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,12 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
612612
useBlockNavigation(isModalOpen);
613613
// Method to fetch content types
614614
const fetchContentTypes = async (searchText: string) => {
615+
setIsLoading(true);
616+
615617
try {
616-
setIsLoading(true);
617618
const { data } = await getContentTypes(projectId || '', 0, 5000, searchContentType || ''); //org id will always present
618619

620+
setIsLoading(false);
619621
setContentTypes(data?.contentTypes);
620622
setCount(data?.contentTypes?.length);
621623
setFilteredContentTypes(data?.contentTypes);
@@ -670,8 +672,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
670672

671673
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
672674

673-
setTableData(validTableData || []);
674-
setSelectedEntries(validTableData);
675+
setTableData(validTableData ?? []);
676+
setSelectedEntries(validTableData ?? []);
675677
setTotalCounts(validTableData?.length);
676678
setInitialRowSelectedData(validTableData?.filter((item: FieldMapType) => !item?.isDeleted))
677679
setIsLoading(false);
@@ -825,7 +827,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
825827
}, [tableData]);
826828

827829
const getParentId = (uid: string) => {
828-
return tableData?.find(i => i?.uid === uid)?.id ?? ''
830+
return tableData?.find(i => i?.uid?.toLowerCase() === uid?.toLowerCase())?.id ?? ''
829831
}
830832

831833
const modifiedObj = (obj: FieldMapType) => {
@@ -940,8 +942,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
940942
} else if(latestRow?.parentId && !["title", "url"]?.includes?.(latestRow?.uid?.toLowerCase())){
941943
// Extract the group UID if item is child of any group
942944
const uidBeforeDot = latestRow?.uid?.split?.('.')?.[0]?.toLowerCase();
943-
const groupItem = tableData?.find((entry) => entry?.uid === uidBeforeDot);
944-
const childItems = tableData?.filter((entry) => entry?.uid?.toLowerCase()?.startsWith(groupItem?.uid + '.'));
945+
const groupItem = tableData?.find((entry) => entry?.uid?.toLowerCase() === uidBeforeDot);
946+
const childItems = tableData?.filter((entry) => entry?.uid?.toLowerCase()?.startsWith(groupItem?.uid?.toLowerCase() + '.'));
945947

946948
if(latestRow?.checked) {
947949
if(!selectedObj[latestRow?.parentId]){
@@ -1072,6 +1074,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
10721074
maxWidth="290px"
10731075
isClearable={false}
10741076
options={option}
1077+
menuPlacement="auto"
10751078
isDisabled={
10761079
data?.otherCmsType === "Group" ||
10771080
data?.otherCmsField === 'title' ||
@@ -1577,6 +1580,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
15771580
isClearable={selectedOptions?.includes?.(existingField?.[data?.uid]?.label ?? '')}
15781581
options={adjustedOptions}
15791582
isDisabled={OptionValue?.isDisabled || newMigrationData?.project_current_step > 4}
1583+
menuPlacement="auto"
15801584
/>
15811585
</div>
15821586
{(!OptionValue?.isDisabled || OptionValue?.label === 'Dropdown'||

0 commit comments

Comments
 (0)