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";
30 import { treePickerReducer } from './tree-picker/tree-picker-reducer';
31 import { TreePicker } from './tree-picker/tree-picker';
33 const composeEnhancers =
34 (process.env.NODE_ENV === 'development' &&
35 window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
38 export interface RootState {
40 projects: ProjectState;
41 collections: CollectionsState;
43 dataExplorer: DataExplorerState;
44 sidePanel: SidePanelState;
45 collectionPanel: CollectionPanelState;
46 detailsPanel: DetailsPanelState;
47 contextMenu: ContextMenuState;
48 favorites: FavoritesState;
49 snackbar: SnackbarState;
50 collectionPanelFiles: CollectionPanelFilesState;
52 treePicker: TreePicker;
55 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
57 export function configureStore(history: History, services: ServiceRepository): RootStore {
58 const rootReducer = combineReducers({
59 auth: authReducer(services),
60 projects: projectsReducer,
61 collections: collectionsReducer,
62 router: routerReducer,
63 dataExplorer: dataExplorerReducer,
64 sidePanel: sidePanelReducer,
65 collectionPanel: collectionPanelReducer,
66 detailsPanel: detailsPanelReducer,
67 contextMenu: contextMenuReducer,
69 favorites: favoritesReducer,
70 snackbar: snackbarReducer,
71 collectionPanelFiles: collectionPanelFilesReducer,
72 dialog: dialogReducer,
73 treePicker: treePickerReducer,
76 const projectPanelMiddleware = dataExplorerMiddleware(
77 new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
79 const favoritePanelMiddleware = dataExplorerMiddleware(
80 new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
83 const middlewares: Middleware[] = [
84 routerMiddleware(history),
85 thunkMiddleware.withExtraArgument(services),
86 projectPanelMiddleware,
87 favoritePanelMiddleware
89 const enhancer = composeEnhancers(applyMiddleware(...middlewares));
90 return createStore(rootReducer, enhancer);