Skip to content

Commit 5cf48d5

Browse files
committed
refactor:added code from conflicts
1 parent e08c2d2 commit 5cf48d5

File tree

10 files changed

+58
-26
lines changed

10 files changed

+58
-26
lines changed

api/src/utils/content-type-creator.utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const saveAppMapper = async ({ marketPlacePath, data, fileName }: any) => {
112112
}
113113
}
114114

115-
const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any) => {
115+
const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath, keyMapper }: any) => {
116116
switch (field?.contentstackFieldType) {
117117
case 'single_line_text': {
118118
return {
@@ -435,7 +435,7 @@ const convertToSchemaFormate = ({ field, advanced = true, marketPlacePath }: any
435435
return {
436436
data_type: "reference",
437437
display_name: field?.title,
438-
reference_to: field?.refrenceTo ?? [],
438+
reference_to: field?.refrenceTo?.map((item:string) => keyMapper?.[item] || item) ?? [],
439439
field_metadata: {
440440
ref_multiple: true,
441441
ref_multiple_content_types: true
@@ -728,7 +728,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
728728
uid: extractValue(element?.contentstackFieldUid, item?.contentstackFieldUid, '.'),
729729
title: extractValue(element?.contentstackField, item?.contentstackField, ' >')?.trim(),
730730
}
731-
const schema: any = convertToSchemaFormate({ field, marketPlacePath });
731+
const schema: any = convertToSchemaFormate({ field, marketPlacePath ,keyMapper});
732732
if (typeof schema === 'object' && Array.isArray(group?.schema) && element?.isDeleted === false) {
733733
group.schema.push(schema);
734734
}
@@ -741,7 +741,8 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
741741
title: item?.contentstackField,
742742
uid: item?.contentstackFieldUid
743743
},
744-
marketPlacePath
744+
marketPlacePath,
745+
keyMapper
745746
});
746747
if (dt && item?.isDeleted === false) {
747748
ct?.schema?.push(dt);

ui/src/components/ContentMapper/index.tsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
272272
const [otherCmsUid, setOtherCmsUid] = useState<string>(contentTypes?.[0]?.otherCmsUid);
273273

274274
const [active, setActive] = useState<number | null>(0);
275-
276275
const [searchContentType, setSearchContentType] = useState('');
277-
278276
const [rowIds, setRowIds] = useState<Record<string, boolean>>({});
279277
const [selectedEntries, setSelectedEntries] = useState<FieldMapType[]>([]);
280278
const [contentTypeSchema, setContentTypeSchema] = useState<ContentTypesSchema[] | undefined>([]);
@@ -365,6 +363,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
365363

366364
if (newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || ''] === otherContentType?.id) {
367365
setIsAllCheck(false);
366+
368367
tableData?.forEach((row) => {
369368
contentTypeSchema?.forEach((schema) => {
370369

@@ -679,6 +678,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
679678
setItemStatusMap({ ...itemStatusMap });
680679

681680
const validTableData = data?.fieldMapping?.filter((field: FieldMapType) => field?.otherCmsType !== undefined);
681+
682682
setIsAllCheck(true);
683683
setTableData(validTableData ?? []);
684684
setSelectedEntries(validTableData ?? []);
@@ -726,6 +726,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
726726
setTotalCounts([...tableData, ...validTableData ?? tableData]?.length);
727727
setIsLoading(false);
728728
setIsAllCheck(true);
729+
729730
} catch (error) {
730731
console.error('loadMoreItems -> error', error);
731732
}
@@ -898,6 +899,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
898899

899900
const handleSelectedEntries = (singleSelectedRowIds: string[]) => {
900901
const selectedObj: UidMap = {};
902+
901903
setIsAllCheck(false);
902904
singleSelectedRowIds?.forEach((uid: string) => {
903905
const isId = selectedEntries?.some((item) => item?.id === uid);
@@ -1023,6 +1025,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
10231025

10241026
const handleDropDownChange = (value: FieldTypes) => {
10251027
(value?.id !== otherContentType?.id) && setsCsCTypeUpdated(true);
1028+
10261029
setIsAllCheck(false);
10271030
setOtherContentType(value);
10281031
};
@@ -1437,7 +1440,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
14371440
const fieldTypeToMatch = Fields[data?.backupFieldType as keyof Mapping]?.type;
14381441
//check if UID of souce field is matching to exsting content type field UID
14391442
for (const value of contentTypeSchema) {
1440-
if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type) {
1443+
if (data?.uid === value?.uid && data?.backupFieldType === value?.data_type && fieldTypeToMatch) {
14411444
OptionsForRow.push({ label: value?.display_name, value, isDisabled: false });
14421445
break;
14431446
}
@@ -1505,7 +1508,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
15051508
if (!hasMatchingEntry) {
15061509
updatedExstingField = {
15071510
...updatedExstingField,
1508-
[data?.uid]: { label: newLabel, value: newvalue }
1511+
[data?.backupFieldUid]: { label: newLabel, value: newvalue }
15091512
};
15101513
existingField[data?.backupFieldUid] = { label: newLabel, value: newvalue }
15111514
}
@@ -1579,12 +1582,13 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
15791582
...option,
15801583
isDisabled: selectedOptions?.includes?.(option?.label ?? '')
15811584
}));
1582-
15831585
return (
15841586
<div className="table-row">
15851587
<div className="select">
15861588
<Select
1587-
value={(OptionsForRow?.length === 0 || existingField?.[data?.backupFieldUid]?.label === undefined) ? OptionValue : existingField[data?.backupFieldUid]}
1589+
value={(OptionsForRow?.length === 0 || (data?.backupFieldType !== existingField[data?.backupFieldUid]?.value?.data_type || existingField?.[data?.backupFieldUid]?.label === undefined)) ? OptionValue :
1590+
1591+
existingField[data?.backupFieldUid]}
15881592
onChange={(selectedOption: FieldTypes) => {
15891593
if (OptionsForRow?.length === 0) {
15901594
handleValueChange(selectedOption, data?.uid, data?.backupFieldUid)
@@ -1595,7 +1599,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
15951599
placeholder="Select Field"
15961600
version={'v2'}
15971601
maxWidth="290px"
1598-
isClearable={selectedOptions?.includes?.(existingField?.[data?.backupFieldUid]?.label ?? '')}
1602+
isClearable={data?.backupFieldType === existingField[data?.backupFieldUid]?.value?.data_type && selectedOptions?.includes?.(existingField?.[data?.backupFieldUid]?.label ?? '')}
15991603
options={adjustedOptions}
16001604
isDisabled={OptionValue?.isDisabled || newMigrationData?.project_current_step > 4}
16011605
menuPlacement="auto"
@@ -1719,10 +1723,19 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
17191723
const savedCT = filteredContentTypes?.map?.(ct =>
17201724
ct?.id === data?.data?.updatedContentType?.id ? { ...ct, status: data?.data?.updatedContentType?.status } : ct
17211725
);
1726+
let filteredCT = savedCT;
1727+
if (!isEmptyString(activeFilter)) {
1728+
filteredCT = savedCT?.filter((ct) =>
1729+
CONTENT_MAPPING_STATUS?.[ct?.status] === activeFilter
1730+
);
1731+
}
1732+
const savedContentTypes = contentTypes?.map?.(ct =>
1733+
ct?.id === selectedContentType?.id ? { ...ct, status: data?.data?.status } : ct
1734+
);
17221735

1723-
setFilteredContentTypes(savedCT);
1724-
setContentTypes(savedCT);
1725-
1736+
setFilteredContentTypes(filteredCT);
1737+
setContentTypes(savedContentTypes);
1738+
setCount(filteredCT?.length);
17261739
try {
17271740
otherContentType?.id && await updateContentMapper(orgId, projectID, { ...contentTypeMapped, [selectedContentType?.contentstackUid]: otherContentType?.id });
17281741
} catch (err) {
@@ -2181,6 +2194,7 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
21812194
(e?.target as HTMLElement)?.closest('li')?.classList?.add('active-filter');
21822195

21832196
const filteredCT = contentTypes?.filter((ct) => { return CONTENT_MAPPING_STATUS[ct?.status] === value });
2197+
console.info('content types --> ',filteredCT)
21842198
if (value !== 'All') {
21852199
setFilteredContentTypes(filteredCT);
21862200
setCount(filteredCT?.length);
@@ -2450,7 +2464,8 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
24502464
...newMigrationData?.legacy_cms,
24512465
uploadedFile: {
24522466
...newMigrationData?.legacy_cms?.uploadedFile,
2453-
reValidate: true
2467+
reValidate: true,
2468+
buttonClicked: true,
24542469
}
24552470
}
24562471
}

ui/src/components/DestinationStack/Actions/LoadStacks.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ const LoadStacks = (props: LoadFileFormatProps) => {
376376
></Icon>
377377
</Tooltip>
378378
</div>
379+
379380
<LanguageMapper
380381
uid={selectedStack?.uid ?? ''}
381382
stack={newMigrationData?.destination_stack?.selectedStack ?? DEFAULT_DROPDOWN} />

ui/src/components/LegacyCms/Actions/LoadUploadFile.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface UploadState {
3535
fileDetails?: FileDetails;
3636
}
3737

38+
3839
const FileComponent = ({ fileDetails }: Props) => {
3940
return (
4041
<div>
@@ -122,6 +123,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
122123
legacy_cms: {
123124
...newMigrationDataRef?.current?.legacy_cms,
124125
uploadedFile: {
126+
...newMigrationDataRef?.current?.legacy_cms?.uploadedFile,
125127
name: data?.file_details?.localPath || '',
126128
url: data?.file_details?.localPath,
127129
validation: data?.message,
@@ -186,6 +188,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
186188
}, 1000);
187189

188190
setIsLoading(false);
191+
189192
saveStateToLocalStorage(
190193
{
191194
isLoading,
@@ -287,6 +290,7 @@ const LoadUploadFile = (props: LoadUploadFileProps) => {
287290

288291
useEffect(() => {
289292
const savedState = getStateFromLocalStorage(projectId);
293+
290294
if (savedState) {
291295
setIsLoading(savedState.isLoading);
292296
setIsConfigLoading(savedState.isConfigLoading);

ui/src/components/MigrationFlowHeader/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ const MigrationFlowHeader = ({
8787

8888
const isProjectStatusThreeAndMapperNotGenerated =
8989
params?.stepId === '1' &&
90-
newMigrationData?.legacy_cms?.projectStatus === 3
90+
newMigrationData?.legacy_cms?.projectStatus === 3 &&
91+
newMigrationData?.legacy_cms?.uploadedFile?.buttonClicked
9192

9293
const isStepInvalid =
9394
params?.stepId &&
9495
params?.stepId <= '2' &&
95-
newMigrationData?.project_current_step?.toString() !== params?.stepId;
96+
newMigrationData?.project_current_step?.toString() !== params?.stepId &&
97+
parseInt(params?.stepId) < newMigrationData?.project_current_step;
9698

9799
const isExecutionStarted =
98100
finalExecutionStarted ||
@@ -126,10 +128,9 @@ const MigrationFlowHeader = ({
126128
disabled={
127129
isProjectStatusThreeAndMapperNotGenerated ?
128130
isFileValidated :
129-
isPreviousStepDisabled ||
130-
isStep4AndNotMigrated ||
131-
isStepInvalid ||
132-
isExecutionStarted ||
131+
isStep4AndNotMigrated ||
132+
isStepInvalid ||
133+
isExecutionStarted ||
133134
destinationStackMigrated
134135
}
135136
>

ui/src/context/app/app.interface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export interface IFile {
6868
file_details?: FileDetails;
6969
isValidated: boolean;
7070
reValidate: boolean;
71-
cmsType: string
71+
cmsType: string;
72+
buttonClicked:boolean
7273
}
7374

7475
export interface ICMSType extends ICardType {
@@ -318,6 +319,7 @@ export const DEFAULT_FILE: IFile = {
318319
isValidated: false,
319320
reValidate: false,
320321
cmsType: '',
322+
buttonClicked: false
321323
};
322324

323325
export const DEFAULT_CMS_TYPE: ICMSType = {

ui/src/hooks/useWarnOnrefresh.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export function useWarnOnRefresh(isUnsaved : boolean){
1515
window.removeEventListener('beforeunload', handleBeforeUnload);
1616
};
1717
}, [isUnsaved]);
18+
1819
}

ui/src/pages/Migration/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ type LocalesType = {
7474
[key: string]: any
7575
}
7676

77+
/**
78+
* Migration component to handle the migration process
79+
* It includes steps like selecting legacy CMS, configuring destination stack,
80+
* mapping content fields, running test migration, and executing final migration.
81+
*/
7782
const Migration = () => {
7883
const params: Params<string> = useParams();
7984
const { projectId = '' } = useParams();
@@ -247,6 +252,7 @@ const Migration = () => {
247252
// funcrion to form upload object from config response
248253
const getFileInfo = (data: FileDetails) => {
249254
const newMigrationDataObj = {
255+
...newMigrationData?.legacy_cms?.uploadedFile,
250256
name: data?.localPath,
251257
url: data?.localPath,
252258
isValidated: false,
@@ -353,7 +359,8 @@ const Migration = () => {
353359
isLocalPath: projectData?.legacy_cms?.is_localPath
354360
},
355361
isValidated: projectData?.legacy_cms?.is_fileValid,
356-
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate
362+
reValidate: newMigrationData?.legacy_cms?.uploadedFile?.reValidate,
363+
buttonClicked: newMigrationData?.legacy_cms?.uploadedFile?.buttonClicked ? true : false,
357364
} : uploadObj,
358365
isFileFormatCheckboxChecked: true,
359366
isRestictedKeywordCheckboxChecked: true,

upload-api/migration-contentful/libs/contentTypeMapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const uidCorrector = (uid, affix) => {
2727
newId = uid?.replace?.(uid, `${affix}_${uid}`);
2828
newId = newId?.replace?.(/[^a-zA-Z0-9]+/g, '_');
2929
}
30-
return newId.replace(/([A-Z])/g, (match) => `_${match?.toLowerCase?.()}`);
30+
return newId.replace(/([A-Z])/g, (match) => `${match?.toLowerCase?.()}`);
3131
};
3232

3333
/**
@@ -319,7 +319,7 @@ const contentTypeMapper = (data, entries) => {
319319
}
320320
});
321321
}
322-
console.info('contentTypeRefs', contentTypeRefs, contentTypeUid);
322+
323323
return contentTypeRefs;
324324

325325
}

upload-api/migration-contentful/libs/createInitialMapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const uidCorrector = (uid, prefix) => {
4040
newId = uid.replace(uid, `${prefix}_${uid}`);
4141
newId = newId.replace(/[^a-zA-Z0-9]+/g, '_');
4242
}
43-
return newId.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`);
43+
return newId.replace(/([A-Z])/g, (match) => `${match.toLowerCase()}`);
4444
};
4545

4646
/**

0 commit comments

Comments
 (0)