Skip to content
Merged
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
52 changes: 40 additions & 12 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
const isNewStack = newMigrationData?.stackDetails?.isNewStack;
const [isFieldDeleted, setIsFieldDeleted] = useState<boolean>(false);
const [isContentDeleted, setIsContentDeleted] = useState<boolean>(false);
const [isCsCTypeUpdated, setsCsCTypeUpdated] = useState<boolean>(false);


/** ALL HOOKS Here */
Expand Down Expand Up @@ -435,7 +436,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
// if exsting content type is changed in contentstack, reflect those changes for
// maaped fields
useEffect(() => {
if (existingField) {
if (existingField && !isCsCTypeUpdated) {

contentTypeSchema?.forEach((item) => {
for (const [key, value] of Object.entries(existingField)) {
Expand Down Expand Up @@ -467,7 +468,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R

},[contentTypeSchema]);
useEffect(() => {
if (existingField) {
if (existingField && isCsCTypeUpdated) {
const matchedKeys = new Set<string>();

contentTypeSchema?.forEach((item) => {
Expand Down Expand Up @@ -674,7 +675,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
setActive(i);
const otherTitle = filteredContentTypes?.[i]?.contentstackUid;
const mappedContentType = contentModels && contentModels?.find((item)=> item?.uid === newMigrationData?.content_mapping?.content_type_mapping?.[otherTitle]);
setOtherCmsTitle(otherTitle);
setOtherCmsTitle(filteredContentTypes?.[i]?.otherCmsTitle);
setContentTypeUid(filteredContentTypes?.[i]?.id ?? '');
fetchFields(filteredContentTypes?.[i]?.id ?? '', searchText || '');
setOtherCmsUid(filteredContentTypes?.[i]?.otherCmsUid);
Expand Down Expand Up @@ -884,6 +885,8 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
};

const handleDropDownChange = (value: FieldTypes) => {
(value?.id !== otherContentType?.id) && setsCsCTypeUpdated(true);

setOtherContentType(value);
};

Expand Down Expand Up @@ -964,17 +967,22 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
data?.otherCmsField === 'title' ||
data?.otherCmsField === 'url' ||
data?.otherCmsType === 'reference' ||
data?.otherCmsType === 'global_field'
data?.contentstackFieldType === 'global_field'
) && (
<Tooltip
content="Advanced properties"
position="top"
disabled={
data?.otherCmsField === 'title' ||
data?.otherCmsField === 'url'
data?.otherCmsField === 'url' ||
newMigrationData?.project_current_step > 4
}
>
<Icon
<Button
buttonType="light"
disabled={newMigrationData?.project_current_step > 4}
>
<Icon
version="v2"
icon="Sliders"
size="small"
Expand All @@ -983,6 +991,9 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
}
disabled={newMigrationData?.project_current_step > 4}
/>

</Button>

</Tooltip>
)}
</div>
Expand Down Expand Up @@ -1470,7 +1481,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
selectedContentType?.otherCmsUid &&
otherContentType?.label
) {
setContentTypeMapped((prevState: ContentTypeMap) => ({
otherContentType?.id && setContentTypeMapped((prevState: ContentTypeMap) => ({
...prevState,
[selectedContentType?.contentstackUid]: otherContentType?.id ?? ''
}));
Expand Down Expand Up @@ -1525,6 +1536,17 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
dispatch(updateNewMigrationData(newMigrationDataObj));

}
else{
const newMigrationDataObj: INewMigration = {
...newMigrationData,
content_mapping: {
...newMigrationData?.content_mapping,
isDropDownChanged: false
}
};
dispatch(updateNewMigrationData(newMigrationDataObj));

}



Expand Down Expand Up @@ -1672,10 +1694,13 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
try {
const { data , status} = await getExistingContentTypes(projectId, otherContentType?.id ?? '');
if (status == 201 && data?.contentTypes?.length > 0) {
otherContentType?.id && setOtherContentType({
(otherContentType?.id === data?.selectedContentType?.uid) && setsCsCTypeUpdated(false);

(otherContentType?.id && otherContentType?.label !== data?.selectedContentType?.title)
&& setOtherContentType({
label: data?.selectedContentType?.title,
value: data?.selectedContentType?.title,
id:data?.selectedContentType?.uid
id: data?.selectedContentType?.uid
})
setContentModels(data?.contentTypes);
const newMigrationDataObj : INewMigration = {
Expand Down Expand Up @@ -1717,10 +1742,13 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
const { data, status } = await getExistingGlobalFields(projectId, otherContentType?.id ?? '');

if (status == 201 && data?.globalFields?.length > 0) {
otherContentType?.id && setOtherContentType({
(otherContentType?.id === data?.selectedGlobalField?.uid) && setsCsCTypeUpdated(false);

(otherContentType?.id && otherContentType?.label !== data?.selectedGlobalField?.title)
&& setOtherContentType({
label: data?.selectedGlobalField?.title,
value:data?.selectedGlobalField?.title,
id:data?.selectedGlobalField?.uid
id: data?.selectedGlobalField?.uid
})
setContentModels(data?.globalFields);

Expand Down Expand Up @@ -1907,7 +1935,7 @@ const ContentMapper = forwardRef(({handleStepChange}: contentMapperProps, ref: R
</div>
:
<div className="step-container">
{contentTypes.length > 0 ?
{(contentTypes.length > 0 || tableData?.length > 0) ?
<div className="d-flex flex-wrap table-container">
{/* Content Types List */}
<div className="content-types-list-wrapper">
Expand Down