diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index bccc9cba3..bef1b1a5f 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -55,6 +55,16 @@ const putTestData = async (req: Request) => { return { ...item, id, projectId }; }); + contentTypes?.forEach((items: any) => { + items?.fieldMapping?.forEach?.((item: any) => { + if (item?.advanced) { + item.advanced.initial = structuredClone(item?.advanced); + } + }); + }); + + + /* this code snippet iterates over an array of contentTypes and performs some operations on each element. @@ -65,7 +75,6 @@ const putTestData = async (req: Request) => { Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array. */ await FieldMapperModel.read(); - contentTypes.map((type: any, index: any) => { const fieldIds: string[] = []; const fields = Array?.isArray?.(type?.fieldMapping) ? type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => { @@ -265,7 +274,15 @@ const getFieldMapping = async (req: Request) => { return fieldMapper; }); - const fieldMapping: any = fieldData; + + const fieldMapping: any = fieldData?.map((field: any) => { + if (field?.advanced?.initial) { + const { initial, ...restAdvanced } = field?.advanced; + return { ...field, advanced: restAdvanced }; + } + return field; + }); + if (!isEmpty(fieldMapping)) { if (search) { filteredResult = fieldMapping?.filter?.((item: any) => @@ -633,8 +650,16 @@ const updateContentType = async (req: Request) => { ); if (fieldIndex > -1 && field?.contentstackFieldType !== "") { FieldMapperModel.update((data: any) => { + const existingField = data?.field_mapper?.[fieldIndex]; + const preservedInitial = existingField?.advanced?.initial; + + data.field_mapper[fieldIndex] = field; - //data.field_mapper[fieldIndex].isDeleted = false; + + + if (preservedInitial && field?.advanced) { + data.field_mapper[fieldIndex].advanced.initial = preservedInitial; + } }); } }); @@ -750,12 +775,17 @@ const resetToInitialMapping = async (req: Request) => { ); if (fieldIndex > -1) { FieldMapperModel.update((data: any) => { - data.field_mapper[fieldIndex] = { - ...field, - contentstackField: field?.otherCmsField, - contentstackFieldUid: field?.backupFieldUid, - contentstackFieldType: field?.backupFieldType, - }; + + data.field_mapper[fieldIndex] = { + ...field, + contentstackField: field?.otherCmsField, + contentstackFieldUid: field?.backupFieldUid, + contentstackFieldType: field?.backupFieldType, + advanced: { + ...field?.advanced?.initial, + initial: field?.advanced?.initial, + } + } }); } }); diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index f18bee009..e4d25e2d2 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -2067,6 +2067,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: isDropDownChanged: false } }; + dispatch(updateNewMigrationData(newMigrationDataObj)); const resetCT = filteredContentTypes?.map?.(ct => ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct @@ -2082,9 +2083,13 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: const resetContentTypes = contentTypes?.map?.(ct => ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct ); + setFilteredContentTypes(filteredCT); setContentTypes(resetContentTypes); setCount(filteredCT?.length); + + await fetchFields(selectedContentType?.id ?? '', searchText || ''); + Notification({ notificationContent: { text: data?.message }, notificationProps: {