Commit edfce089 by David Committed by GitHub

Merge pull request #15090 from grafana/hugoh/bug-explore-cant-go-from-dashboard-to-explore

Fixed reinitialise of Explore
parents 9298876e 6b0400ee
import { LocationUpdate } from 'app/types';
export enum CoreActionTypes {
UpdateLocation = 'UPDATE_LOCATION',
}
export type Action = UpdateLocationAction;
export interface UpdateLocationAction {
type: 'UPDATE_LOCATION';
type: CoreActionTypes.UpdateLocation;
payload: LocationUpdate;
}
export const updateLocation = (location: LocationUpdate): UpdateLocationAction => ({
type: 'UPDATE_LOCATION',
type: CoreActionTypes.UpdateLocation,
payload: location,
});
import { Action } from 'app/core/actions/location';
import { Action, CoreActionTypes } from 'app/core/actions/location';
import { LocationState } from 'app/types';
import { renderUrl } from 'app/core/utils/url';
import _ from 'lodash';
......@@ -12,7 +12,7 @@ export const initialState: LocationState = {
export const locationReducer = (state = initialState, action: Action): LocationState => {
switch (action.type) {
case 'UPDATE_LOCATION': {
case CoreActionTypes.UpdateLocation: {
const { path, routeParams } = action.payload;
let query = action.payload.query || state.query;
......@@ -24,9 +24,7 @@ export const locationReducer = (state = initialState, action: Action): LocationS
return {
url: renderUrl(path || state.path, query),
path: path || state.path,
query: {
...query,
},
query: { ...query },
routeParams: routeParams || state.routeParams,
};
}
......
......@@ -7,7 +7,7 @@ import { StoreState } from 'app/types';
import { ExploreId, ExploreUrlState } from 'app/types/explore';
import { parseUrlState } from 'app/core/utils/explore';
import { initializeExploreSplit } from './state/actions';
import { initializeExploreSplit, resetExplore } from './state/actions';
import ErrorBoundary from './ErrorBoundary';
import Explore from './Explore';
import { CustomScrollbar } from '@grafana/ui';
......@@ -16,6 +16,7 @@ interface WrapperProps {
initializeExploreSplit: typeof initializeExploreSplit;
split: boolean;
updateLocation: typeof updateLocation;
resetExplore: typeof resetExplore;
urlStates: { [key: string]: string };
}
......@@ -42,6 +43,10 @@ export class Wrapper extends Component<WrapperProps> {
}
}
componentWillUnmount() {
this.props.resetExplore();
}
render() {
const { split } = this.props;
const { leftState, rightState } = this.urlStates;
......@@ -74,6 +79,7 @@ const mapStateToProps = (state: StoreState) => {
const mapDispatchToProps = {
initializeExploreSplit,
updateLocation,
resetExplore,
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Wrapper));
// Types
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 {
ExploreId,
ExploreItemState,
......@@ -41,6 +41,7 @@ export enum ActionTypes {
ToggleGraph = 'explore/TOGGLE_GRAPH',
ToggleLogs = 'explore/TOGGLE_LOGS',
ToggleTable = 'explore/TOGGLE_TABLE',
ResetExplore = 'explore/RESET_EXPLORE',
}
export interface AddQueryRowAction {
......@@ -270,6 +271,11 @@ export interface ToggleLogsAction {
};
}
export interface ResetExploreAction {
type: ActionTypes.ResetExplore;
payload: {};
}
export type Action =
| AddQueryRowAction
| ChangeQueryAction
......@@ -297,4 +303,5 @@ export type Action =
| SplitOpenAction
| ToggleGraphAction
| ToggleLogsAction
| ToggleTableAction;
| ToggleTableAction
| ResetExploreAction;
......@@ -21,7 +21,7 @@ import { updateLocation } from 'app/core/actions';
// Types
import { StoreState } from 'app/types';
import { DataQuery, DataSourceSelectItem, QueryHint } from '@grafana/ui/src/types';
import { DataQuery, DataSourceSelectItem, QueryHint } from '@grafana/ui/src/types';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import {
ExploreId,
......@@ -48,7 +48,6 @@ import {
ScanStopAction,
} from './actionTypes';
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>;
/**
......@@ -766,3 +765,12 @@ export function toggleTable(exploreId: ExploreId): ThunkResult<void> {
}
};
}
/**
* Resets state for explore.
*/
export function resetExplore(): ThunkResult<void> {
return dispatch => {
dispatch({ type: ActionTypes.ResetExplore, payload: {} });
};
}
......@@ -428,25 +428,19 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
export const exploreReducer = (state = initialExploreState, action: Action): ExploreState => {
switch (action.type) {
case ActionTypes.SplitClose: {
return {
...state,
split: false,
};
return { ...state, split: false };
}
case ActionTypes.SplitOpen: {
return {
...state,
split: true,
right: action.payload.itemState,
};
return { ...state, split: true, right: action.payload.itemState };
}
case ActionTypes.InitializeExploreSplit: {
return {
...state,
split: true,
};
return { ...state, split: true };
}
case ActionTypes.ResetExplore: {
return initialExploreState;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment