mirror of https://github.com/grafana/grafana
Feature: Adds redux action logging toggle from url params (#17368)
With live tailing introduced in Explore we now have a lot of actions dispatching and the Redux Dev Tools doesn't cope with the amount and rate of actions and crashes. This PR turns on redux action logging when you add logActions=true in the url and turns it off if you refresh the page or add logActions=false in the url.pull/17263/head^2
parent
20229a40eb
commit
5761179ad9
@ -0,0 +1,3 @@ |
||||
import { noPayloadActionCreatorFactory } from 'app/core/redux'; |
||||
|
||||
export const toggleLogActions = noPayloadActionCreatorFactory('TOGGLE_LOG_ACTIONS').create(); |
@ -0,0 +1,27 @@ |
||||
import { Store, Dispatch } from 'redux'; |
||||
import { StoreState } from 'app/types/store'; |
||||
import { ActionOf } from '../redux/actionCreatorFactory'; |
||||
import { toggleLogActions } from '../actions/application'; |
||||
|
||||
export const toggleLogActionsMiddleware = (store: Store<StoreState>) => (next: Dispatch) => (action: ActionOf<any>) => { |
||||
const isLogActionsAction = action.type === toggleLogActions.type; |
||||
if (isLogActionsAction) { |
||||
return next(action); |
||||
} |
||||
|
||||
const logActionsTrue = |
||||
window && window.location && window.location.search && window.location.search.indexOf('logActions=true') !== -1; |
||||
const logActionsFalse = |
||||
window && window.location && window.location.search && window.location.search.indexOf('logActions=false') !== -1; |
||||
const logActions = store.getState().application.logActions; |
||||
|
||||
if (logActionsTrue && !logActions) { |
||||
store.dispatch(toggleLogActions()); |
||||
} |
||||
|
||||
if (logActionsFalse && logActions) { |
||||
store.dispatch(toggleLogActions()); |
||||
} |
||||
|
||||
return next(action); |
||||
}; |
@ -0,0 +1,17 @@ |
||||
import { ApplicationState } from 'app/types/application'; |
||||
import { reducerFactory } from 'app/core/redux'; |
||||
import { toggleLogActions } from '../actions/application'; |
||||
|
||||
export const initialState: ApplicationState = { |
||||
logActions: false, |
||||
}; |
||||
|
||||
export const applicationReducer = reducerFactory<ApplicationState>(initialState) |
||||
.addMapper({ |
||||
filter: toggleLogActions, |
||||
mapper: (state): ApplicationState => ({ |
||||
...state, |
||||
logActions: !state.logActions, |
||||
}), |
||||
}) |
||||
.create(); |
@ -1,9 +1,11 @@ |
||||
import { navIndexReducer as navIndex } from './navModel'; |
||||
import { locationReducer as location } from './location'; |
||||
import { appNotificationsReducer as appNotifications } from './appNotification'; |
||||
import { applicationReducer as application } from './application'; |
||||
|
||||
export default { |
||||
navIndex, |
||||
location, |
||||
appNotifications, |
||||
application, |
||||
}; |
||||
|
@ -0,0 +1,3 @@ |
||||
export interface ApplicationState { |
||||
logActions: boolean; |
||||
} |
Loading…
Reference in new issue