Create project panel middleware
[arvados-workbench2.git] / src / store / store.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { createStore, applyMiddleware, compose, Middleware, combineReducers } from 'redux';
6 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
7 import thunkMiddleware from 'redux-thunk';
8 import { History } from "history";
9
10 import projectsReducer, { ProjectState } from "./project/project-reducer";
11 import sidePanelReducer, { SidePanelState } from './side-panel/side-panel-reducer';
12 import authReducer, { AuthState } from "./auth/auth-reducer";
13 import dataExplorerReducer, { DataExplorerState } from './data-explorer/data-explorer-reducer';
14 import collectionsReducer, { CollectionState } from "./collection/collection-reducer";
15 import { projectPanelMiddleware } from '../views/project-panel/project-panel-middleware';
16
17 const composeEnhancers =
18     (process.env.NODE_ENV === 'development' &&
19         window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
20     compose;
21
22 export interface RootState {
23     auth: AuthState;
24     projects: ProjectState;
25     collections: CollectionState;
26     router: RouterState;
27     dataExplorer: DataExplorerState;
28     sidePanel: SidePanelState;
29 }
30
31 const rootReducer = combineReducers({
32     auth: authReducer,
33     projects: projectsReducer,
34     collections: collectionsReducer,
35     router: routerReducer,
36     dataExplorer: dataExplorerReducer,
37     sidePanel: sidePanelReducer
38 });
39
40
41 export default function configureStore(history: History) {
42     const middlewares: Middleware[] = [
43         routerMiddleware(history),
44         thunkMiddleware,
45         projectPanelMiddleware
46     ];
47     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
48     return createStore(rootReducer, enhancer);
49 }