From e9f1e86c8e19c27eed3243be93252e5e8d14905d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Mon, 16 Sep 2019 14:17:33 +0200 Subject: [PATCH] Fix: Fixes crash using back button with zoomed graph (#19122) Fixes: #19114 --- .../features/explore/state/reducers.test.ts | 28 ++++++++++++++++++- public/app/features/explore/state/reducers.ts | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/public/app/features/explore/state/reducers.test.ts b/public/app/features/explore/state/reducers.test.ts index bf09628ef70..79bd276e9ac 100644 --- a/public/app/features/explore/state/reducers.test.ts +++ b/public/app/features/explore/state/reducers.test.ts @@ -20,6 +20,7 @@ import { scanStopAction, toggleGraphAction, toggleTableAction, + changeRangeAction, } from './actionTypes'; import { Reducer } from 'redux'; import { ActionOf } from 'app/core/redux/actionCreatorFactory'; @@ -27,7 +28,7 @@ import { updateLocation } from 'app/core/actions/location'; import { serializeStateToUrlParam } from 'app/core/utils/explore'; import TableModel from 'app/core/table_model'; import { DataSourceApi, DataQuery } from '@grafana/ui'; -import { LogsModel, LogsDedupStrategy } from '@grafana/data'; +import { LogsModel, LogsDedupStrategy, dateTime } from '@grafana/data'; describe('Explore item reducer', () => { describe('scanning', () => { @@ -196,6 +197,31 @@ describe('Explore item reducer', () => { }); }); }); + + describe('changing range', () => { + describe('when changeRangeAction is dispatched', () => { + it('then it should set correct state', () => { + reducerTester() + .givenReducer(itemReducer, { + update: { ...makeInitialUpdateState(), range: true }, + range: null, + absoluteRange: null, + }) + .whenActionIsDispatched( + changeRangeAction({ + exploreId: ExploreId.left, + absoluteRange: { from: 1546297200000, to: 1546383600000 }, + range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } }, + }) + ) + .thenStateShouldEqual({ + update: { ...makeInitialUpdateState(), range: false }, + absoluteRange: { from: 1546297200000, to: 1546383600000 }, + range: { from: dateTime('2019-01-01'), to: dateTime('2019-01-02'), raw: { from: 'now-1d', to: 'now' } }, + }); + }); + }); + }); }); export const setup = (urlStateOverrides?: any) => { diff --git a/public/app/features/explore/state/reducers.ts b/public/app/features/explore/state/reducers.ts index 27bdd4b6b58..899c60eec26 100644 --- a/public/app/features/explore/state/reducers.ts +++ b/public/app/features/explore/state/reducers.ts @@ -540,6 +540,7 @@ export const itemReducer = reducerFactory({} as ExploreItemSta ...state, range, absoluteRange, + update: makeInitialUpdateState(), }; }, })