Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 58 additions & 25 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
let updatedExstingField: ExistingFieldType = existingField;
const updatedSelectedOptions: string[] = selectedOptions;
const [initialRowSelectedData, setInitialRowSelectedData] = useState();

const deletedExstingField : ExistingFieldType= existingField;
const isNewStack = newMigrationData?.stackDetails?.isNewStack;
const [isFieldDeleted, setIsFieldDeleted] = useState<boolean>(false);

/** ALL HOOKS Here */
const { projectId = '' } = useParams();
Expand Down Expand Up @@ -352,13 +353,20 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
if(schema?.schema) {
schema?.schema?.forEach((childSchema) => {
if(row?.contentstackField === `${schema?.display_name} > ${childSchema?.display_name}`){
if(existingField[row?.uid]){
if(!isFieldDeleted) {

updatedExstingField[row?.uid] = {
label: `${schema?.display_name} > ${childSchema?.display_name}`,
value: childSchema
}

}
// else if(existingField[row?.uid]){
// updatedExstingField[row?.uid] = {
// label: `${schema?.display_name} > ${childSchema?.display_name}`,
// value: childSchema
// }
// }

}
})
Expand Down Expand Up @@ -429,20 +437,20 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
},[contentTypeSchema]);

// To dispatch the changed dropdown state
useEffect(() => {
const newMigrationDataObj: INewMigration = {
...newMigrationData,
content_mapping: {
...newMigrationData?.content_mapping,
isDropDownChanged: isDropDownChanged,
content_type_mapping: [
...newMigrationData?.content_mapping?.content_type_mapping ?? [],
]
}
};

dispatch(updateNewMigrationData((newMigrationDataObj)));
}, [isDropDownChanged]);
// useEffect(() => {
// const newMigrationDataObj: INewMigration = {
// ...newMigrationData,
// content_mapping: {
// ...newMigrationData?.content_mapping,
// isDropDownChanged: isDropDownChanged,
// content_type_mapping: [
// ...newMigrationData?.content_mapping?.content_type_mapping ?? [],
// ]
// }
// };

// dispatch(updateNewMigrationData((newMigrationDataObj)));
// }, [isDropDownChanged]);


useBlockNavigation(isModalOpen);
Expand Down Expand Up @@ -568,6 +576,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
};

const openContentType = (i: number) => {
setIsFieldDeleted(false);
setActive(i);
const otherTitle = contentTypes?.[i]?.otherCmsTitle;
setOtherCmsTitle(otherTitle);
Expand Down Expand Up @@ -870,7 +879,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
</div>
);
};

// console.log("false", isFieldDeleted);
const handleFieldChange = (selectedValue: FieldTypes, rowIndex: string) => {
setIsDropDownChanged(true);
const previousSelectedValue = existingField[rowIndex]?.label;
Expand All @@ -879,9 +888,32 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
)
if(groupArray[0].child && previousSelectedValue !== selectedValue?.label && groupArray[0]?.uid === rowIndex){
for(const item of groupArray[0].child){
deletedExstingField[item?.uid] = {
label:item?.uid,
value:existingField[item?.uid]

}
setIsFieldDeleted(true);
// console.log(deletedExstingField);

delete existingField[item?.uid]


const index = selectedOptions?.indexOf(`${item.contentstackField}`);
//console.log(index);
if(index > -1){
selectedOptions.slice(index,1 )
}


}
}
else{


setIsFieldDeleted(false);
}



setExistingField((prevOptions: ExistingFieldType) => ({
Expand Down Expand Up @@ -1346,7 +1378,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
}
};

dispatch(updateNewMigrationData((newMigrationDataObj)));

dispatch(updateNewMigrationData(newMigrationDataObj));
}

if (orgId && contentTypeUid && selectedContentType) {
Expand Down Expand Up @@ -1383,21 +1416,21 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
setIsContentTypeMapped(true);
setIsContentTypeSaved(true);

const newMigrationDataObj: INewMigration = {
...newMigrationData,
content_mapping: { ...newMigrationData?.content_mapping, isDropDownChanged: false }
};
// const newMigrationDataObj: INewMigration = {
// ...newMigrationData,
// content_mapping: { ...newMigrationData?.content_mapping, isDropDownChanged: false }
// };


dispatch(updateNewMigrationData((newMigrationDataObj)));
// dispatch(updateNewMigrationData((newMigrationDataObj)));

const savedCT = filteredContentTypes?.map(ct =>
ct?.id === data?.data?.updatedContentType?.id ? { ...ct, status: data?.data?.updatedContentType?.status } : ct
);

setFilteredContentTypes(savedCT);
setContentTypes(savedCT);
await updateContentMapper(orgId, projectID, [contentTypeMapped,{[otherCmsTitle]: otherContentType?.label}]);
await updateContentMapper(orgId, projectID, [...newMigrationData.content_mapping.content_type_mapping,{[otherCmsTitle]: otherContentType?.label}]);

} else {
Notification({
Expand Down Expand Up @@ -1796,4 +1829,4 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
});

ContentMapper.displayName = 'ContentMapper';
export default ContentMapper;
export default ContentMapper;
2 changes: 0 additions & 2 deletions ui/src/components/DestinationStack/Actions/LoadStacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const defaultStack = {
};

const LoadStacks = (props: LoadFileFormatProps) => {
console.log("props", props);

/**** ALL HOOKS HERE ****/
const newMigrationData = useSelector((state:RootState)=>state?.migration?.newMigrationData);
const selectedOrganisation = useSelector((state:RootState)=>state?.authentication?.selectedOrganisation);
Expand Down