-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data Explorer] Allow render from View directly, not from Data Explor…
…er (#6167) (#6959) * [Discover] Remove double render This PR avoids re-rendering the entire AppContainer when data services update. The re-render is caused by history object which is in AppMountParameters. This history object is part of the application's routing context and can change frequently as the url is updated by query, filter or time range. Each change in the history object could potentially trigger a re-render of the AppContainer and its child components. With this PR, the AppContainer will not be re-loaded. Instead each component, like Canvas and Panel, will be updated. --------- (cherry picked from commit b792242) Signed-off-by: Anan Zhuang <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
150a9d3
commit 4b9dd67
Showing
5 changed files
with
143 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/plugins/data_explorer/public/utils/use/shallow_equal.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { shallowEqual } from './shallow_equal'; | ||
|
||
describe('shallowEqual', () => { | ||
it('should return true for equal objects without ignored keys', () => { | ||
const obj1 = { a: 1, b: 2, c: 3 }; | ||
const obj2 = { a: 1, b: 2, c: 3 }; | ||
const ignoreKeys = []; | ||
|
||
expect(shallowEqual(obj1, obj2, ignoreKeys)).toBe(true); | ||
}); | ||
|
||
it('should return false for objects with different values', () => { | ||
const obj1 = { a: 1, b: 2, c: 3 }; | ||
const obj2 = { a: 1, b: 2, c: 4 }; | ||
const ignoreKeys = []; | ||
|
||
expect(shallowEqual(obj1, obj2, ignoreKeys)).toBe(false); | ||
}); | ||
|
||
it('should return false for objects with different keys', () => { | ||
const obj1 = { a: 1, b: 2 }; | ||
const obj2 = { a: 1, b: 2, c: 3 }; | ||
const ignoreKeys = []; | ||
|
||
expect(shallowEqual(obj1, obj2, ignoreKeys)).toBe(false); | ||
}); | ||
|
||
it('should return true for objects with different values but ignored', () => { | ||
const obj1 = { a: 1, b: 2, c: 3 }; | ||
const obj2 = { a: 1, b: 2, c: 4 }; | ||
const ignoreKeys = ['c']; | ||
|
||
expect(shallowEqual(obj1, obj2, ignoreKeys)).toBe(true); | ||
}); | ||
|
||
it('should return true for objects with different keys but ignored', () => { | ||
const obj1 = { a: 1, b: 2 }; | ||
const obj2 = { a: 1, b: 2, c: 4 }; | ||
const ignoreKeys = ['c']; | ||
|
||
expect(shallowEqual(obj1, obj2, ignoreKeys)).toBe(true); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/plugins/data_explorer/public/utils/use/shallow_equal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// A simple shallow equal function that can ignore specified keys | ||
export function shallowEqual(object1: any, object2: any, ignoreKeys: any) { | ||
const keys1 = Object.keys(object1).filter((key) => !ignoreKeys.includes(key)); | ||
const keys2 = Object.keys(object2).filter((key) => !ignoreKeys.includes(key)); | ||
|
||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} | ||
|
||
for (const key of keys1) { | ||
if (object1[key] !== object2[key]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters