From 7bab3a90ef73eb8c4924f9706bbc2ee144edb650 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 11 Mar 2024 17:20:00 +0530 Subject: [PATCH] optimisation --- .../src/utils/entries-helper.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 6740a59f42..2f5e2edaee 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -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); } } } @@ -584,6 +577,10 @@ export const restoreJsonRteEntryRefs = ( return entry; }; +function updateUids(str:string,match:string,uidMapper:Record) { + return str.replace(new RegExp(match, 'g'), (match:string) => uidMapper[match]) +} + function setDirtyTrue(jsonRteChild: any) { // also removing uids in this function if (jsonRteChild.type) {