Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue with import entries arising from compact library #1409

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions packages/contentstack-import/src/utils/asset-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,24 +375,24 @@ function findFileUrls(schema: any, _entry: any, assetUrls: any) {
}

function updateFileFields(
objekt: any,
object: any,
parent: any,
pos: any,
mappedAssetUids: any,
matchedUids: any,
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);
}
};

Expand All @@ -401,7 +401,7 @@ function updateFileFields(
}

if (
objekt &&
object &&
_.isObject(parent[pos]) &&
parent[pos].uid &&
parent[pos].url &&
Expand All @@ -417,23 +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);

parent[pos] = _.compact(objekt);
// No need for _.compact() since you want to keep zero values
parent[pos] = _.filter(object, (value: any) => value !== undefined && value !== null);
}
}
Loading