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
2 changes: 1 addition & 1 deletion api/src/models/project-lowdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface Project {
isNewStack: boolean;
newStackId: string;
stackDetails: [];
mapperKeys: [];
mapperKeys: {};
extract_path: string;
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const createProject = async (req: Request) => {
created_at: '',
isNewStack: false
},
mapperKeys: []
mapperKeys: {}
};

try {
Expand Down
66 changes: 35 additions & 31 deletions ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
const [selectedOptions, setSelectedOptions] = useState<string[]>([]);
const [isDropDownChanged, setIsDropDownChanged] = useState<boolean>(false);
const [contentTypeMapped, setContentTypeMapped] = useState<ContentTypeMap>(
newMigrationData?.content_mapping?.content_type_mapping?.[0] || {}
newMigrationData?.content_mapping?.content_type_mapping || {}
);
const [otherContentType, setOtherContentType] = useState<FieldTypes>({
label: newMigrationData?.content_mapping?.content_type_mapping?.[0]?.[otherCmsTitle] || 'Select content type from existing stack',
value: newMigrationData?.content_mapping?.content_type_mapping?.[0]?.[otherCmsTitle] || 'Select content type from existing stack',
label: contentTypeMapped?.[otherCmsTitle] || 'Select content type from existing stack',
value: contentTypeMapped?.[otherCmsTitle] || 'Select content type from existing stack',
});
const [otherCmsUid, setOtherCmsUid] = useState<string>(contentTypes[0]?.otherCmsUid);
const [isContentTypeMapped, setIsContentTypeMapped] = useState<boolean>(false);
Expand Down Expand Up @@ -323,23 +323,16 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
},[tableData]);

useEffect(() => {
if(otherCmsTitle) {
newMigrationData?.content_mapping?.content_type_mapping?.forEach((ctMap) => {
if (ctMap?.[otherCmsTitle] !== undefined) {

setOtherContentType({
label: ctMap?.[otherCmsTitle] ?? 'Select content type from existing stack',
value: ctMap?.[otherCmsTitle] ?? 'Select content type from existing stack'
})
}
})
if (contentTypeMapped && otherCmsTitle) {
setOtherContentType({
label: contentTypeMapped?.[otherCmsTitle] ?? 'Select content type from existing stack',
value: contentTypeMapped?.[otherCmsTitle] ?? 'Select content type from existing stack'
});
}
}, [otherCmsTitle]);
}, [contentTypeMapped, otherCmsTitle]);

useEffect(() => {
const checkKey = newMigrationData?.content_mapping?.content_type_mapping?.find(ctMap => ctMap[otherCmsTitle] === otherContentType?.label);

if (checkKey?.[otherCmsTitle] !== undefined) {
if (contentTypeMapped[otherCmsTitle] === otherContentType?.label) {
tableData?.forEach((row) => {
contentTypeSchema?.forEach((schema) => {

Expand All @@ -361,13 +354,6 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
}

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

}
})
}
Expand Down Expand Up @@ -582,8 +568,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
setOtherCmsTitle(otherTitle);

setOtherContentType({
label: newMigrationData?.content_mapping?.content_type_mapping?.[i]?.[otherTitle] || 'Select content type from existing stack',
value: newMigrationData?.content_mapping?.content_type_mapping?.[i]?.[otherTitle] || 'Select content type from existing stack'
label: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack',
value: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack'
});

setContentTypeUid(contentTypes?.[i]?.id ?? '');
Expand Down Expand Up @@ -970,6 +956,16 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re

setTableData(updatedRows);
setSelectedEntries(updatedRows);

const dropdownChangeState: INewMigration = {
...newMigrationData,
content_mapping: {
...newMigrationData?.content_mapping,
isDropDownChanged: true
}
}
dispatch(updateNewMigrationData((dropdownChangeState)));

};

//function to generate group schema structure of source cms
Expand Down Expand Up @@ -1370,11 +1366,11 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re
...newMigrationData,
content_mapping: {
...newMigrationData?.content_mapping,
content_type_mapping: [
content_type_mapping: {

...newMigrationData?.content_mapping?.content_type_mapping ?? [],
{[otherCmsTitle]: otherContentType?.label}
]
...newMigrationData?.content_mapping?.content_type_mapping ?? {},
[otherCmsTitle]: otherContentType?.label
}
}
};

Expand Down Expand Up @@ -1430,7 +1426,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re

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

} else {
Notification({
Expand All @@ -1447,6 +1443,14 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re

const handleDropdownState = () => {
setIsDropDownChanged(false);
const dropdownChangeState: INewMigration = {
...newMigrationData,
content_mapping: {
...newMigrationData?.content_mapping,
isDropDownChanged: false
}
}
dispatch(updateNewMigrationData((dropdownChangeState )));
}

useImperativeHandle(ref, () => ({
Expand Down
8 changes: 4 additions & 4 deletions ui/src/context/app/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ export interface IDestinationStack {
stackArray: IDropDown[];
}
export interface IContentMapper {
content_type_mapping: ContentTypeMap[];
content_type_mapping: ContentTypeMap;
isDropDownChanged?: boolean;
otherCmsTitle?: string;
}
export interface INewMigration {
mapperKeys: ContentTypeMap[];
mapperKeys: ContentTypeMap;
legacy_cms: ILegacyCms;
destination_stack: IDestinationStack;
content_mapping: IContentMapper;
Expand Down Expand Up @@ -305,7 +305,7 @@ export const DEFAULT_DESTINATION_STACK: IDestinationStack = {
};

export const DEFAULT_CONTENT_MAPPER: IContentMapper = {
content_type_mapping: [],
content_type_mapping: {},
isDropDownChanged: false,
otherCmsTitle: ''
};
Expand All @@ -316,7 +316,7 @@ export const DEFAULT_TEST_MIGRATION: ITestMigration = {
};

export const DEFAULT_NEW_MIGRATION: INewMigration = {
mapperKeys: [],
mapperKeys: {},
legacy_cms: DEFAULT_LEGACY_CMS,
destination_stack: DEFAULT_DESTINATION_STACK,
content_mapping: DEFAULT_CONTENT_MAPPER,
Expand Down