Browse Source

Fixed reinitialise of Explore

Hugo Häggmark 7 years ago
parent
commit
40f410562a

+ 6 - 2
public/app/core/actions/location.ts

@@ -1,13 +1,17 @@
 import { LocationUpdate } from 'app/types';
 import { LocationUpdate } from 'app/types';
 
 
+export enum CoreActionTypes {
+  UpdateLocation = 'UPDATE_LOCATION',
+}
+
 export type Action = UpdateLocationAction;
 export type Action = UpdateLocationAction;
 
 
 export interface UpdateLocationAction {
 export interface UpdateLocationAction {
-  type: 'UPDATE_LOCATION';
+  type: CoreActionTypes.UpdateLocation;
   payload: LocationUpdate;
   payload: LocationUpdate;
 }
 }
 
 
 export const updateLocation = (location: LocationUpdate): UpdateLocationAction => ({
 export const updateLocation = (location: LocationUpdate): UpdateLocationAction => ({
-  type: 'UPDATE_LOCATION',
+  type: CoreActionTypes.UpdateLocation,
   payload: location,
   payload: location,
 });
 });

+ 3 - 5
public/app/core/reducers/location.ts

@@ -1,4 +1,4 @@
-import { Action } from 'app/core/actions/location';
+import { Action, CoreActionTypes } from 'app/core/actions/location';
 import { LocationState } from 'app/types';
 import { LocationState } from 'app/types';
 import { renderUrl } from 'app/core/utils/url';
 import { renderUrl } from 'app/core/utils/url';
 import _ from 'lodash';
 import _ from 'lodash';
@@ -12,7 +12,7 @@ export const initialState: LocationState = {
 
 
 export const locationReducer = (state = initialState, action: Action): LocationState => {
 export const locationReducer = (state = initialState, action: Action): LocationState => {
   switch (action.type) {
   switch (action.type) {
-    case 'UPDATE_LOCATION': {
+    case CoreActionTypes.UpdateLocation: {
       const { path, routeParams } = action.payload;
       const { path, routeParams } = action.payload;
       let query = action.payload.query || state.query;
       let query = action.payload.query || state.query;
 
 
@@ -24,9 +24,7 @@ export const locationReducer = (state = initialState, action: Action): LocationS
       return {
       return {
         url: renderUrl(path || state.path, query),
         url: renderUrl(path || state.path, query),
         path: path || state.path,
         path: path || state.path,
-        query: {
-          ...query,
-        },
+        query: { ...query },
         routeParams: routeParams || state.routeParams,
         routeParams: routeParams || state.routeParams,
       };
       };
     }
     }

+ 4 - 2
public/app/features/explore/state/actionTypes.ts

@@ -1,6 +1,6 @@
 // Types
 // Types
 import { Emitter } from 'app/core/core';
 import { Emitter } from 'app/core/core';
-import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem  } from '@grafana/ui/src/types';
+import { RawTimeRange, TimeRange, DataQuery, DataSourceSelectItem } from '@grafana/ui/src/types';
 import {
 import {
   ExploreId,
   ExploreId,
   ExploreItemState,
   ExploreItemState,
@@ -9,6 +9,7 @@ import {
   ResultType,
   ResultType,
   QueryTransaction,
   QueryTransaction,
 } from 'app/types/explore';
 } from 'app/types/explore';
+import { UpdateLocationAction } from 'app/core/actions/location';
 
 
 export enum ActionTypes {
 export enum ActionTypes {
   AddQueryRow = 'explore/ADD_QUERY_ROW',
   AddQueryRow = 'explore/ADD_QUERY_ROW',
@@ -297,4 +298,5 @@ export type Action =
   | SplitOpenAction
   | SplitOpenAction
   | ToggleGraphAction
   | ToggleGraphAction
   | ToggleLogsAction
   | ToggleLogsAction
-  | ToggleTableAction;
+  | ToggleTableAction
+  | UpdateLocationAction;

+ 12 - 13
public/app/features/explore/state/reducers.ts

@@ -8,6 +8,7 @@ import { ExploreItemState, ExploreState, QueryTransaction } from 'app/types/expl
 import { DataQuery } from '@grafana/ui/src/types';
 import { DataQuery } from '@grafana/ui/src/types';
 
 
 import { Action, ActionTypes } from './actionTypes';
 import { Action, ActionTypes } from './actionTypes';
+import { CoreActionTypes } from 'app/core/actions/location';
 
 
 export const DEFAULT_RANGE = {
 export const DEFAULT_RANGE = {
   from: 'now-6h',
   from: 'now-6h',
@@ -428,25 +429,23 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
 export const exploreReducer = (state = initialExploreState, action: Action): ExploreState => {
 export const exploreReducer = (state = initialExploreState, action: Action): ExploreState => {
   switch (action.type) {
   switch (action.type) {
     case ActionTypes.SplitClose: {
     case ActionTypes.SplitClose: {
-      return {
-        ...state,
-        split: false,
-      };
+      return { ...state, split: false };
     }
     }
 
 
     case ActionTypes.SplitOpen: {
     case ActionTypes.SplitOpen: {
-      return {
-        ...state,
-        split: true,
-        right: action.payload.itemState,
-      };
+      return { ...state, split: true, right: action.payload.itemState };
     }
     }
 
 
     case ActionTypes.InitializeExploreSplit: {
     case ActionTypes.InitializeExploreSplit: {
-      return {
-        ...state,
-        split: true,
-      };
+      return { ...state, split: true };
+    }
+
+    case CoreActionTypes.UpdateLocation: {
+      if (action.payload.path && action.payload.path !== '/explore') {
+        return initialExploreState;
+      }
+
+      return state;
     }
     }
   }
   }