From b29e2b0237c461da447b0183d85f4ddd24a9906e Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 20 Sep 2024 10:40:03 +0530 Subject: [PATCH 1/7] refactor:content mapper bugs --- ui/src/components/ContentMapper/index.tsx | 132 +++++++++++++++++++--- ui/src/context/app/app.interface.ts | 5 +- 2 files changed, 121 insertions(+), 16 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index c5cded6b..7d137f85 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -284,6 +284,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const deletedExstingField : ExistingFieldType= existingField; const isNewStack = newMigrationData?.stackDetails?.isNewStack; const [isFieldDeleted, setIsFieldDeleted] = useState(false); + const [isContentDeleted, setIsContentDeleted] = useState(false); /** ALL HOOKS Here */ const { projectId = '' } = useParams(); @@ -323,13 +324,46 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re },[tableData]); useEffect(() => { - if (contentTypeMapped && otherCmsTitle) { - setOtherContentType({ - label: contentTypeMapped?.[otherCmsTitle] ?? 'Select content type from existing stack', - value: contentTypeMapped?.[otherCmsTitle] ?? 'Select content type from existing stack' - }); + const mappedContentType = contentTypesList && contentTypesList?.find((item)=>item?.title === contentTypeMapped?.[otherCmsTitle]); + + if (contentTypeMapped && otherCmsTitle ) { + + if (mappedContentType?.uid) { + setOtherContentType({ + id: mappedContentType?.uid, + label: contentTypeMapped?.[otherCmsTitle], + value: contentTypeMapped?.[otherCmsTitle], + }); + setIsContentDeleted(false); + } else { + + setOtherContentType({ + label: 'Select content type from existing stack', + value: 'Select content type from existing stack', + }); + + } + + } + + }, [contentTypeMapped, otherCmsTitle,contentTypesList]); + + + + useEffect(()=>{ + if(isContentDeleted){ + setContentTypeMapped((prevState: ContentTypeMap) => { + const { [otherCmsTitle]: removed, ...newState } = prevState; + + return newState; + }); + + setIsFieldDeleted(false); } - }, [contentTypeMapped, otherCmsTitle]); + + + },[isContentDeleted, contentTypesList, otherCmsTitle]) + useEffect(() => { if (contentTypeMapped[otherCmsTitle] === otherContentType?.label) { @@ -567,10 +601,10 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const otherTitle = contentTypes?.[i]?.otherCmsTitle; setOtherCmsTitle(otherTitle); - setOtherContentType({ - label: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack', - value: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack' - }); + // setOtherContentType({ + // label: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack', + // value: contentTypeMapped?.[otherTitle] || 'Select content type from existing stack' + // }); setContentTypeUid(contentTypes?.[i]?.id ?? ''); fetchFields(contentTypes?.[i]?.id ?? '', searchText || ''); @@ -583,6 +617,16 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const { data, status } = await getExistingContentTypes(projectId); if (status === 201) { setContentTypesList(data?.contentTypes); + const mappedContentType = data?.contentTypes && data?.contentTypes?.find((item:ContentTypeList)=>item?.title === contentTypeMapped?.[otherCmsTitle]); + + if (mappedContentType?.uid) { + setOtherContentType({ + id: mappedContentType?.uid, + label: contentTypeMapped?.[otherCmsTitle], + value: contentTypeMapped?.[otherCmsTitle], + }); + setIsContentDeleted(false); + } } }; @@ -1480,6 +1524,15 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re fieldMapping: updatedRows } }; + let newstate = {} ; + setContentTypeMapped((prevState: ContentTypeMap) => { + const newState = { ...prevState }; + + delete newState[otherCmsTitle]; + newstate = newState; + + return newState; + }); if (orgId && selectedContentType) { const { status } = await resetToInitialMapping( orgId, @@ -1487,10 +1540,13 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re selectedContentType?.id ?? '', dataCs ); + setExistingField({}); setContentTypeSchema([]); - setContentTypeMapped({}); + if (status == 200) { + await updateContentMapper(orgId, projectID, {...newstate} ); + Notification({ notificationContent: { text: 'Content type reset successfully' }, notificationProps: { @@ -1505,6 +1561,51 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re // Function to fetch single content type const handleFetchContentType = async () => { + const { data , status} = await fetchExistingContentType(projectId,'') ; + // if(status === 201){ + // Notification({ + // notificationContent: { text: "All Content Types fetched successfully" }, + // notificationProps: { + // position: 'bottom-center', + // hideProgressBar: false + // }, + // type: 'success' + // }); + + // } + const contentTypesArr: ContentTypeList[] = contentTypesList; + const index = contentTypesList.findIndex(ct => ct?.uid === data?.uid); + + if(index != -1) { + contentTypesArr[index] = data; + } + + setContentTypesList(data?.contentTypes); + + + const content_type = data?.contentTypes?.find((item:any)=>item?.title === otherContentType?.label); + const contentTypeKey = Object.keys(contentTypeMapped).find(key => contentTypeMapped[key] === otherContentType?.label); + + + if(! content_type && contentTypeKey){ + const updatedState = { ...contentTypeMapped }; + delete updatedState[contentTypeKey]; + + setContentTypeMapped((prevState: ContentTypeMap) => { + const newState = { ...prevState }; + + delete newState[contentTypeKey] + + return newState; + }); + await updateContentMapper(selectedOrganisation?.value, projectId, {... updatedState} ); + setOtherContentType({ + label: 'Select content type from existing stack', + value: 'Select content type from existing stack' + + }); + } + if (otherContentType?.label === "Select Content Type") { Notification({ notificationContent: { text: "Please Select a Content Type to fetch." }, @@ -1514,8 +1615,9 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re }, type: 'error' }); - } else { - const { data , status} = await fetchExistingContentType(projectId, otherContentType?.id ?? ''); + } else if(otherContentType?.id){ + + const { data , status} = await fetchExistingContentType(projectId, otherContentType?.id ?? '') ; const index = contentTypesList.findIndex(ct => ct?.uid === data?.uid); @@ -1525,7 +1627,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re contentTypesArr[index] = data; } - setContentTypesList(contentTypesArr); + //setContentTypesList(contentTypesArr); setContentTypeSchema(data?.schema); if (status == 201) { Notification({ @@ -1553,7 +1655,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re } ]; - const isOtherContentType = contentTypesList?.some((ct) => ct?.title === otherContentType?.label); + const isOtherContentType = contentTypesList && contentTypesList?.some((ct) => ct?.title === otherContentType?.label); if (!isNewStack) { columns?.push({ diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index da29be63..7f82fc8e 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -5,6 +5,7 @@ import { import { ICardType, defaultCardType } from '../../components/Common/Card/card.interface'; import { CTA } from '../../types/common.interface'; import { IFilterType } from '../../components/Common/Modal/FilterModal/filterModal.interface'; +import { ContentTypeList } from '../../components/ContentMapper/contentMapper.interface'; export interface ICTA { title: string; href: string; @@ -170,6 +171,7 @@ export interface IContentMapper { content_type_mapping: ContentTypeMap; isDropDownChanged?: boolean; otherCmsTitle?: string; + contentTypeList:ContentTypeList[] } export interface INewMigration { mapperKeys: ContentTypeMap; @@ -307,7 +309,8 @@ export const DEFAULT_DESTINATION_STACK: IDestinationStack = { export const DEFAULT_CONTENT_MAPPER: IContentMapper = { content_type_mapping: {}, isDropDownChanged: false, - otherCmsTitle: '' + otherCmsTitle: '', + contentTypeList: [], }; export const DEFAULT_TEST_MIGRATION: ITestMigration = { From 4ddabee8d788a7b16d9cca491b3a29dbc2ddd65d Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 20 Sep 2024 12:19:44 +0530 Subject: [PATCH 2/7] refactor:changed logic for setting stepIndex in stepper to avoid by default render of 0th step --- .../Stepper/HorizontalStepper/HorizontalStepper.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx b/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx index 4424acf0..92a5d024 100644 --- a/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx +++ b/ui/src/components/Stepper/HorizontalStepper/HorizontalStepper.tsx @@ -77,13 +77,15 @@ const showNotification = (currentIndex:number) =>{ } const HorizontalStepper = forwardRef( (props: stepperProps, ref: React.ForwardedRef) => { + + const { stepId } = useParams<{ stepId: string }>(); + const stepIndex = parseInt(stepId || '', 10) - 1; + const { steps, className, emptyStateMsg, hideTabView, testId } = props; - const [showStep, setShowStep] = useState(0); + const [showStep, setShowStep] = useState(stepIndex); const [stepsCompleted, setStepsCompleted] = useState([]); const [isModalOpen, setIsModalOpen] = useState(false); - const { stepId } = useParams<{ stepId: string }>(); - const navigate = useNavigate(); const { projectId = '' } = useParams(); @@ -156,7 +158,8 @@ const HorizontalStepper = forwardRef( notificationContent: { text: `Please select a stack to proceed further` }, type: 'warning' }) - } else if (newMigrationData?.destination_stack?.selectedStack?.value !== newMigrationData?.stackDetails?.value) { + } + else if (newMigrationData?.destination_stack?.selectedStack?.value !== newMigrationData?.stackDetails?.value) { return Notification({ notificationContent: { text: `Please save the stack to proceed further` }, type: 'warning' From 0586d91a61888e45785c564585547d63ca1a9e33 Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 20 Sep 2024 12:23:50 +0530 Subject: [PATCH 3/7] refactor:removed file format confirmation api call form useEffect --- ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index ee835410..310d86c5 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -60,9 +60,6 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { isFileFormatCheckboxChecked: isCheckedBoxChecked } })); - await fileformatConfirmation(selectedOrganisation?.value, projectId, { - fileformat_confirmation: true - }); //call for Step Change props.handleStepChange(props?.currentStep); From d8d6bbce56216bd923cef9e9aea1e73987670382 Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 20 Sep 2024 17:29:27 +0530 Subject: [PATCH 4/7] refactor:content mapper bugs and api calls --- ui/src/components/ContentMapper/index.tsx | 26 +++++++++---------- .../LegacyCms/Actions/LoadFileFormat.tsx | 25 +++++++++++------- .../LegacyCms/Actions/LoadPrefix.tsx | 1 + 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 48f2493e..754901fe 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -537,7 +537,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re // Fetch table data const fetchData = async ({ searchText }: TableTypes) => { setSearchText(searchText) - fetchFields(contentTypeUid, searchText); + contentTypeUid && fetchFields(contentTypeUid, searchText); }; // Method for Load more table data @@ -1289,6 +1289,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re ...updatedExstingField, [data?.uid]: { label: newLabel, value: newvalue } }; + existingField[data?.uid] = { label: newLabel, value: newvalue } } const newValue: string = OptionsForRow[0]?.value?.display_name; @@ -1569,17 +1570,16 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re // Function to fetch single content type const handleFetchContentType = async () => { const { data , status} = await fetchExistingContentType(projectId,'') ; - // if(status === 201){ - // Notification({ - // notificationContent: { text: "All Content Types fetched successfully" }, - // notificationProps: { - // position: 'bottom-center', - // hideProgressBar: false - // }, - // type: 'success' - // }); - - // } + if(data?.contentTypes?.length <= 0){ + Notification({ + notificationContent: { text: "No content found in the stack" }, + notificationProps: { + position: 'bottom-center', + hideProgressBar: false + }, + type: 'error' + }); + } const contentTypesArr: ContentTypeList[] = contentTypesList; const index = contentTypesList.findIndex(ct => ct?.uid === data?.uid); @@ -1638,7 +1638,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re setContentTypeSchema(data?.schema); if (status == 201) { Notification({ - notificationContent: { text: 'Content type fetched successfully' }, + notificationContent: { text: 'Content type data fetched successfully' }, notificationProps: { position: 'bottom-center', hideProgressBar: false diff --git a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx index 310d86c5..6cfab901 100644 --- a/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadFileFormat.tsx @@ -135,16 +135,21 @@ const LoadFileFormat = (props: LoadFileFormatProps) => { return (
- } - /> + + {isError &&

{error}

}
diff --git a/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx b/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx index b01125a3..deb0d31f 100644 --- a/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx +++ b/ui/src/components/LegacyCms/Actions/LoadPrefix.tsx @@ -118,6 +118,7 @@ const LoadPreFix = (props: LoadSelectCmsProps) => { placeholder={'Enter Affix'} version="v2" error={isError} + aria-label='affix' /> {isError &&

{errorMessage}

} From be3c5c5e4ad0fd8e9f1e5378adc1a33810c49978 Mon Sep 17 00:00:00 2001 From: AishDani Date: Fri, 20 Sep 2024 17:36:50 +0530 Subject: [PATCH 5/7] refcator:uncommented code for isDropdown change --- ui/src/components/ContentMapper/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 754901fe..253e0475 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -1462,13 +1462,13 @@ 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 From 20e52933d9c4a6de984c5c083864ee146e736ef8 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Fri, 20 Sep 2024 19:32:09 +0530 Subject: [PATCH 6/7] [CMG-324] - Content mapper | Global fields | When opening global fields then on top ,existing global fields dropdown should display instead of content type dropdown --- .../projects.contentMapper.controller.ts | 19 +++++- api/src/routes/contentMapper.routes.ts | 9 +++ api/src/services/contentMapper.service.ts | 58 +++++++++++++++++-- ui/src/components/ContentMapper/index.tsx | 55 ++++++++++++++---- ui/src/services/api/migration.service.ts | 12 ++++ 5 files changed, 135 insertions(+), 18 deletions(-) diff --git a/api/src/controllers/projects.contentMapper.controller.ts b/api/src/controllers/projects.contentMapper.controller.ts index 956e3638..fd1000ae 100644 --- a/api/src/controllers/projects.contentMapper.controller.ts +++ b/api/src/controllers/projects.contentMapper.controller.ts @@ -48,6 +48,22 @@ const getExistingContentTypes = async ( const resp = await contentMapperService.getExistingContentTypes(req); res.status(201).json(resp); }; + +/** + * Retrieves the existing global fields. + * + * @param {Request} req - The request object. + * @param {Response} res - The response object. + * @returns {Promise} - A promise that resolves when the operation is complete. + */ +const getExistingGlobalFields = async ( + req: Request, + res: Response +): Promise => { + const resp = await contentMapperService.getExistingGlobalFields(req); + res.status(201).json(resp); +}; + /** * Updates the content type fields. * @@ -131,5 +147,6 @@ export const contentMapperController = { // removeMapping, getSingleContentTypes, removeContentMapper, - updateContentMapper + updateContentMapper, + getExistingGlobalFields }; diff --git a/api/src/routes/contentMapper.routes.ts b/api/src/routes/contentMapper.routes.ts index a50282d6..6b8fed79 100644 --- a/api/src/routes/contentMapper.routes.ts +++ b/api/src/routes/contentMapper.routes.ts @@ -40,6 +40,15 @@ router.get( asyncRouter(contentMapperController.getExistingContentTypes) ); +/** + * Get Existing GlobalFields List + * @route GET /:projectId + */ +router.get( + "/globalFields/:projectId", + asyncRouter(contentMapperController.getExistingGlobalFields) +); + /** * Update FieldMapping or contentType * @route PUT /contentTypes/:orgId/:projectId/:contentTypeId diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index e138ccc9..2146509c 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -268,7 +268,6 @@ const getExistingContentTypes = async (req: Request) => { data: err.response.data, status: err.response.status, }; - const contentTypes = res.data.content_types.map((singleCT: any) => { return { title: singleCT.title, @@ -280,6 +279,57 @@ const getExistingContentTypes = async (req: Request) => { //Add logic to get Project from DB return { contentTypes }; }; + +/** + * Retrieves existing global fields for a given project. + * @param req - The request object containing the project ID and token payload. + * @returns An object containing the retrieved content types. + */ +const getExistingGlobalFields = async (req: Request) => { + const projectId = req?.params?.projectId; + + const { token_payload } = req.body; + + const authtoken = await getAuthtoken( + token_payload?.region, + token_payload?.user_id + ); + await ProjectModelLowdb.read(); + const project = ProjectModelLowdb.chain + .get("projects") + .find({ id: projectId }) + .value(); + const stackId = project?.destination_stack_id; + const [err, res] = await safePromise( + https({ + method: "GET", + url: `${config.CS_API[ + token_payload?.region as keyof typeof config.CS_API + ]!}/global_fields`, + headers: { + api_key: stackId, + authtoken: authtoken, + }, + }) + ); + + if (err) + return { + data: err.response.data, + status: err.response.status, + }; + const globalFields = res.data.global_fields.map((global: any) => { + return { + title: global.title, + uid: global.uid, + schema: global.schema, + }; + }); + + //Add logic to get Project from DB + return { globalFields }; +}; + /** * Updates the content type based on the provided request. * @param req - The request object containing the necessary parameters and data. @@ -923,8 +973,6 @@ const removeContentMapper = async (req: Request) => { * @throws ExceptionFunction if an error occurs during the update. */ const updateContentMapper = async (req: Request) => { - console.info("updateContentMapper", req.params, req.body); - const { orgId, projectId } = req.params; const { token_payload, content_mapper } = req.body; const srcFunc = "updateContentMapper"; @@ -944,7 +992,6 @@ const updateContentMapper = async (req: Request) => { try { ProjectModelLowdb.update((data: any) => { - // console.info("data ===============", data, content_mapper) data.projects[projectIndex].mapperKeys = content_mapper; data.projects[projectIndex].updated_at = new Date().toISOString(); }); @@ -989,5 +1036,6 @@ export const contentMapperService = { removeContentMapper, removeMapping, getSingleContentTypes, - updateContentMapper + updateContentMapper, + getExistingGlobalFields }; diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index bd0a3b03..1129cfc1 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -21,6 +21,7 @@ import { getContentTypes, getFieldMapping, getExistingContentTypes, + getExistingGlobalFields, updateContentType, resetToInitialMapping, fetchExistingContentType, @@ -226,6 +227,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re }= {} } = migrationData; + // const contentTypesList = awau + const [tableData, setTableData] = useState([]); const [loading, setLoading] = useState(false); const [isLoading, setIsLoading] = useState(newMigrationData?.isprojectMapped); @@ -237,7 +240,13 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const [contentTypes, setContentTypes] = useState([]); const [otherCmsTitle, setOtherCmsTitle] = useState(contentTypes[0]?.otherCmsTitle); const [contentTypeUid, setContentTypeUid] = useState(''); - const [contentTypesList, setContentTypesList] = useState([]); + + const [existingContentTypes, setExistingContentTypes] = useState([]); + const [existingGlobalFields, setExistingGlobalFields] = useState([]) + const [isContentType, setIsContentType] = useState(contentTypes?.[0]?.type === "content_type"); + const [contentModels, setContentModels] = useState([]); + + const [selectedContentType, setSelectedContentType] = useState(); const [existingField, setExistingField] = useState({}); const [selectedOptions, setSelectedOptions] = useState([]); @@ -285,6 +294,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const isNewStack = newMigrationData?.stackDetails?.isNewStack; const [isFieldDeleted, setIsFieldDeleted] = useState(false); + /** ALL HOOKS Here */ const { projectId = '' } = useParams(); @@ -309,8 +319,9 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re console.error(err); }); - fetchExistingContentTypes(); fetchContentTypes(searchText || ''); + fetchExistingContentTypes(); + fetchExistingGlobalFields(); }, []); // Make title and url field non editable @@ -392,6 +403,15 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re setRowIds(selectedId); }, [tableData]); + // To fetch existing content types or global fields as per the type + useEffect(() => { + if(isContentType) { + setContentModels(existingContentTypes); + } else { + setContentModels(existingGlobalFields); + } + }, [existingContentTypes, existingGlobalFields, isContentType]) + // To close the filter panel on outside click useEffect(() => { document.addEventListener('click', handleClickOutside, true); @@ -453,6 +473,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re setContentTypeUid(data?.contentTypes?.[0]?.id); fetchFields(data?.contentTypes?.[0]?.id, searchText || ''); setOtherCmsUid(data?.contentTypes?.[0]?.otherCmsUid); + setIsContentType(data?.contentTypes?.[0]?.type === "content_type"); }; // Method to search content types @@ -576,16 +597,26 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re fetchFields(contentTypes?.[i]?.id ?? '', searchText || ''); setOtherCmsUid(contentTypes?.[i]?.otherCmsUid); setSelectedContentType(contentTypes?.[i]); + setIsContentType(contentTypes?.[i]?.type === "content_type"); } // Function to get exisiting content types list const fetchExistingContentTypes = async () => { const { data, status } = await getExistingContentTypes(projectId); - if (status === 201) { - setContentTypesList(data?.contentTypes); + if (status === 201 ) { + setExistingContentTypes(data?.contentTypes); } }; + // Function to get exisiting global fields list + const fetchExistingGlobalFields = async () => { + const { data, status } = await getExistingGlobalFields(projectId); + + if (status === 201) { + setExistingGlobalFields(data?.globalFields); + } + } + const updateFieldSettings = (rowId: string, updatedSettings: Advanced, checkBoxChanged: boolean) => { setIsDropDownChanged(checkBoxChanged); @@ -1162,9 +1193,9 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re const OptionsForRow: OptionsType[] = []; - // If OtherContentType label and contentTypesList are present, set the contentTypeSchema - if (otherContentType?.label && contentTypesList) { - const ContentType: ContentTypeList | undefined = contentTypesList?.find( + // If OtherContentType label and contentModels are present, set the contentTypeSchema + if (otherContentType?.label && contentModels) { + const ContentType: ContentTypeList | undefined = contentModels?.find( ({ title }) => title === otherContentType?.label ); setContentTypeSchema(ContentType?.schema); @@ -1524,15 +1555,15 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re } else { const { data , status} = await fetchExistingContentType(projectId, otherContentType?.id ?? ''); - const index = contentTypesList.findIndex(ct => ct?.uid === data?.uid); + const index = contentModels.findIndex(ct => ct?.uid === data?.uid); - const contentTypesArr: ContentTypeList[] = contentTypesList; + const contentTypesArr: ContentTypeList[] = contentModels; if(index != -1) { contentTypesArr[index] = data; } - setContentTypesList(contentTypesArr); + setContentModels(contentTypesArr); setContentTypeSchema(data?.schema); if (status == 201) { Notification({ @@ -1560,7 +1591,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re } ]; - const isOtherContentType = contentTypesList?.some((ct) => ct?.title === otherContentType?.label); + const isOtherContentType = contentModels?.some((ct) => ct?.title === otherContentType?.label); if (!isNewStack) { columns?.push({ @@ -1581,7 +1612,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re }); } - const options = contentTypesList?.map((item) => ({ + const options = contentModels?.map((item) => ({ label: item?.title, value: item?.title, id: item?.uid, diff --git a/ui/src/services/api/migration.service.ts b/ui/src/services/api/migration.service.ts index 71dadafe..d46a4b53 100644 --- a/ui/src/services/api/migration.service.ts +++ b/ui/src/services/api/migration.service.ts @@ -164,6 +164,18 @@ export const getExistingContentTypes = async (projectId: string) => { } }; +export const getExistingGlobalFields = async (projectId: string) => { + try { + return await getCall(`${API_VERSION}/mapper/globalFields/${projectId}`, options); + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } + } +}; + export const updateContentType = async ( orgId: string, projectId: string, From ebf68004636b23c045ac2d876487b51f317b6866 Mon Sep 17 00:00:00 2001 From: Sayali Joshi Date: Mon, 23 Sep 2024 16:14:14 +0530 Subject: [PATCH 7/7] Dropdown placeholder changes for global fields --- ui/src/components/ContentMapper/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 1141865c..09931295 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -255,8 +255,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re newMigrationData?.content_mapping?.content_type_mapping || {} ); const [otherContentType, setOtherContentType] = useState({ - label: contentTypeMapped?.[otherCmsTitle] || 'Select content type from existing stack', - value: contentTypeMapped?.[otherCmsTitle] || 'Select content type from existing stack', + label: contentTypeMapped?.[otherCmsTitle] || `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`, + value: contentTypeMapped?.[otherCmsTitle] || `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`, }); const [otherCmsUid, setOtherCmsUid] = useState(contentTypes[0]?.otherCmsUid); const [isContentTypeMapped, setIsContentTypeMapped] = useState(false); @@ -348,8 +348,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re } else { setOtherContentType({ - label: 'Select content type from existing stack', - value: 'Select content type from existing stack', + label: `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`, + value: `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack` }); } @@ -1637,8 +1637,8 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re }); await updateContentMapper(selectedOrganisation?.value, projectId, {... updatedState} ); setOtherContentType({ - label: 'Select content type from existing stack', - value: 'Select content type from existing stack' + label: `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`, + value: `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack` }); } @@ -1937,7 +1937,7 @@ const ContentMapper = forwardRef(({projectData}: ContentMapperComponentProps, re options={adjustedOption} width="440px" maxWidth="440px" - placeholder={otherContentType && 'Select content type from existing stack'} + placeholder={otherContentType && `Select ${isContentType ? 'Content Type' : 'Global Field'} from Existing Stack`} version="v2" />