From 02c7dd9c3a96bef5fb4d2535a4af191e80b6bc5b Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 5 Jul 2022 12:49:10 -0500 Subject: [PATCH] fix(siblings) Combine siblings data but remove duplicate data (#5337) --- .../src/app/entity/shared/siblingUtils.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/datahub-web-react/src/app/entity/shared/siblingUtils.ts b/datahub-web-react/src/app/entity/shared/siblingUtils.ts index f280716922d896..d94f3fbda6e352 100644 --- a/datahub-web-react/src/app/entity/shared/siblingUtils.ts +++ b/datahub-web-react/src/app/entity/shared/siblingUtils.ts @@ -1,4 +1,5 @@ import merge from 'deepmerge'; +import { unionBy } from 'lodash'; import { Entity, MatchedField, Maybe, SiblingProperties } from '../../../types.generated'; function cleanHelper(obj, visited) { @@ -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; @@ -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), }); };