From 3753d46d3b0aa5c1285faad740503637543debd6 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Mon, 16 Sep 2024 19:33:33 +0530 Subject: [PATCH] Resolved mapped content types disable issue --- api/src/models/project-lowdb.ts | 2 +- api/src/services/projects.service.ts | 2 +- ui/src/components/ContentMapper/index.tsx | 66 ++++++++++++----------- ui/src/context/app/app.interface.ts | 8 +-- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/api/src/models/project-lowdb.ts b/api/src/models/project-lowdb.ts index 99075ccd..4de76bac 100644 --- a/api/src/models/project-lowdb.ts +++ b/api/src/models/project-lowdb.ts @@ -70,7 +70,7 @@ interface Project { isNewStack: boolean; newStackId: string; stackDetails: []; - mapperKeys: []; + mapperKeys: {}; extract_path: string; } diff --git a/api/src/services/projects.service.ts b/api/src/services/projects.service.ts index 58c91176..30e83276 100644 --- a/api/src/services/projects.service.ts +++ b/api/src/services/projects.service.ts @@ -125,7 +125,7 @@ const createProject = async (req: Request) => { created_at: '', isNewStack: false }, - mapperKeys: [] + mapperKeys: {} }; try { diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index d1efa746..19f41d1b 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -243,11 +243,11 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const [selectedOptions, setSelectedOptions] = useState([]); const [isDropDownChanged, setIsDropDownChanged] = useState(false); const [contentTypeMapped, setContentTypeMapped] = useState( - newMigrationData?.content_mapping?.content_type_mapping?.[0] || {} + newMigrationData?.content_mapping?.content_type_mapping || {} ); const [otherContentType, setOtherContentType] = useState({ - 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(contentTypes[0]?.otherCmsUid); const [isContentTypeMapped, setIsContentTypeMapped] = useState(false); @@ -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) => { @@ -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 - // } - // } - } }) } @@ -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 ?? ''); @@ -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 @@ -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 + } } }; @@ -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({ @@ -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, () => ({ diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index c723ba36..da29be63 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -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; @@ -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: '' }; @@ -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,