Skip to content

Commit

Permalink
formatting fixed and used filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Mar 13, 2024
1 parent 7bab3a9 commit 6ed1178
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/contentstack-import/src/utils/entries-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,20 +553,16 @@ export const restoreJsonRteEntryRefs = (
case 'text': {
if (entry[element.uid] && element.field_metadata.rich_text_type) {
entry[element.uid] = sourceStackEntry[element.uid];
const matches: string[] = [];
Object.keys(uidMapper).forEach((uid) => {
if (sourceStackEntry[element.uid].indexOf(uid) !== -1) {
matches.push(uid);
}
const matches = Object.keys(uidMapper).filter((uid) => {
if (sourceStackEntry[element.uid].indexOf(uid) !== -1) return uid;
});

if (element.multiple && Array.isArray(entry[element.uid])) {
for (let i = 0; i < matches.length; i++) {
entry[element.uid] = entry[element.uid].map((el:string) => updateUids(el,matches[i],uidMapper));
entry[element.uid] = entry[element.uid].map((el: string) => updateUids(el, matches[i], uidMapper));
}
} else {
for (let i = 0; i < matches.length; i++) {
entry[element.uid] = updateUids(entry[element.uid],matches[i],uidMapper);
entry[element.uid] = updateUids(entry[element.uid], matches[i], uidMapper);
}
}
}
Expand All @@ -577,8 +573,8 @@ export const restoreJsonRteEntryRefs = (
return entry;
};

function updateUids(str:string,match:string,uidMapper:Record<string, string>) {
return str.replace(new RegExp(match, 'g'), (match:string) => uidMapper[match])
function updateUids(str: string, match: string, uidMapper: Record<string, string>) {
return str.replace(new RegExp(match, 'g'), (match: string) => uidMapper[match]);
}

function setDirtyTrue(jsonRteChild: any) {
Expand Down Expand Up @@ -698,4 +694,4 @@ function restoreReferenceInJsonRTE(
}

return jsonRTE;
}
}

0 comments on commit 6ed1178

Please sign in to comment.