mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Firing off an action instead of listening to location changes
This commit is contained in:
parent
40f410562a
commit
6b0400eed2
@ -7,7 +7,7 @@ import { StoreState } from 'app/types';
|
|||||||
import { ExploreId, ExploreUrlState } from 'app/types/explore';
|
import { ExploreId, ExploreUrlState } from 'app/types/explore';
|
||||||
import { parseUrlState } from 'app/core/utils/explore';
|
import { parseUrlState } from 'app/core/utils/explore';
|
||||||
|
|
||||||
import { initializeExploreSplit } from './state/actions';
|
import { initializeExploreSplit, resetExplore } from './state/actions';
|
||||||
import ErrorBoundary from './ErrorBoundary';
|
import ErrorBoundary from './ErrorBoundary';
|
||||||
import Explore from './Explore';
|
import Explore from './Explore';
|
||||||
import { CustomScrollbar } from '@grafana/ui';
|
import { CustomScrollbar } from '@grafana/ui';
|
||||||
@ -16,6 +16,7 @@ interface WrapperProps {
|
|||||||
initializeExploreSplit: typeof initializeExploreSplit;
|
initializeExploreSplit: typeof initializeExploreSplit;
|
||||||
split: boolean;
|
split: boolean;
|
||||||
updateLocation: typeof updateLocation;
|
updateLocation: typeof updateLocation;
|
||||||
|
resetExplore: typeof resetExplore;
|
||||||
urlStates: { [key: string]: string };
|
urlStates: { [key: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +43,10 @@ export class Wrapper extends Component<WrapperProps> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.props.resetExplore();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { split } = this.props;
|
const { split } = this.props;
|
||||||
const { leftState, rightState } = this.urlStates;
|
const { leftState, rightState } = this.urlStates;
|
||||||
@ -74,6 +79,7 @@ const mapStateToProps = (state: StoreState) => {
|
|||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
initializeExploreSplit,
|
initializeExploreSplit,
|
||||||
updateLocation,
|
updateLocation,
|
||||||
|
resetExplore,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Wrapper));
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Wrapper));
|
||||||
|
@ -9,7 +9,6 @@ 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',
|
||||||
@ -42,6 +41,7 @@ export enum ActionTypes {
|
|||||||
ToggleGraph = 'explore/TOGGLE_GRAPH',
|
ToggleGraph = 'explore/TOGGLE_GRAPH',
|
||||||
ToggleLogs = 'explore/TOGGLE_LOGS',
|
ToggleLogs = 'explore/TOGGLE_LOGS',
|
||||||
ToggleTable = 'explore/TOGGLE_TABLE',
|
ToggleTable = 'explore/TOGGLE_TABLE',
|
||||||
|
ResetExplore = 'explore/RESET_EXPLORE',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddQueryRowAction {
|
export interface AddQueryRowAction {
|
||||||
@ -271,6 +271,11 @@ export interface ToggleLogsAction {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ResetExploreAction {
|
||||||
|
type: ActionTypes.ResetExplore;
|
||||||
|
payload: {};
|
||||||
|
}
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
| AddQueryRowAction
|
| AddQueryRowAction
|
||||||
| ChangeQueryAction
|
| ChangeQueryAction
|
||||||
@ -299,4 +304,4 @@ export type Action =
|
|||||||
| ToggleGraphAction
|
| ToggleGraphAction
|
||||||
| ToggleLogsAction
|
| ToggleLogsAction
|
||||||
| ToggleTableAction
|
| ToggleTableAction
|
||||||
| UpdateLocationAction;
|
| ResetExploreAction;
|
||||||
|
@ -48,7 +48,6 @@ import {
|
|||||||
ScanStopAction,
|
ScanStopAction,
|
||||||
} from './actionTypes';
|
} from './actionTypes';
|
||||||
|
|
||||||
|
|
||||||
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, ThunkableAction>;
|
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: {} });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -8,7 +8,6 @@ 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',
|
||||||
@ -440,13 +439,9 @@ export const exploreReducer = (state = initialExploreState, action: Action): Exp
|
|||||||
return { ...state, split: true };
|
return { ...state, split: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
case CoreActionTypes.UpdateLocation: {
|
case ActionTypes.ResetExplore: {
|
||||||
if (action.payload.path && action.payload.path !== '/explore') {
|
|
||||||
return initialExploreState;
|
return initialExploreState;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.payload) {
|
if (action.payload) {
|
||||||
|
Loading…
Reference in New Issue
Block a user