Skip to content

Commit

Permalink
optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Mar 11, 2024
1 parent b5459fa commit 7bab3a9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions packages/contentstack-import/src/utils/entries-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,11 @@ export const restoreJsonRteEntryRefs = (

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) => {
while (el.indexOf(matches[i]) !== -1) {
el = el.replace(matches[i], uidMapper[matches[i]]);
}
return el;
});
entry[element.uid] = entry[element.uid].map((el:string) => updateUids(el,matches[i],uidMapper));
}
} else {
for (let i = 0; i < matches.length; i++) {
while (entry[element.uid].indexOf(matches[i]) !== -1) {
entry[element.uid] = entry[element.uid].replace(matches[i], uidMapper[matches[i]]);
}
entry[element.uid] = updateUids(entry[element.uid],matches[i],uidMapper);
}
}
}
Expand All @@ -584,6 +577,10 @@ 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 setDirtyTrue(jsonRteChild: any) {
// also removing uids in this function
if (jsonRteChild.type) {
Expand Down

0 comments on commit 7bab3a9

Please sign in to comment.