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 { CollectionPanelFilesState } from './collection-panel/collection-panel-files/collection-panel-files-state';
20 import { collectionPanelFilesReducer } from './collection-panel/collection-panel-files/collection-panel-files-reducer';
21 import { dataExplorerMiddleware } from "./data-explorer/data-explorer-middleware";
22 import { FAVORITE_PANEL_ID } from "./favorite-panel/favorite-panel-action";
23 import { PROJECT_PANEL_ID } from "./project-panel/project-panel-action";
24 import { ProjectPanelMiddlewareService } from "./project-panel/project-panel-middleware-service";
25 import { FavoritePanelMiddlewareService } from "./favorite-panel/favorite-panel-middleware-service";
26 import { CollectionPanelState, collectionPanelReducer } from './collection-panel/collection-panel-reducer';
27 import { DialogState, dialogReducer } from './dialog/dialog-reducer';
28 import { CollectionsState, collectionsReducer } from './collections/collections-reducer';
29 import { ServiceRepository } from "../services/services";
31 const composeEnhancers =
32 (process.env.NODE_ENV === 'development' &&
33 window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
36 export interface RootState {
38 projects: ProjectState;
39 collections: CollectionsState;
41 dataExplorer: DataExplorerState;
42 sidePanel: SidePanelState;
43 collectionPanel: CollectionPanelState;
44 detailsPanel: DetailsPanelState;
45 contextMenu: ContextMenuState;
46 favorites: FavoritesState;
47 snackbar: SnackbarState;
48 collectionPanelFiles: CollectionPanelFilesState;
52 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
54 export function configureStore(history: History, services: ServiceRepository): RootStore {
55 const rootReducer = combineReducers({
56 auth: authReducer(services),
57 projects: projectsReducer,
58 collections: collectionsReducer,
59 router: routerReducer,
60 dataExplorer: dataExplorerReducer,
61 sidePanel: sidePanelReducer,
62 collectionPanel: collectionPanelReducer,
63 detailsPanel: detailsPanelReducer,
64 contextMenu: contextMenuReducer,
66 favorites: favoritesReducer,
67 snackbar: snackbarReducer,
68 collectionPanelFiles: collectionPanelFilesReducer,
72 const projectPanelMiddleware = dataExplorerMiddleware(
73 new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
75 const favoritePanelMiddleware = dataExplorerMiddleware(
76 new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
79 const middlewares: Middleware[] = [
80 routerMiddleware(history),
81 thunkMiddleware.withExtraArgument(services),
82 projectPanelMiddleware,
83 favoritePanelMiddleware
85 const enhancer = composeEnhancers(applyMiddleware(...middlewares));
86 return createStore(rootReducer, enhancer);