Skip to content

Commit f8ac7db

Browse files
Merge pull request #822 from contentstack/bugfix/aem-752
CMG-752: Fix advanced settings not resetting on mapping reset
2 parents 860ee72 + aa8e183 commit f8ac7db

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

api/src/services/contentMapper.service.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ const putTestData = async (req: Request) => {
5555
return { ...item, id, projectId };
5656
});
5757

58+
contentTypes?.forEach((items: any) => {
59+
items?.fieldMapping?.forEach?.((item: any) => {
60+
if (item?.advanced) {
61+
item.advanced.initial = structuredClone(item?.advanced);
62+
}
63+
});
64+
});
65+
66+
67+
5868
/*
5969
this code snippet iterates over an array of contentTypes and performs
6070
some operations on each element.
@@ -65,7 +75,6 @@ const putTestData = async (req: Request) => {
6575
Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array.
6676
*/
6777
await FieldMapperModel.read();
68-
6978
contentTypes.map((type: any, index: any) => {
7079
const fieldIds: string[] = [];
7180
const fields = Array?.isArray?.(type?.fieldMapping) ? type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => {
@@ -265,7 +274,15 @@ const getFieldMapping = async (req: Request) => {
265274

266275
return fieldMapper;
267276
});
268-
const fieldMapping: any = fieldData;
277+
278+
const fieldMapping: any = fieldData?.map((field: any) => {
279+
if (field?.advanced?.initial) {
280+
const { initial, ...restAdvanced } = field?.advanced;
281+
return { ...field, advanced: restAdvanced };
282+
}
283+
return field;
284+
});
285+
269286
if (!isEmpty(fieldMapping)) {
270287
if (search) {
271288
filteredResult = fieldMapping?.filter?.((item: any) =>
@@ -633,8 +650,16 @@ const updateContentType = async (req: Request) => {
633650
);
634651
if (fieldIndex > -1 && field?.contentstackFieldType !== "") {
635652
FieldMapperModel.update((data: any) => {
653+
const existingField = data?.field_mapper?.[fieldIndex];
654+
const preservedInitial = existingField?.advanced?.initial;
655+
656+
636657
data.field_mapper[fieldIndex] = field;
637-
//data.field_mapper[fieldIndex].isDeleted = false;
658+
659+
660+
if (preservedInitial && field?.advanced) {
661+
data.field_mapper[fieldIndex].advanced.initial = preservedInitial;
662+
}
638663
});
639664
}
640665
});
@@ -750,12 +775,17 @@ const resetToInitialMapping = async (req: Request) => {
750775
);
751776
if (fieldIndex > -1) {
752777
FieldMapperModel.update((data: any) => {
753-
data.field_mapper[fieldIndex] = {
754-
...field,
755-
contentstackField: field?.otherCmsField,
756-
contentstackFieldUid: field?.backupFieldUid,
757-
contentstackFieldType: field?.backupFieldType,
758-
};
778+
779+
data.field_mapper[fieldIndex] = {
780+
...field,
781+
contentstackField: field?.otherCmsField,
782+
contentstackFieldUid: field?.backupFieldUid,
783+
contentstackFieldType: field?.backupFieldType,
784+
advanced: {
785+
...field?.advanced?.initial,
786+
initial: field?.advanced?.initial,
787+
}
788+
}
759789
});
760790
}
761791
});

ui/src/components/ContentMapper/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
20672067
isDropDownChanged: false
20682068
}
20692069
};
2070+
20702071
dispatch(updateNewMigrationData(newMigrationDataObj));
20712072
const resetCT = filteredContentTypes?.map?.(ct =>
20722073
ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct
@@ -2082,9 +2083,13 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
20822083
const resetContentTypes = contentTypes?.map?.(ct =>
20832084
ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct
20842085
);
2086+
20852087
setFilteredContentTypes(filteredCT);
20862088
setContentTypes(resetContentTypes);
20872089
setCount(filteredCT?.length);
2090+
2091+
await fetchFields(selectedContentType?.id ?? '', searchText || '');
2092+
20882093
Notification({
20892094
notificationContent: { text: data?.message },
20902095
notificationProps: {

0 commit comments

Comments
 (0)