Skip to content

Commit b91adfd

Browse files
Merge pull request #673 from contentstack/bugfix/cmg-616
Bugfix/cmg 616
2 parents 8e5a006 + f24f448 commit b91adfd

File tree

17 files changed

+355
-171
lines changed

17 files changed

+355
-171
lines changed

.talismanrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ ignoreconfig:
1010
ignore_detectors:
1111
- Base64Detector
1212

13-
version: "1.0"
13+
- filename: ui/src/components/ContentMapper/index.tsx
14+
checksum: 6743142fce18f945d55fc61d7d774118db400b72ccc7a0b5e089ccc8aed20340
15+
version: "1.0.1-beta"

api/src/services/migration.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ const startMigration = async (req: Request): Promise<any> => {
666666
.findIndex({ id: projectId })
667667
.value();
668668
if (index > -1) {
669-
ProjectModelLowdb.update((data: any) => {
669+
await ProjectModelLowdb.update((data: any) => {
670670
data.projects[index].isMigrationStarted = true;
671671
});
672672
}
@@ -682,6 +682,18 @@ const startMigration = async (req: Request): Promise<any> => {
682682
projectId,
683683
`${project?.destination_stack_id}.log`
684684
);
685+
const message = getLogMessage(
686+
'start Migration',
687+
'Starting Migration...',
688+
{}
689+
);
690+
await customLogger(
691+
projectId,
692+
project?.destination_stack_id,
693+
'info',
694+
message
695+
);
696+
685697
await setLogFilePath(loggerPath);
686698

687699
const copyLogsToStack = async (

api/src/services/wordpress.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,17 @@ async function extractPosts( packagePath: string, destinationStackId: string, pr
23302330
// Process the current chunk
23312331
const chunkPostData = await processChunkData(chunkData, filename, isLastChunk, contenttype);
23322332
postdataCombined = { ...postdataCombined, ...chunkPostData };
2333+
2334+
const seenTitles = new Map();
2335+
Object?.entries?.(postdataCombined)?.forEach?.(([uid, item]:any) => {
2336+
const originalTitle = item?.title;
2337+
2338+
if (seenTitles?.has(originalTitle)) {
2339+
item.title = `${originalTitle} - ${item?.uid}`;
2340+
}
2341+
seenTitles?.set?.(item?.title, true);
2342+
});
2343+
23332344
const message = getLogMessage(
23342345
srcFunc,
23352346
`${filename.split(".").slice(0, -1).join(".")} has been successfully transformed.`,

api/src/utils/content-type-creator.utils.ts

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,19 @@ const arrangGroups = ({ schema, newStack }: any) => {
7474
schema?.forEach((item: any) => {
7575
if (item?.contentstackFieldType === 'group') {
7676
const groupSchema: any = { ...item, schema: [] }
77+
if (item?.contentstackFieldUid?.includes('.')) {
78+
const parts = item?.contentstackFieldUid?.split('.');
79+
groupSchema.contentstackFieldUid = parts?.[parts?.length - 1];
80+
}
7781
schema?.forEach((et: any) => {
7882
if (et?.contentstackFieldUid?.includes(`${item?.contentstackFieldUid}.`) ||
7983
(newStack === false && et?.uid?.includes(`${item?.uid}.`))) {
84+
const target = groupSchema?.contentstackFieldUid;
85+
const index = et?.contentstackFieldUid?.indexOf?.(target);
86+
87+
if (index > 0) {
88+
et.contentstackFieldUid = et?.contentstackFieldUid?.substring(index);
89+
}
8090
groupSchema?.schema?.push(et);
8191
}
8292
})
@@ -112,7 +122,7 @@ const saveAppMapper = async ({ marketPlacePath, data, fileName }: any) => {
112122
}
113123
}
114124

115-
const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any) => {
125+
const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath, keyMapper }: any) => {
116126
switch (field?.contentstackFieldType) {
117127
case 'single_line_text': {
118128
return {
@@ -435,7 +445,7 @@ const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any
435445
return {
436446
data_type: "reference",
437447
display_name: field?.title,
438-
reference_to: field?.refrenceTo ?? [],
448+
reference_to: field?.refrenceTo?.map((item:string) => keyMapper[item] || item) ?? [],
439449
field_metadata: {
440450
ref_multiple: true,
441451
ref_multiple_content_types: true
@@ -654,45 +664,98 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
654664
}
655665
}
656666

657-
const mergeArrays = async (a: any[], b: any[]) => {
658-
for await (const fieldGp of b) {
659-
const exists = a.some(fld =>
660-
fld?.uid === fieldGp?.uid &&
661-
fld?.data_type === fieldGp?.data_type
667+
const mergeArrays = (a: any[], b: any[]): any[] => {
668+
const result = [...a];
669+
670+
for (const field of b) {
671+
const exists = result?.some(f =>
672+
f?.uid === field?.uid &&
673+
f?.data_type === field?.data_type
662674
);
663675
if (!exists) {
664-
a.push(fieldGp);
676+
result?.push(field);
665677
}
666678
}
667-
return a;
679+
680+
return result;
681+
};
682+
683+
const mergeFields = async (schema1: any[], schema2: any[]): Promise<any[]> => {
684+
const result: any[] = [];
685+
686+
for (const field2 of schema2) {
687+
if (field2?.data_type === 'group') {
688+
const machingGroup = findGroupByUid(schema1, field2?.uid);
689+
if(machingGroup){
690+
const schema = await mergeArrays(machingGroup?.schema ?? [],field2?.schema ?? [] );
691+
result?.push({
692+
...field2,
693+
schema: schema
694+
});
695+
}
696+
else{
697+
result?.push({
698+
...field2,
699+
schema: await mergeFields(schema1, field2?.schema)
700+
})
701+
}
702+
}
703+
else{
704+
const exists = schema1?.find(
705+
(fld) =>
706+
fld?.uid === field2?.uid &&
707+
fld?.data_type === field2?.data_type
708+
);
709+
result?.push({
710+
...field2
711+
});
712+
713+
}
714+
715+
}
716+
717+
for (const field1 of schema1) {
718+
const isMatched = schema2?.some(
719+
(field2) =>
720+
field1?.uid === field2?.uid &&
721+
field1?.data_type === field2?.data_type
722+
);
723+
724+
if (!isMatched) {
725+
result?.push(field1);
726+
}
727+
}
728+
729+
return result;
668730
}
669731

732+
733+
const findGroupByUid = (
734+
schema: any[],
735+
uid: string,
736+
excludeRef: any = null
737+
): any | undefined => {
738+
for (const field of schema) {
739+
if (field?.data_type === 'group') {
740+
if (field?.uid === uid && field !== excludeRef) return field;
741+
const nested = findGroupByUid(field?.schema ?? [], uid, excludeRef);
742+
if (nested) return nested;
743+
}
744+
}
745+
return undefined;
746+
};
747+
670748
const mergeTwoCts = async (ct: any, mergeCts: any) => {
671-
const ctData: any = {
672-
...ct,
749+
const merged :any = {
673750
title: mergeCts?.title,
674751
uid: mergeCts?.uid,
675752
options: {
676753
"singleton": false,
677-
}
678-
}
679-
for await (const field of ctData?.schema ?? []) {
680-
if (field?.data_type === 'group') {
681-
const currentGroup = mergeCts?.schema?.find((grp: any) => grp?.uid === field?.uid &&
682-
grp?.data_type === 'group');
683-
const group = [];
684-
for await (const fieldGp of currentGroup?.schema ?? []) {
685-
const fieldNst = field?.schema?.find((fld: any) => fld?.uid === fieldGp?.uid &&
686-
fld?.data_type === fieldGp?.data_type);
687-
if (fieldNst === undefined) {
688-
group?.push(fieldGp);
689-
}
690-
}
691-
field.schema = [...field?.schema ?? [], ...group];
692-
}
693-
}
694-
ctData.schema = await mergeArrays(ctData?.schema, mergeCts?.schema) ?? [];
695-
return ctData;
754+
},
755+
schema: await mergeFields(ct?.schema ?? [], mergeCts?.schema ?? [])
756+
};
757+
758+
return merged;
696759
}
697760

698761
export const contenTypeMaker = async ({ contentType, destinationStackId, projectId, newStack, keyMapper, region, user_id }: any) => {
@@ -717,7 +780,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
717780
"display_name": item?.contentstackField,
718781
"field_metadata": {},
719782
"schema": [],
720-
"uid": item?.contentstackFieldUid,
783+
"uid": item?.contentstackFieldUid?.replace(/\./g, '_'),
721784
"multiple": false,
722785
"mandatory": false,
723786
"unique": false
@@ -728,7 +791,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
728791
uid: extractValue(element?.contentstackFieldUid, item?.contentstackFieldUid, '.'),
729792
title: extractValue(element?.contentstackField, item?.contentstackField, ' >')?.trim(),
730793
}
731-
const schema: any = convertToSchemaFormate({ field, marketPlacePath });
794+
const schema: any = convertToSchemaFormate({ field, marketPlacePath, keyMapper});
732795
if (typeof schema === 'object' && Array.isArray(group?.schema) && element?.isDeleted === false) {
733796
group.schema.push(schema);
734797
}
@@ -741,7 +804,8 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
741804
title: item?.contentstackField,
742805
uid: item?.contentstackFieldUid
743806
},
744-
marketPlacePath
807+
marketPlacePath,
808+
keyMapper
745809
});
746810
if (dt && item?.isDeleted === false) {
747811
ct?.schema?.push(dt);

api/src/utils/field-attacher.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const fieldAttacher = async ({ projectId, orgId, destinationStackId, regi
2222
contentType.fieldMapping = contentType?.fieldMapping?.map((fieldUid: any) => {
2323
const field = FieldMapperModel.chain
2424
.get("field_mapper")
25-
.find({ id: fieldUid, projectId: projectId })
25+
.find({ id: fieldUid, projectId: projectId , contentTypeId: contentId})
2626
.value()
2727
return field;
2828
})

ui/src/components/AdvancePropertise/advanceProperties.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface SchemaProps {
2525
* @param value - The advanced settings.
2626
* @param checkBoxChanged - Indicates whether the checkbox has changed.
2727
*/
28-
updateFieldSettings: (rowId: string, value: Advanced, checkBoxChanged: boolean) => void;
28+
updateFieldSettings: (rowId: string, value: Advanced, checkBoxChanged: boolean, rowContentstackFieldUid: string) => void;
2929

3030
/**
3131
* Indicates whether the field is localized.

ui/src/components/AdvancePropertise/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ const AdvancePropertise = (props: SchemaProps) => {
147147
title: currentToggleStates?.title,
148148
url: currentToggleStates?.url
149149
},
150-
checkBoxChanged
150+
checkBoxChanged,
151+
props?.data?.contentstackFieldUid
152+
151153
);
152154
};
153155

@@ -189,7 +191,8 @@ const AdvancePropertise = (props: SchemaProps) => {
189191
title: currentToggleStates?.title,
190192
url: currentToggleStates?.url
191193
},
192-
checkBoxChanged
194+
checkBoxChanged,
195+
props?.data?.contentstackFieldUid
193196
);
194197
};
195198

@@ -215,7 +218,8 @@ const AdvancePropertise = (props: SchemaProps) => {
215218
embedObject: currentToggleStates?.embedObject,
216219
embedObjects: embedObjectsLabels
217220
},
218-
true
221+
true,
222+
props?.data?.contentstackFieldUid
219223
);
220224
};
221225

@@ -251,7 +255,8 @@ const AdvancePropertise = (props: SchemaProps) => {
251255
embedObjects: embedObjectsLabels,
252256
options: options
253257
},
254-
true
258+
true,
259+
props?.data?.contentstackFieldUid
255260
);
256261
};
257262
const handleRemoveDefalutValue = (index: number) => {
@@ -280,7 +285,8 @@ const AdvancePropertise = (props: SchemaProps) => {
280285
embedObjects: embedObjectsLabels,
281286
options: options
282287
},
283-
true
288+
true,
289+
props?.data?.contentstackFieldUid
284290
);
285291
};
286292

@@ -583,7 +589,8 @@ const AdvancePropertise = (props: SchemaProps) => {
583589
validationRegex: toggleStates?.validationRegex ?? '',
584590
embedObjects: embedObject
585591
},
586-
true
592+
true,
593+
props?.data?.contentstackFieldUid
587594
);
588595
}}
589596
options={option}

ui/src/components/ContentMapper/contentMapper.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,5 @@ export interface ModifiedField {
206206
backupFieldType: string;
207207
parentId: string;
208208
uid: string;
209+
_canSelect?: boolean;
209210
}

ui/src/components/ContentMapper/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,7 @@ div .table-row {
311311
font-size: $size-font-large;
312312
font-weight: $font-weight-semi-bold;
313313
}
314+
.filterButton-color{
315+
color: $color-brand-primary-base;
316+
font-weight: $font-weight-bold;
317+
}

0 commit comments

Comments
 (0)