From 5cf48d5f54e18e7acac43ab18524f8506a730c59 Mon Sep 17 00:00:00 2001 From: AishDani Date: Thu, 31 Jul 2025 14:57:11 +0530 Subject: [PATCH 1/2] refactor:added code from conflicts --- api/src/utils/content-type-creator.utils.ts | 9 +++-- ui/src/components/ContentMapper/index.tsx | 37 +++++++++++++------ .../DestinationStack/Actions/LoadStacks.tsx | 1 + .../LegacyCms/Actions/LoadUploadFile.tsx | 4 ++ .../components/MigrationFlowHeader/index.tsx | 13 ++++--- ui/src/context/app/app.interface.ts | 4 +- ui/src/hooks/useWarnOnrefresh.tsx | 1 + ui/src/pages/Migration/index.tsx | 9 ++++- .../libs/contentTypeMapper.js | 4 +- .../libs/createInitialMapper.js | 2 +- 10 files changed, 58 insertions(+), 26 deletions(-) diff --git a/api/src/utils/content-type-creator.utils.ts b/api/src/utils/content-type-creator.utils.ts index e00b14c14..49e25a950 100644 --- a/api/src/utils/content-type-creator.utils.ts +++ b/api/src/utils/content-type-creator.utils.ts @@ -112,7 +112,7 @@ const saveAppMapper = async ({ marketPlacePath, data, fileName }: any) => { } } -const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any) => { +const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath, keyMapper }: any) => { switch (field?.contentstackFieldType) { case 'single_line_text': { return { @@ -435,7 +435,7 @@ const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any return { data_type: "reference", display_name: field?.title, - reference_to: field?.refrenceTo ?? [], + reference_to: field?.refrenceTo?.map((item:string) => keyMapper?.[item] || item) ?? [], field_metadata: { ref_multiple: true, ref_multiple_content_types: true @@ -728,7 +728,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project uid: extractValue(element?.contentstackFieldUid, item?.contentstackFieldUid, '.'), title: extractValue(element?.contentstackField, item?.contentstackField, ' >')?.trim(), } - const schema: any = convertToSchemaFormate({ field, marketPlacePath }); + const schema: any = convertToSchemaFormate({ field, marketPlacePath ,keyMapper}); if (typeof schema === 'object' && Array.isArray(group?.schema) && element?.isDeleted === false) { group.schema.push(schema); } @@ -741,7 +741,8 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project title: item?.contentstackField, uid: item?.contentstackFieldUid }, - marketPlacePath + marketPlacePath, + keyMapper }); if (dt && item?.isDeleted === false) { ct?.schema?.push(dt); diff --git a/ui/src/components/ContentMapper/index.tsx b/ui/src/components/ContentMapper/index.tsx index 6113fea8b..4cc6d86d1 100644 --- a/ui/src/components/ContentMapper/index.tsx +++ b/ui/src/components/ContentMapper/index.tsx @@ -272,9 +272,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: const [otherCmsUid, setOtherCmsUid] = useState(contentTypes?.[0]?.otherCmsUid); const [active, setActive] = useState(0); - const [searchContentType, setSearchContentType] = useState(''); - const [rowIds, setRowIds] = useState>({}); const [selectedEntries, setSelectedEntries] = useState([]); const [contentTypeSchema, setContentTypeSchema] = useState([]); @@ -365,6 +363,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) { setIsAllCheck(false); + tableData?.forEach((row) => { contentTypeSchema?.forEach((schema) => { @@ -679,6 +678,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: setItemStatusMap({ ...itemStatusMap }); const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined); + setIsAllCheck(true); setTableData(validTableData ?? []); setSelectedEntries(validTableData ?? []); @@ -726,6 +726,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: setTotalCounts([...tableData, ...validTableData ?? tableData]?.length); setIsLoading(false); setIsAllCheck(true); + } catch (error) { console.error('loadMoreItems -> error', error); } @@ -898,6 +899,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: const handleSelectedEntries = (singleSelectedRowIds: string[]) => { const selectedObj: UidMap = {}; + setIsAllCheck(false); singleSelectedRowIds?.forEach((uid: string) => { const isId = selectedEntries?.some((item) => item?.id === uid); @@ -1023,6 +1025,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: const handleDropDownChange = (value: FieldTypes) => { (value?.id !== otherContentType?.id) && setsCsCTypeUpdated(true); + setIsAllCheck(false); setOtherContentType(value); }; @@ -1437,7 +1440,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: const fieldTypeToMatch = Fields[data?.backupFieldType as keyof Mapping]?.type; //check if UID of souce field is matching to exsting content type field UID for (const value of contentTypeSchema) { - if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type) { + if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type && fieldTypeToMatch) { OptionsForRow.push({ label: value?.display_name, value, isDisabled: false }); break; } @@ -1505,7 +1508,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: if (!hasMatchingEntry) { updatedExstingField = { ...updatedExstingField, - [data?.uid]: { label: newLabel, value: newvalue } + [data?.backupFieldUid]: { label: newLabel, value: newvalue } }; existingField[data?.backupFieldUid] = { label: newLabel, value: newvalue } } @@ -1579,12 +1582,13 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref: ...option, isDisabled: selectedOptions?.includes?.(option?.label ?? '') })); - return (