Skip to content

Commit 44affd7

Browse files
fix(ui) Fix merging siblings schema with mix of v1 & v2 fields (#11837)
1 parent 2d155cc commit 44affd7

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

datahub-web-react/src/app/entity/shared/siblingUtils.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as QueryString from 'query-string';
55
import { Dataset, Entity, Maybe, SiblingProperties } from '../../../types.generated';
66
import { GenericEntityProperties } from './types';
77
import { useIsShowSeparateSiblingsEnabled } from '../../useAppConfig';
8+
import { downgradeV2FieldPath } from '../dataset/profile/schema/utils/utils';
89

910
export function stripSiblingsFromEntity(entity: any) {
1011
return {
@@ -55,16 +56,30 @@ const combineMerge = (target, source, options) => {
5556
return destination;
5657
};
5758

58-
function convertObjectKeysToLowercase(object: Record<string, unknown>) {
59-
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key.toLowerCase(), value]));
59+
// this function is responsible for normalizing object keys to make sure merging on key matches keys appropriately
60+
function normalizeObjectKeys(object: Record<string, unknown>, isSchemaField = false) {
61+
return Object.fromEntries(
62+
Object.entries(object).map(([key, value]) => {
63+
let normalizedKey = key.toLowerCase();
64+
if (isSchemaField) {
65+
normalizedKey = downgradeV2FieldPath(normalizedKey) || normalizedKey;
66+
}
67+
return [normalizedKey, value];
68+
}),
69+
);
6070
}
6171

6272
// use when you want to merge an array of objects by key in the object as opposed to by index of array
63-
const mergeArrayOfObjectsByKey = (destinationArray: any[], sourceArray: any[], key: string) => {
64-
const destination = convertObjectKeysToLowercase(keyBy(destinationArray, key));
65-
const source = convertObjectKeysToLowercase(keyBy(sourceArray, key));
73+
const mergeArrayOfObjectsByKey = (destinationArray: any[], sourceArray: any[], key: string, isSchemaField = false) => {
74+
const destination = normalizeObjectKeys(keyBy(destinationArray, key), isSchemaField);
75+
const source = normalizeObjectKeys(keyBy(sourceArray, key), isSchemaField);
6676

67-
return values(merge(destination, source));
77+
return values(
78+
merge(destination, source, {
79+
arrayMerge: combineMerge,
80+
customMerge,
81+
}),
82+
);
6883
};
6984

7085
const mergeTags = (destinationArray, sourceArray, _options) => {
@@ -88,7 +103,7 @@ const mergeOwners = (destinationArray, sourceArray, _options) => {
88103
};
89104

90105
const mergeFields = (destinationArray, sourceArray, _options) => {
91-
return mergeArrayOfObjectsByKey(destinationArray, sourceArray, 'fieldPath');
106+
return mergeArrayOfObjectsByKey(destinationArray, sourceArray, 'fieldPath', true);
92107
};
93108

94109
function getArrayMergeFunction(key) {
@@ -112,7 +127,7 @@ function getArrayMergeFunction(key) {
112127
}
113128
}
114129

115-
const customMerge = (isPrimary, key) => {
130+
function customMerge(isPrimary, key) {
116131
if (key === 'upstream' || key === 'downstream') {
117132
return (_secondary, primary) => primary;
118133
}
@@ -145,7 +160,7 @@ const customMerge = (isPrimary, key) => {
145160
customMerge: customMerge.bind({}, isPrimary),
146161
});
147162
};
148-
};
163+
}
149164

150165
export const getEntitySiblingData = <T>(baseEntity: T): Maybe<SiblingProperties> => {
151166
if (!baseEntity) {

0 commit comments

Comments
 (0)