Skip to content

Commit 995e1a8

Browse files
conflict resolve
2 parents db8f573 + d2eed4f commit 995e1a8

File tree

9 files changed

+132
-85
lines changed

9 files changed

+132
-85
lines changed

api/src/models/FieldMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface FieldMapper {
2828
field_mapper: {
2929
id: string;
3030
projectId: string;
31+
contentTypeId: string;
3132
uid: string;
3233
otherCmsField: string;
3334
otherCmsType: string;

api/src/services/contentMapper.service.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ const putTestData = async (req: Request) => {
3636
const contentTypes = req.body.contentTypes;
3737

3838
try {
39-
await FieldMapperModel.read();
39+
40+
/*
41+
this code snippet is iterating over an array called contentTypes and
42+
transforming each element by adding a unique identifier (id) if it doesn't already exist.
43+
The transformed elements are then stored in the contentType variable,
44+
and the generated id values are pushed into the contentIds array.
45+
*/
46+
await ContentTypesMapperModelLowdb.read();
47+
const contentIds: any[] = [];
48+
const contentType = contentTypes.map((item: any) => {
49+
const id = item?.id?.replace(/[{}]/g, "")?.toLowerCase() || uuidv4();
50+
item.id = id;
51+
contentIds.push(id);
52+
return { ...item, id, projectId };
53+
});
4054

4155
/*
4256
this code snippet iterates over an array of contentTypes and performs
@@ -47,36 +61,24 @@ const putTestData = async (req: Request) => {
4761
It then updates the field_mapper property of a data object using the FieldMapperModel.update() function.
4862
Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array.
4963
*/
64+
await FieldMapperModel.read();
65+
5066
contentTypes.map((type: any, index: any) => {
5167
const fieldIds: string[] = [];
5268
const fields = type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => {
5369
const id = field?.id ? field?.id?.replace(/[{}]/g, "")?.toLowerCase() : uuidv4();
5470
field.id = id;
5571
fieldIds.push(id);
56-
return { id, projectId, isDeleted: false, ...field };
72+
return { id, projectId, contentTypeId: type?.id, isDeleted: false, ...field };
5773
});
5874

5975
FieldMapperModel.update((data: any) => {
6076
data.field_mapper = [...(data?.field_mapper ?? []), ...(fields ?? [])];
6177
});
62-
contentTypes[index].fieldMapping = fieldIds;
78+
contentType[index].fieldMapping = fieldIds;
6379
});
6480

65-
await ContentTypesMapperModelLowdb.read();
66-
const contentIds: any[] = [];
6781

68-
/*
69-
this code snippet is iterating over an array called contentTypes and
70-
transforming each element by adding a unique identifier (id) if it doesn't already exist.
71-
The transformed elements are then stored in the contentType variable,
72-
and the generated id values are pushed into the contentIds array.
73-
*/
74-
const contentType = contentTypes.map((item: any) => {
75-
const id = item?.id?.replace(/[{}]/g, "")?.toLowerCase() || uuidv4();
76-
item.id = id;
77-
contentIds.push(id);
78-
return { ...item, id, projectId };
79-
});
8082

8183
await ContentTypesMapperModelLowdb.update((data: any) => {
8284
data.ContentTypesMappers = [
@@ -248,7 +250,7 @@ const getFieldMapping = async (req: Request) => {
248250
const fieldData = contentType?.fieldMapping?.map?.((fields: any) => {
249251
const fieldMapper = FieldMapperModel.chain
250252
.get("field_mapper")
251-
.find({ id: fields, projectId: projectId })
253+
.find({ id: fields, projectId: projectId, contentTypeId: contentTypeId })
252254
.value();
253255

254256
return fieldMapper;
@@ -616,7 +618,7 @@ const updateContentType = async (req: Request) => {
616618
await FieldMapperModel.read();
617619
fieldMapping.forEach((field: any) => {
618620
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
619-
(f: any) => f?.id === field?.id
621+
(f: any) => f?.id === field?.id && f?.contentTypeId === field?.contentTypeId
620622
);
621623
if (fieldIndex > -1 && field?.contentstackFieldType !== "") {
622624
FieldMapperModel.update((data: any) => {

api/src/services/wordpress.service.ts

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import axios from "axios";
55
//import _ from "lodash";
66
import { LOCALE_MAPPER, MIGRATION_DATA_CONFIG } from "../constants/index.js";
77
import jsdom from "jsdom";
8-
import { htmlToJson } from "@contentstack/json-rte-serializer";
8+
import { htmlToJson, jsonToHtml } from "@contentstack/json-rte-serializer";
99
import customLogger from "../utils/custom-logger.utils.js";
1010
import { getLogMessage } from "../utils/index.js";
1111
import { Advanced } from "../models/FieldMapper.js";
@@ -110,20 +110,28 @@ let assetData: Record<string, any> | any = {};
110110
let blog_base_url = "";
111111

112112
//helper function to convert entries with content type
113-
function mapContentTypeToEntry(contentType: any, data: any) {
114-
return contentType?.fieldMapping?.reduce((acc: { [key: string]: any }, field: FieldMapping) => {
113+
async function mapContentTypeToEntry(contentType: any, data: any) {
114+
const result: { [key: string]: any } = {};
115+
116+
for (const field of contentType?.fieldMapping || []) {
115117
const fieldValue = data?.[field?.uid];
116118
let formattedValue;
117119

118120
switch (field?.contentstackFieldType) {
119121
case "single_line_text":
120122
case "text":
121-
case 'html':
122123
formattedValue = fieldValue;
123124
break;
124-
case "json":
125-
formattedValue = convertHtmlToJson(fieldValue);
125+
case "html":
126+
formattedValue =
127+
fieldValue && typeof fieldValue === "object"
128+
? await convertJsonToHtml(fieldValue)
129+
: fieldValue;
126130
break;
131+
case "json":
132+
133+
formattedValue = await convertHtmlToJson(fieldValue);
134+
break;
127135
case "reference":
128136
formattedValue = getParent(data, data[field.uid]);
129137
break;
@@ -134,10 +142,12 @@ function mapContentTypeToEntry(contentType: any, data: any) {
134142
formattedValue = Array.isArray(formattedValue) ? formattedValue : [formattedValue];
135143
}
136144

137-
acc[field.contentstackFieldUid] = formattedValue;
138-
return acc;
139-
}, {});
145+
result[field?.contentstackFieldUid] = formattedValue;
146+
}
147+
148+
return result;
140149
}
150+
141151
// helper functions
142152
async function writeFileAsync(filePath: string, data: any, tabSpaces: number) {
143153
filePath = path.resolve(filePath);
@@ -679,7 +689,7 @@ async function getAllreference(affix: string, packagePath: string, destinationSt
679689
...processReferenceData(referenceTerms, "terms", "wp:term_slug", terms)
680690
);
681691
referenceArray.push(
682-
...processReferenceData(referenceTags, "tags", "wp:tag_slug", tag)
692+
...processReferenceData(referenceTags, "tag", "wp:tag_slug", tag)
683693
);
684694

685695
if (referenceArray.length > 0) {
@@ -887,7 +897,7 @@ async function saveAuthors(authorDetails: any[], destinationStackId: string, pro
887897
authordata[customId] = {
888898
...authordata[customId],
889899
uid: customId,
890-
...mapContentTypeToEntry(contentType, authordataEntry),
900+
...( await mapContentTypeToEntry(contentType, authordataEntry)),
891901
};
892902
authordata[customId].publish_details = [];
893903

@@ -1633,15 +1643,16 @@ async function saveTerms(
16331643
try {
16341644
const termsFilePath = path.join(termsFolderPath, `${master_locale}.json`);
16351645
const termsdata = termsDetails.reduce(
1636-
(acc: { [key: string]: any }, data) => {
1646+
async (acc: { [key: string]: any }, data) => {
1647+
16371648
const { id } = data;
16381649
const uid = `terms_${id}`;
16391650
const customId = uid;
16401651

16411652
acc[customId] = {
16421653
...acc[customId],
16431654
uid: customId,
1644-
...mapContentTypeToEntry(contentType, data),
1655+
...mapContentTypeToEntry(contentType, data), // Pass individual term object
16451656
};
16461657
acc[customId].publish_details = [];
16471658
return acc;
@@ -1813,17 +1824,19 @@ async function saveTags(
18131824
) {
18141825
const srcFunc = 'saveTags';
18151826
try {
1816-
const tagsFilePath = path.join(tagsFolderPath, `${master_locale}.json`);
1817-
1827+
const tagsFilePath = path.join(
1828+
tagsFolderPath,
1829+
`${master_locale}.json`
1830+
);
18181831
const tagdata = tagDetails.reduce((acc: { [key: string]: any }, data) => {
18191832
const { id } = data;
18201833
const uid = `tags_${id}`;
18211834
const customId = idCorrector(uid);
18221835

18231836
acc[customId] = {
18241837
...acc[customId],
1825-
uid: customId,
1826-
...mapContentTypeToEntry(contenttype, data),
1838+
uid:customId,
1839+
...mapContentTypeToEntry(contenttype,data),
18271840
};
18281841
acc[customId].publish_details = [];
18291842

@@ -1977,11 +1990,22 @@ async function startingDirCategories(
19771990
}
19781991

19791992
const convertHtmlToJson = (htmlString: any) => {
1980-
const dom = new JSDOM(htmlString?.replace(/&amp;/g, "&"));
1981-
const htmlDoc = dom.window.document.querySelector("body");
1982-
return htmlToJson(htmlDoc);
1993+
if(typeof htmlString === 'string'){
1994+
const dom = new JSDOM(htmlString?.replace(/&amp;/g, "&"));
1995+
const htmlDoc = dom.window.document.querySelector("body");
1996+
const jsonValue = htmlToJson(htmlDoc)
1997+
return jsonValue;
1998+
1999+
}
2000+
else return htmlString;
19832001
};
19842002

2003+
const convertJsonToHtml = async (json: any) => {
2004+
const htmlValue = await jsonToHtml(json);
2005+
return htmlValue;
2006+
2007+
}
2008+
19852009
function getParent(data: any, id: string) {
19862010
const parentId: any = fs.readFileSync(
19872011
path.join(referencesFolder, MIGRATION_DATA_CONFIG.REFERENCES_FILE_NAME),
@@ -2015,17 +2039,17 @@ async function saveCategories(
20152039
const srcFunc = 'saveCategories';
20162040
try {
20172041
const categorydata = categoryDetails.reduce(
2018-
(acc: { [key: string]: any }, data) => {
2042+
async (acc: { [key: string]: any }, data) => {
20192043
const uid = `category_${data["id"]}`;
20202044

20212045
const customId = uid;
20222046

20232047
// Accumulate category data
20242048
acc[customId] = {
20252049
...acc[customId],
2026-
uid: customId,
2027-
...mapContentTypeToEntry(contenttype, data),
2028-
};
2050+
uid:customId,
2051+
...mapContentTypeToEntry(contenttype,data),
2052+
}
20292053
acc[customId].publish_details = [];
20302054

20312055
return acc;
@@ -2378,23 +2402,23 @@ async function processChunkData(
23782402
postdata
23792403
);
23802404
const formattedPosts = Object?.entries(formatted_posts)?.reduce(
2381-
(acc: { [key: string]: any }, data: any) => {
2382-
2405+
(acc: { [key: string]: any }, data:any) => {
2406+
23832407
const customId = idCorrector(data["uid"])
2384-
2408+
23852409
// Accumulate category data
2386-
acc[customId] = {
2410+
acc[customId]={
23872411
...acc[customId],
23882412
uid: customId,
2389-
...mapContentTypeToEntry(contenttype, data),
2413+
...mapContentTypeToEntry(contenttype,data),
23902414
};
23912415
acc[customId].publish_details = [];
2392-
2416+
23932417
return acc;
23942418
},
23952419
{}
23962420
);
2397-
Object.assign(postdata, formattedPosts);
2421+
Object.assign(postdata,formattedPosts);
23982422

23992423
// await writeFileAsync(
24002424
// path.join(postFolderPath, filename),
@@ -2415,6 +2439,7 @@ async function processChunkData(
24152439
if (isLastChunk && allSuccess) {
24162440
console.info("last data");
24172441
}
2442+
console.info("postData ---> ", postdata)
24182443
return postdata
24192444
} catch (error) {
24202445
console.error(error);
@@ -2433,8 +2458,8 @@ async function extractPosts(
24332458
project: any
24342459
) {
24352460
const srcFunc = "extractPosts";
2436-
const ct: any = keyMapper?.["categories"];
2437-
const contenttype = contentTypes?.find((item: any) => item?.otherCmsUid === 'categories');
2461+
const ct:any = keyMapper?.["categories"];
2462+
const contenttype = contentTypes?.find((item:any)=> item?.otherCmsUid === 'categories');
24382463

24392464
try {
24402465
await startingDirPosts(ct, master_locale, project?.locales);

ui/src/components/AdvancePropertise/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ const AdvancePropertise = (props: SchemaProps) => {
576576
isMulti={true}
577577
onChange={(selectedOptions: ContentTypeOption[]) => {
578578
setCTValue(selectedOptions);
579-
const embedObject = selectedOptions.map((item: optionsType) => item.label); // Update the state with the selected options
579+
const embedObject = selectedOptions.map((item: optionsType) => item?.value); // Update the state with the selected options
580580
props?.updateFieldSettings(
581581
props?.rowId,
582582
{

ui/src/components/ContentMapper/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
671671
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
672672

673673
setTableData(validTableData || []);
674+
setSelectedEntries(validTableData);
674675
setTotalCounts(validTableData?.length);
675676
setInitialRowSelectedData(validTableData?.filter((item: FieldMapType) => !item?.isDeleted))
676677
setIsLoading(false);

ui/src/components/LegacyCms/Actions/LoadSelectCms.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
142142
}
143143
};
144144
//await updateLegacyCMSData(selectedOrganisation.value, projectId, { legacy_cms: newSelectedCard?.cms_id });
145-
//dispatch(updateNewMigrationData(newMigrationDataObj));
145+
dispatch(updateNewMigrationData(newMigrationDataObj));
146146
props?.handleStepChange(props?.currentStep);
147147
}
148148
} catch (error) {
@@ -155,25 +155,27 @@ const LoadSelectCms = (props: LoadSelectCmsProps) => {
155155
filterCMSData(searchText);
156156
}, []);
157157

158-
// Handle Legacy cms selection for single match
159-
useEffect(() => {
160-
const isSingleMatch = cmsData?.length === 1;
161-
if (isSingleMatch) {
162-
setSelectedCard({ ...selectedCard });
163158

164-
const newMigrationDataObj: INewMigration = {
165-
...newMigrationData,
166-
legacy_cms: {
167-
...newMigrationData.legacy_cms,
168-
selectedCms: { ...selectedCard }
169-
}
170-
};
171-
dispatch(updateNewMigrationData(newMigrationDataObj));
172-
173-
// Call for Step Change
174-
props?.handleStepChange(props?.currentStep);
175-
}
176-
}, [cmsData]);
159+
// Handle Legacy cms selection for single match
160+
// useEffect(() => {
161+
// const isSingleMatch = cmsData?.length === 1;
162+
// if (isSingleMatch) {
163+
// setSelectedCard({ ...selectedCard });
164+
165+
// const newMigrationDataObj: INewMigration = {
166+
// ...newMigrationData,
167+
// legacy_cms: {
168+
// ...newMigrationDataRef?.current?.legacy_cms,
169+
// selectedCms: { ...selectedCard }
170+
// }
171+
// };
172+
// console.info("neMigObj ---> ", newMigrationDataObj, cmsData)
173+
// dispatch(updateNewMigrationData(newMigrationDataObj));
174+
175+
// // Call for Step Change
176+
// props?.handleStepChange(props?.currentStep);
177+
// }
178+
// }, [cmsData]);
177179

178180
return (
179181
<div>

ui/src/components/MigrationExecution/index.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ div .step-component .action-component-body {
6969
border: 1px solid #dde3ee;
7070
border-radius: var(--TermCount, 5px);
7171
}
72+
.textInput-ellipse {
73+
text-overflow: ellipsis;
74+
overflow: hidden;
75+
white-space: nowrap;
76+
}

0 commit comments

Comments
 (0)