From 1c94309e98e652989b2c41b9188cb920f042f822 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 14 May 2024 19:55:07 +0530 Subject: [PATCH 1/2] fix: issue with import entries arising from compact library --- packages/contentstack-import/src/utils/asset-helper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index e8e8d0cd47..803b9846ac 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -434,6 +434,7 @@ function updateFileFields( for (let i = 0; i <= objekt.length; i++) updateFileFields(objekt[i], objekt, i, mappedAssetUids, matchedUids, unmatchedUids); - parent[pos] = _.compact(objekt); + // No need for _.compact() since you want to keep zero values + parent[pos] = _.filter(objekt, (value: any) => value !== undefined && value !== null); } } From ed729dcd0d7006d8b7376c82d8b3e935d9306e4e Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 15 May 2024 11:19:09 +0530 Subject: [PATCH 2/2] fix: typo --- .../src/utils/asset-helper.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index 803b9846ac..48bf419a5f 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -375,7 +375,7 @@ function findFileUrls(schema: any, _entry: any, assetUrls: any) { } function updateFileFields( - objekt: any, + object: any, parent: any, pos: any, mappedAssetUids: any, @@ -383,16 +383,16 @@ function updateFileFields( unmatchedUids: any, mappedAssetUrls?: any, ) { - if (_.isPlainObject(objekt) && _.has(objekt, 'filename') && _.has(objekt, 'uid')) { + if (_.isPlainObject(object) && _.has(object, 'filename') && _.has(object, 'uid')) { if (typeof pos !== 'undefined') { if (typeof pos === 'number' || typeof pos === 'string') { const replacer = () => { - if (mappedAssetUids.hasOwnProperty(objekt.uid)) { - parent[pos] = mappedAssetUids[objekt.uid]; - matchedUids.push(objekt.uid); + if (mappedAssetUids.hasOwnProperty(object.uid)) { + parent[pos] = mappedAssetUids[object.uid]; + matchedUids.push(object.uid); } else { parent[pos] = ''; - unmatchedUids.push(objekt.uid); + unmatchedUids.push(object.uid); } }; @@ -401,7 +401,7 @@ function updateFileFields( } if ( - objekt && + object && _.isObject(parent[pos]) && parent[pos].uid && parent[pos].url && @@ -417,24 +417,24 @@ function updateFileFields( parent = _.omit(parent, ['asset']); } - if (objekt.uid && mappedAssetUids && mappedAssetUids[objekt.uid]) { - objekt.uid = mappedAssetUids[objekt.uid]; + if (object.uid && mappedAssetUids && mappedAssetUids[object.uid]) { + object.uid = mappedAssetUids[object.uid]; } - if (objekt.url && mappedAssetUrls && mappedAssetUrls[objekt.url]) { - objekt.url = mappedAssetUrls[objekt.url]; + if (object.url && mappedAssetUrls && mappedAssetUrls[object.url]) { + object.url = mappedAssetUrls[object.url]; } } else { replacer(); } } } - } else if (_.isPlainObject(objekt)) { - for (let key in objekt) updateFileFields(objekt[key], objekt, key, mappedAssetUids, matchedUids, unmatchedUids); - } else if (_.isArray(objekt) && objekt.length) { - for (let i = 0; i <= objekt.length; i++) - updateFileFields(objekt[i], objekt, i, mappedAssetUids, matchedUids, unmatchedUids); + } else if (_.isPlainObject(object)) { + for (let key in object) updateFileFields(object[key], object, key, mappedAssetUids, matchedUids, unmatchedUids); + } else if (_.isArray(object) && object.length) { + for (let i = 0; i <= object.length; i++) + updateFileFields(object[i], object, i, mappedAssetUids, matchedUids, unmatchedUids); // No need for _.compact() since you want to keep zero values - parent[pos] = _.filter(objekt, (value: any) => value !== undefined && value !== null); + parent[pos] = _.filter(object, (value: any) => value !== undefined && value !== null); } }