1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { createStore, applyMiddleware, compose, Middleware, combineReducers, Store, Action, Dispatch } from 'redux';
6 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
7 import thunkMiddleware from 'redux-thunk';
8 import { History } from "history";
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 { detailsPanelReducer, DetailsPanelState } from './details-panel/details-panel-reducer';
15 import { contextMenuReducer, ContextMenuState } from './context-menu/context-menu-reducer';
16 import { reducer as formReducer } from 'redux-form';
17 import { FavoritesState, favoritesReducer } from './favorites/favorites-reducer';
18 import { snackbarReducer, SnackbarState } from './snackbar/snackbar-reducer';
19 import { dataExplorerMiddleware } from "./data-explorer/data-explorer-middleware";
20 import { FAVORITE_PANEL_ID } from "./favorite-panel/favorite-panel-action";
21 import { PROJECT_PANEL_ID } from "./project-panel/project-panel-action";
22 import { ProjectPanelMiddlewareService } from "./project-panel/project-panel-middleware-service";
23 import { FavoritePanelMiddlewareService } from "./favorite-panel/favorite-panel-middleware-service";
24 import { CollectionCreatorState, collectionCreationReducer } from './collections/creator/collection-creator-reducer';
25 import { CollectionPanelState, collectionPanelReducer } from './collection-panel/collection-panel-reducer';
26 import { ServiceRepository } from "../services/services";
28 const composeEnhancers =
29 (process.env.NODE_ENV === 'development' &&
30 window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
33 export interface RootState {
35 projects: ProjectState;
36 collectionCreation: CollectionCreatorState;
38 dataExplorer: DataExplorerState;
39 sidePanel: SidePanelState;
40 collectionPanel: CollectionPanelState;
41 detailsPanel: DetailsPanelState;
42 contextMenu: ContextMenuState;
43 favorites: FavoritesState;
44 snackbar: SnackbarState;
47 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
49 export function configureStore(history: History, services: ServiceRepository): RootStore {
50 const rootReducer = combineReducers({
51 auth: authReducer(services),
52 projects: projectsReducer,
53 collectionCreation: collectionCreationReducer,
54 router: routerReducer,
55 dataExplorer: dataExplorerReducer,
56 sidePanel: sidePanelReducer,
57 collectionPanel: collectionPanelReducer,
58 detailsPanel: detailsPanelReducer,
59 contextMenu: contextMenuReducer,
61 favorites: favoritesReducer,
62 snackbar: snackbarReducer,
65 const projectPanelMiddleware = dataExplorerMiddleware(
66 new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
68 const favoritePanelMiddleware = dataExplorerMiddleware(
69 new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
72 const middlewares: Middleware[] = [
73 routerMiddleware(history),
74 thunkMiddleware.withExtraArgument(services),
75 projectPanelMiddleware,
76 favoritePanelMiddleware
78 const enhancer = composeEnhancers(applyMiddleware(...middlewares));
79 return createStore(rootReducer, enhancer);