Skip to content

Commit

Permalink
feat(diff-using-parent-fields): use parent field values from same lay…
Browse files Browse the repository at this point in the history
…er when deduplicating
  • Loading branch information
missinglink committed Aug 17, 2021
1 parent b6ed89d commit 8984c03
Show file tree
Hide file tree
Showing 4 changed files with 2,208 additions and 2 deletions.
24 changes: 22 additions & 2 deletions helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,37 @@ function isNameDifferent(item1, item2, requestLanguage){
// iterate over all the languages in item2, comparing them to the
// 'default' name of item1 and also against the language requested by the user.
for( let lang in names2 ){
if (!names2.hasOwnProperty(lang)) { continue; } // do not iterate over inherited properties
if( !isPropertyDifferent({[lang]: names1.default}, names2, lang) ){ return false; }
if( requestLanguage && !isPropertyDifferent({[lang]: names1[requestLanguage]}, names2, lang) ){ return false; }
}

// iterate over all the languages in item1, comparing them to the
// 'default' name of item2 and also against the language requested by the user.
// as above, but inverse
for( let lang in names1 ){
if (!names1.hasOwnProperty(lang)) { continue; } // do not iterate over inherited properties
if( !isPropertyDifferent({[lang]: names2.default}, names1, lang) ){ return false; }
if( requestLanguage && !isPropertyDifferent({[lang]: names2[requestLanguage]}, names1, lang) ){ return false; }
}

// iterate over the parent field values from the same layer as item2 itself and compare them to
// the 'default' name of item1 and also against the language requested by the user.
// note: this is helpful when the item 'source' is different from the parent 'source'
// at the same level in the hierarchy and the labels assigned differ.
let layer2 = _.get(item2, 'layer');
let parent2 = _.get(item2, 'parent');
for (let name of _.castArray(_.get(parent2, layer2, []))) {
if (!isPropertyDifferent({ default: name }, names1, 'default')) { return false; }
if (requestLanguage && !isPropertyDifferent({ [requestLanguage]: name }, names1, requestLanguage)) { return false; }
}

// as above, but inverse
let layer1 = _.get(item1, 'layer');
let parent1 = _.get(item1, 'parent');
for (let name of _.castArray(_.get(parent1, layer1, []))) {
if (!isPropertyDifferent({ default: name }, names2, 'default')) { return false; }
if (requestLanguage && !isPropertyDifferent({ [requestLanguage]: name }, names2, requestLanguage)) { return false; }
}

return true;
}

Expand Down
Loading

0 comments on commit 8984c03

Please sign in to comment.