mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: remove redux-logger (#34220)
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
import { AnyAction, Dispatch, Middleware, MiddlewareAPI } from 'redux';
|
||||
|
||||
import { StoreState } from 'app/types/store';
|
||||
import { toggleLogActions } from '../reducers/application';
|
||||
|
||||
export const toggleLogActionsMiddleware: Middleware<{}, StoreState> = (store: MiddlewareAPI<Dispatch, StoreState>) => (
|
||||
next: Dispatch
|
||||
) => (action: AnyAction) => {
|
||||
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);
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
import { reducerTester } from '../../../test/core/redux/reducerTester';
|
||||
import { applicationReducer, toggleLogActions } from './application';
|
||||
import { ApplicationState } from '../../types/application';
|
||||
|
||||
describe('applicationReducer', () => {
|
||||
describe('when toggleLogActions is dispatched', () => {
|
||||
it('then state should be correct', () => {
|
||||
reducerTester<ApplicationState>()
|
||||
.givenReducer(applicationReducer, { logActions: false })
|
||||
.whenActionIsDispatched(toggleLogActions())
|
||||
.thenStateShouldEqual({ logActions: true })
|
||||
.whenActionIsDispatched(toggleLogActions())
|
||||
.thenStateShouldEqual({ logActions: false });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
import { ApplicationState } from 'app/types/application';
|
||||
|
||||
export const initialState: ApplicationState = {
|
||||
logActions: false,
|
||||
};
|
||||
|
||||
const applicationSlice = createSlice({
|
||||
name: 'application',
|
||||
initialState,
|
||||
reducers: {
|
||||
toggleLogActions: (state) => ({ ...state, logActions: !state.logActions }),
|
||||
},
|
||||
});
|
||||
|
||||
export const { toggleLogActions } = applicationSlice.actions;
|
||||
export const applicationReducer = applicationSlice.reducer;
|
||||
@@ -1,9 +1,7 @@
|
||||
import { navIndexReducer as navIndex } from './navModel';
|
||||
import { appNotificationsReducer as appNotifications } from './appNotification';
|
||||
import { applicationReducer as application } from './application';
|
||||
|
||||
export default {
|
||||
navIndex,
|
||||
appNotifications,
|
||||
application,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { configureStore as reduxConfigureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
|
||||
import { createLogger } from 'redux-logger';
|
||||
import { ThunkMiddleware } from 'redux-thunk';
|
||||
import { setStore } from './store';
|
||||
import { StoreState } from 'app/types/store';
|
||||
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
||||
import { addReducer, createRootReducer } from '../core/reducers/root';
|
||||
import { buildInitialState } from '../core/reducers/navModel';
|
||||
|
||||
@@ -15,14 +13,6 @@ export function addRootReducer(reducers: any) {
|
||||
}
|
||||
|
||||
export function configureStore(initialState?: Partial<StoreState>) {
|
||||
const logger = createLogger({
|
||||
predicate: (getState) => {
|
||||
return getState().application.logActions;
|
||||
},
|
||||
});
|
||||
|
||||
const middleware = process.env.NODE_ENV !== 'production' ? [toggleLogActionsMiddleware, logger] : [];
|
||||
|
||||
const reduxDefaultMiddleware = getDefaultMiddleware<StoreState>({
|
||||
thunk: true,
|
||||
serializableCheck: false,
|
||||
@@ -31,7 +21,7 @@ export function configureStore(initialState?: Partial<StoreState>) {
|
||||
|
||||
const store = reduxConfigureStore<StoreState>({
|
||||
reducer: createRootReducer(),
|
||||
middleware: [...reduxDefaultMiddleware, ...middleware] as [ThunkMiddleware<StoreState>],
|
||||
middleware: (reduxDefaultMiddleware as unknown) as [ThunkMiddleware<StoreState>],
|
||||
devTools: process.env.NODE_ENV !== 'production',
|
||||
preloadedState: {
|
||||
navIndex: buildInitialState(),
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export interface ApplicationState {
|
||||
logActions: boolean;
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import { UserAdminState, UserListAdminState, UsersState, UserState } from './use
|
||||
import { OrganizationState } from './organization';
|
||||
import { AppNotificationsState } from './appNotifications';
|
||||
import { PluginsState } from './plugins';
|
||||
import { ApplicationState } from './application';
|
||||
import { LdapState } from './ldap';
|
||||
import { PanelEditorState } from '../features/dashboard/components/PanelEditor/state/reducers';
|
||||
import { ApiKeysState } from './apiKeys';
|
||||
@@ -35,7 +34,6 @@ export interface StoreState {
|
||||
appNotifications: AppNotificationsState;
|
||||
user: UserState;
|
||||
plugins: PluginsState;
|
||||
application: ApplicationState;
|
||||
ldap: LdapState;
|
||||
apiKeys: ApiKeysState;
|
||||
userAdmin: UserAdminState;
|
||||
|
||||
Reference in New Issue
Block a user