Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ ignoreconfig:
ignore_detectors:
- Base64Detector

- filename: ui/src/components/ContentMapper/index.tsx
checksum: 938aaf193e830bade84f9d8d385e55942269c3f2e7be82939994d64d76df3fa6

version: "1.0"
14 changes: 13 additions & 1 deletion api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ const startMigration = async (req: Request): Promise<any> => {
.findIndex({ id: projectId })
.value();
if (index > -1) {
ProjectModelLowdb.update((data: any) => {
await ProjectModelLowdb.update((data: any) => {
data.projects[index].isMigrationStarted = true;
});
}
Expand All @@ -682,6 +682,18 @@ const startMigration = async (req: Request): Promise<any> => {
projectId,
`${project?.destination_stack_id}.log`
);
const message = getLogMessage(
'start Migration',
'Starting Migration...',
{}
);
await customLogger(
projectId,
project?.destination_stack_id,
'info',
message
);

await setLogFilePath(loggerPath);

const copyLogsToStack = async (
Expand Down
11 changes: 11 additions & 0 deletions api/src/services/wordpress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,17 @@ async function extractPosts( packagePath: string, destinationStackId: string, pr
// Process the current chunk
const chunkPostData = await processChunkData(chunkData, filename, isLastChunk, contenttype);
postdataCombined = { ...postdataCombined, ...chunkPostData };

const seenTitles = new Map();
Object?.entries(postdataCombined)?.forEach(([uid, item]:any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object?.entries?.(postdataCombined)?.forEach?.(([uid, item]:any)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const originalTitle = item?.title;

if (seenTitles.has(originalTitle)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

item.title = `${originalTitle} - ${item?.uid}`;
}
seenTitles.set(item?.title, true);
});

const message = getLogMessage(
srcFunc,
`${filename.split(".").slice(0, -1).join(".")} has been successfully transformed.`,
Expand Down
130 changes: 97 additions & 33 deletions api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,19 @@ const arrangGroups = ({ schema, newStack }: any) => {
schema?.forEach((item: any) => {
if (item?.contentstackFieldType === 'group') {
const groupSchema: any = { ...item, schema: [] }
if (item?.contentstackFieldUid?.includes('.')) {
const parts = item?.contentstackFieldUid?.split('.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we are making changes in this file @AishDani

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any group from the source CMS is mapped to a nested group present in Contentstack, then we are modifying its Contentstack UID with all nested groups by adding a dot in between. In this function we are arranging schema of group so keeping only nested group uid to source group which will help to find match in Contentstack schema.

groupSchema.contentstackFieldUid = parts?.[parts?.length - 1];
}
schema?.forEach((et: any) => {
if (et?.contentstackFieldUid?.includes(`${item?.contentstackFieldUid}.`) ||
(newStack === false && et?.uid?.includes(`${item?.uid}.`))) {
const target = groupSchema?.contentstackFieldUid;
const index = et?.contentstackFieldUid?.indexOf(target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

et?.contentstackFieldUid?.indexOf?.(target)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if (index > 0) {
et.contentstackFieldUid = et?.contentstackFieldUid?.substring(index);
}
groupSchema?.schema?.push(et);
}
})
Expand Down Expand Up @@ -112,7 +122,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 {
Expand Down Expand Up @@ -435,7 +445,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
Expand Down Expand Up @@ -654,45 +664,98 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
}
}

const mergeArrays = async (a: any[], b: any[]) => {
for await (const fieldGp of b) {
const exists = a.some(fld =>
fld?.uid === fieldGp?.uid &&
fld?.data_type === fieldGp?.data_type
const mergeArrays = (a: any[], b: any[]): any[] => {
const result = [...a];

for (const field of b) {
const exists = result?.some(f =>
f?.uid === field?.uid &&
f?.data_type === field?.data_type
);
if (!exists) {
a.push(fieldGp);
result?.push(field);
}
}
return a;

return result;
};

const mergeFields = async (schema1: any[], schema2: any[]): Promise<any[]> => {
const result: any[] = [];

for (const field2 of schema2) {
if (field2?.data_type === 'group') {
const machingGroup = findGroupByUid(schema1, field2?.uid);
if(machingGroup){
const schema = await mergeArrays(machingGroup?.schema ?? [],field2?.schema ?? [] );
result?.push({
...field2,
schema: schema
});
}
else{
result?.push({
...field2,
schema: await mergeFields(schema1, field2?.schema)
})
}
}
else{
const exists = schema1?.find(
(fld) =>
fld?.uid === field2?.uid &&
fld?.data_type === field2?.data_type
);
result?.push({
...field2
});

}

}

for (const field1 of schema1) {
const isMatched = schema2?.some(
(field2) =>
field1?.uid === field2?.uid &&
field1?.data_type === field2?.data_type
);

if (!isMatched) {
result?.push(field1);
}
}

return result;
}


const findGroupByUid = (
schema: any[],
uid: string,
excludeRef: any = null
): any | undefined => {
for (const field of schema) {
if (field?.data_type === 'group') {
if (field?.uid === uid && field !== excludeRef) return field;
const nested = findGroupByUid(field?.schema ?? [], uid, excludeRef);
if (nested) return nested;
}
}
return undefined;
};

const mergeTwoCts = async (ct: any, mergeCts: any) => {
const ctData: any = {
...ct,
const merged :any = {
title: mergeCts?.title,
uid: mergeCts?.uid,
options: {
"singleton": false,
}
}
for await (const field of ctData?.schema ?? []) {
if (field?.data_type === 'group') {
const currentGroup = mergeCts?.schema?.find((grp: any) => grp?.uid === field?.uid &&
grp?.data_type === 'group');
const group = [];
for await (const fieldGp of currentGroup?.schema ?? []) {
const fieldNst = field?.schema?.find((fld: any) => fld?.uid === fieldGp?.uid &&
fld?.data_type === fieldGp?.data_type);
if (fieldNst === undefined) {
group?.push(fieldGp);
}
}
field.schema = [...field?.schema ?? [], ...group];
}
}
ctData.schema = await mergeArrays(ctData?.schema, mergeCts?.schema) ?? [];
return ctData;
},
schema: await mergeFields(ct?.schema ?? [], mergeCts?.schema ?? [])
};

return merged;
}

export const contenTypeMaker = async ({ contentType, destinationStackId, projectId, newStack, keyMapper, region, user_id }: any) => {
Expand All @@ -717,7 +780,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
"display_name": item?.contentstackField,
"field_metadata": {},
"schema": [],
"uid": item?.contentstackFieldUid,
"uid": item?.contentstackFieldUid?.replace(/\./g, '_'),
"multiple": false,
"mandatory": false,
"unique": false
Expand All @@ -728,7 +791,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);
}
Expand All @@ -741,7 +804,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);
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/field-attacher.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const fieldAttacher = async ({ projectId, orgId, destinationStackId, regi
contentType.fieldMapping = contentType?.fieldMapping?.map((fieldUid: any) => {
const field = FieldMapperModel.chain
.get("field_mapper")
.find({ id: fieldUid, projectId: projectId })
.find({ id: fieldUid, projectId: projectId , contentTypeId: contentId})
.value()
return field;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface SchemaProps {
* @param value - The advanced settings.
* @param checkBoxChanged - Indicates whether the checkbox has changed.
*/
updateFieldSettings: (rowId: string, value: Advanced, checkBoxChanged: boolean) => void;
updateFieldSettings: (rowId: string, value: Advanced, checkBoxChanged: boolean, rowContentstackFieldUid: string) => void;

/**
* Indicates whether the field is localized.
Expand Down
19 changes: 13 additions & 6 deletions ui/src/components/AdvancePropertise/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ const AdvancePropertise = (props: SchemaProps) => {
title: currentToggleStates?.title,
url: currentToggleStates?.url
},
checkBoxChanged
checkBoxChanged,
props?.data?.contentstackFieldUid

);
};

Expand Down Expand Up @@ -189,7 +191,8 @@ const AdvancePropertise = (props: SchemaProps) => {
title: currentToggleStates?.title,
url: currentToggleStates?.url
},
checkBoxChanged
checkBoxChanged,
props?.data?.contentstackFieldUid
);
};

Expand All @@ -215,7 +218,8 @@ const AdvancePropertise = (props: SchemaProps) => {
embedObject: currentToggleStates?.embedObject,
embedObjects: embedObjectsLabels
},
true
true,
props?.data?.contentstackFieldUid
);
};

Expand Down Expand Up @@ -251,7 +255,8 @@ const AdvancePropertise = (props: SchemaProps) => {
embedObjects: embedObjectsLabels,
options: options
},
true
true,
props?.data?.contentstackFieldUid
);
};
const handleRemoveDefalutValue = (index: number) => {
Expand Down Expand Up @@ -280,7 +285,8 @@ const AdvancePropertise = (props: SchemaProps) => {
embedObjects: embedObjectsLabels,
options: options
},
true
true,
props?.data?.contentstackFieldUid
);
};

Expand Down Expand Up @@ -583,7 +589,8 @@ const AdvancePropertise = (props: SchemaProps) => {
validationRegex: toggleStates?.validationRegex ?? '',
embedObjects: embedObject
},
true
true,
props?.data?.contentstackFieldUid
);
}}
options={option}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ export interface ModifiedField {
backupFieldType: string;
parentId: string;
uid: string;
_canSelect?: boolean;
}
4 changes: 4 additions & 0 deletions ui/src/components/ContentMapper/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,7 @@ div .table-row {
font-size: $size-font-large;
font-weight: $font-weight-semi-bold;
}
.filterButton-color{
color: $color-brand-primary-base;
font-weight: $font-weight-bold;
}
Loading
Loading