From 6ed117817c414303ba0e25aa340d627e67997767 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 13 Mar 2024 16:37:35 +0530 Subject: [PATCH] formatting fixed and used filter --- .../src/utils/entries-helper.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 2f5e2edaee..619c7e4702 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -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); } } } @@ -577,8 +573,8 @@ 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 updateUids(str: string, match: string, uidMapper: Record) { + return str.replace(new RegExp(match, 'g'), (match: string) => uidMapper[match]); } function setDirtyTrue(jsonRteChild: any) { @@ -698,4 +694,4 @@ function restoreReferenceInJsonRTE( } return jsonRTE; -} \ No newline at end of file +}