2019-10-04 05:24:47 -07:00
|
|
|
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
|
2018-07-09 10:28:20 +02:00
|
|
|
import thunk from 'redux-thunk';
|
2019-06-03 13:40:33 +02:00
|
|
|
import { createLogger } from 'redux-logger';
|
2019-10-04 05:24:47 -07:00
|
|
|
import sharedReducers from 'app/core/reducers';
|
|
|
|
|
import alertingReducers from 'app/features/alerting/state/reducers';
|
|
|
|
|
import teamsReducers from 'app/features/teams/state/reducers';
|
|
|
|
|
import apiKeysReducers from 'app/features/api-keys/state/reducers';
|
|
|
|
|
import foldersReducers from 'app/features/folders/state/reducers';
|
|
|
|
|
import dashboardReducers from 'app/features/dashboard/state/reducers';
|
|
|
|
|
import exploreReducers from 'app/features/explore/state/reducers';
|
|
|
|
|
import pluginReducers from 'app/features/plugins/state/reducers';
|
|
|
|
|
import dataSourcesReducers from 'app/features/datasources/state/reducers';
|
|
|
|
|
import usersReducers from 'app/features/users/state/reducers';
|
|
|
|
|
import userReducers from 'app/features/profile/state/reducers';
|
|
|
|
|
import organizationReducers from 'app/features/org/state/reducers';
|
|
|
|
|
import ldapReducers from 'app/features/admin/state/reducers';
|
2018-11-05 16:54:48 +01:00
|
|
|
import { setStore } from './store';
|
2019-06-03 13:40:33 +02:00
|
|
|
import { StoreState } from 'app/types/store';
|
|
|
|
|
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
2019-10-04 05:24:47 -07:00
|
|
|
|
|
|
|
|
const rootReducers = {
|
|
|
|
|
...sharedReducers,
|
|
|
|
|
...alertingReducers,
|
|
|
|
|
...teamsReducers,
|
|
|
|
|
...apiKeysReducers,
|
|
|
|
|
...foldersReducers,
|
|
|
|
|
...dashboardReducers,
|
|
|
|
|
...exploreReducers,
|
|
|
|
|
...pluginReducers,
|
|
|
|
|
...dataSourcesReducers,
|
|
|
|
|
...usersReducers,
|
|
|
|
|
...userReducers,
|
|
|
|
|
...organizationReducers,
|
|
|
|
|
...ldapReducers,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function addRootReducer(reducers: any) {
|
|
|
|
|
Object.assign(rootReducers, ...reducers);
|
|
|
|
|
}
|
2018-10-16 15:36:33 +02:00
|
|
|
|
2018-07-09 10:28:20 +02:00
|
|
|
export function configureStore() {
|
|
|
|
|
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
2019-10-04 05:24:47 -07:00
|
|
|
const rootReducer = combineReducers(rootReducers);
|
2019-06-03 13:40:33 +02:00
|
|
|
const logger = createLogger({
|
|
|
|
|
predicate: (getState: () => StoreState) => {
|
|
|
|
|
return getState().application.logActions;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const storeEnhancers =
|
|
|
|
|
process.env.NODE_ENV !== 'production'
|
2019-08-28 18:24:52 +02:00
|
|
|
? applyMiddleware(toggleLogActionsMiddleware, thunk, logger)
|
|
|
|
|
: applyMiddleware(thunk);
|
2018-10-16 15:36:33 +02:00
|
|
|
|
2019-06-04 16:20:55 +02:00
|
|
|
const store = createStore(rootReducer, {}, composeEnhancers(storeEnhancers));
|
|
|
|
|
setStore(store);
|
|
|
|
|
return store;
|
2018-07-09 09:17:38 +02:00
|
|
|
}
|