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(siblings) Combine siblings data but remove duplicate data #5337

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
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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need assertion.urn or something here, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope! the assertions array simply returns assertion objects with the urn exposed right there. on the other hand, the tags and terms array both have the shape: terms: [{term: {urn ...}}, ...]

};

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause any runtime issues when we add new arrays to our objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sir - originally we weren't even setting arrayMerge which effectively we were setting arrayMerge: undefined. So it doesn't break anything, just defaults to how we were doing it before this fix. If we add more arrays to our objects that we need to remove duplicates to, we will need to add another custom array merge function like we have for these 3 fields so far.

}
}

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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

customMerge: customMerge.bind({}, isPrimary),
});
};
Expand Down