mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Avoid reinitializing graph on every query run (#77281)
This commit is contained in:
parent
f750c3194e
commit
bf554d121c
@ -51,6 +51,15 @@ beforeAll(() => {
|
||||
describe('useStructureRev', () => {
|
||||
afterEach(() => resetCounters());
|
||||
|
||||
// mirrors the logic in componentDidUpdate in packages/grafana-ui/src/components/GraphNG/GraphNG.tsx,
|
||||
// which treats all falsy values for structureRev as a signal to reconfig the graph
|
||||
it('should start from a thruthy value', () => {
|
||||
let frames: DataFrame[] = [toDataFrame({ fields: [{ name: 'time', type: FieldType.time, values: [1, 2, 3] }] })];
|
||||
const { result } = renderHook((frames) => useStructureRev(frames), { initialProps: frames });
|
||||
|
||||
expect(result.current).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it('should increment only when relevant fields in frame change', () => {
|
||||
let frames: DataFrame[] = [toDataFrame({ fields: [{ name: 'time', type: FieldType.time, values: [1, 2, 3] }] })];
|
||||
const { result, rerender } = renderHook((frames) => useStructureRev(frames), { initialProps: frames });
|
||||
|
@ -4,7 +4,7 @@ import { useCounter, usePrevious } from 'react-use';
|
||||
import { DataFrame, compareArrayValues, compareDataFrameStructures } from '@grafana/data';
|
||||
|
||||
export function useStructureRev(frames: DataFrame[]) {
|
||||
const [structureRev, { inc }] = useCounter(0);
|
||||
const [structureRev, { inc }] = useCounter(1);
|
||||
const previousFrames = usePrevious(frames);
|
||||
|
||||
// We need to increment structureRev when the number of series changes.
|
||||
|
Loading…
Reference in New Issue
Block a user