Skip to content

Commit

Permalink
fix(siblings) Combine siblings data but remove duplicate data
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Collins authored and Chris Collins committed Jul 5, 2022
1 parent 86070d7 commit 9e6fb7e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions datahub-web-react/src/app/entity/shared/siblingUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import merge from 'deepmerge';
import { unionBy } from 'lodash';
import { Entity, MatchedField, Maybe, SiblingProperties } from '../../../types.generated';

function cleanHelper(obj, visited) {
Expand Down Expand Up @@ -41,6 +42,31 @@ const combineMerge = (target, source, options) => {
return destination;
};

const mergeTags = (destinationArray, sourceArray, _options) => {
return unionBy(destinationArray, sourceArray, 'tag.urn');
};

const mergeTerms = (destinationArray, sourceArray, _options) => {
return unionBy(destinationArray, sourceArray, 'term.urn');
};

const mergeAssertions = (destinationArray, sourceArray, _options) => {
return unionBy(destinationArray, sourceArray, 'urn');
};

function getArrayMergeFunction(key) {
switch (key) {
case 'tags':
return mergeTags;
case 'terms':
return mergeTerms;
case 'assertions':
return mergeAssertions;
default:
return undefined;
}
}

const customMerge = (isPrimary, key) => {
if (key === 'upstream' || key === 'downstream') {
return (_secondary, primary) => primary;
Expand All @@ -51,6 +77,7 @@ const customMerge = (isPrimary, key) => {
if (key === 'tags' || key === 'terms' || key === 'assertions') {
return (secondary, primary) => {
return merge(secondary, primary, {
arrayMerge: getArrayMergeFunction(key),
customMerge: customMerge.bind({}, isPrimary),
});
};
Expand Down

0 comments on commit 9e6fb7e

Please sign in to comment.