StructureRev: use deep equals for structure revision change detection (#53920)

This commit is contained in:
Ryan McKinley
2022-08-19 08:29:23 -07:00
committed by GitHub
parent 88419aa8fe
commit 7cbf6015db
3 changed files with 31 additions and 16 deletions
@@ -183,7 +183,7 @@ describe('test comparisons', () => {
expect(compareDataFrameStructures(a, b)).toBeFalsy();
});
it('does not compare deeply', () => {
it('does deep comparison', () => {
const a = {
...frameB,
fields: [
@@ -218,7 +218,7 @@ describe('test comparisons', () => {
],
};
expect(compareDataFrameStructures(a, b)).toBeFalsy();
expect(compareDataFrameStructures(a, b)).toBeTruthy();
});
});
});
@@ -1,3 +1,5 @@
import { isEqual } from 'lodash';
import { DataFrame } from '../types/dataFrame';
/**
@@ -8,10 +10,6 @@ import { DataFrame } from '../types/dataFrame';
* ```
* compareArrayValues(a, b, framesHaveSameStructure);
* ```
* NOTE: this does a shallow check on the FieldConfig properties, when using the query
* editor, this should be sufficient, however if applications are mutating properties
* deep in the FieldConfig this will not recognize a change
*
* @beta
*/
export function compareDataFrameStructures(a: DataFrame, b: DataFrame, skipConfig?: boolean): boolean {
@@ -63,11 +61,9 @@ export function compareDataFrameStructures(a: DataFrame, b: DataFrame, skipConfi
if (key === 'interval') {
continue;
}
if (key === 'custom') {
if (!shallowCompare(cfgA[key], cfgB[key])) {
return false;
}
} else if (cfgA[key] !== cfgB[key]) {
// Deep comparison on all object properties
if (!isEqual(cfgA[key], cfgB[key])) {
return false;
}
}