@@ -5,6 +5,7 @@ import * as QueryString from 'query-string';
55import { Dataset , Entity , Maybe , SiblingProperties } from '../../../types.generated' ;
66import { GenericEntityProperties } from './types' ;
77import { useIsShowSeparateSiblingsEnabled } from '../../useAppConfig' ;
8+ import { downgradeV2FieldPath } from '../dataset/profile/schema/utils/utils' ;
89
910export 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
7085const mergeTags = ( destinationArray , sourceArray , _options ) => {
@@ -88,7 +103,7 @@ const mergeOwners = (destinationArray, sourceArray, _options) => {
88103} ;
89104
90105const mergeFields = ( destinationArray , sourceArray , _options ) => {
91- return mergeArrayOfObjectsByKey ( destinationArray , sourceArray , 'fieldPath' ) ;
106+ return mergeArrayOfObjectsByKey ( destinationArray , sourceArray , 'fieldPath' , true ) ;
92107} ;
93108
94109function 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
150165export const getEntitySiblingData = < T > ( baseEntity : T ) : Maybe < SiblingProperties > => {
151166 if ( ! baseEntity ) {
0 commit comments