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 } from "react-router-redux";
7 import thunkMiddleware from 'redux-thunk';
8 import { History } from "history";
10 import { authReducer } from "./auth/auth-reducer";
11 import { dataExplorerReducer } from './data-explorer/data-explorer-reducer';
12 import { detailsPanelReducer } from './details-panel/details-panel-reducer';
13 import { contextMenuReducer } from './context-menu/context-menu-reducer';
14 import { reducer as formReducer } from 'redux-form';
15 import { favoritesReducer } from './favorites/favorites-reducer';
16 import { snackbarReducer } from './snackbar/snackbar-reducer';
17 import { collectionPanelFilesReducer } from './collection-panel/collection-panel-files/collection-panel-files-reducer';
18 import { dataExplorerMiddleware } from "./data-explorer/data-explorer-middleware";
19 import { FAVORITE_PANEL_ID } from "./favorite-panel/favorite-panel-action";
20 import { PROJECT_PANEL_ID } from "./project-panel/project-panel-action";
21 import { ProjectPanelMiddlewareService } from "./project-panel/project-panel-middleware-service";
22 import { FavoritePanelMiddlewareService } from "./favorite-panel/favorite-panel-middleware-service";
23 import { collectionPanelReducer } from './collection-panel/collection-panel-reducer';
24 import { dialogReducer } from './dialog/dialog-reducer';
25 import { ServiceRepository } from "~/services/services";
26 import { treePickerReducer } from './tree-picker/tree-picker-reducer';
27 import { resourcesReducer } from '~/store/resources/resources-reducer';
28 import { propertiesReducer } from './properties/properties-reducer';
29 import { RootState } from './store';
30 import { fileUploaderReducer } from './file-uploader/file-uploader-reducer';
31 import { TrashPanelMiddlewareService } from "~/store/trash-panel/trash-panel-middleware-service";
32 import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
33 import { processLogsPanelReducer } from './process-logs-panel/process-logs-panel-reducer';
34 import { processPanelReducer } from '~/store/process-panel/process-panel-reducer';
35 import { SHARED_WITH_ME_PANEL_ID } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
36 import { SharedWithMeMiddlewareService } from './shared-with-me-panel/shared-with-me-middleware-service';
37 import { progressIndicatorReducer } from './progress-indicator/progress-indicator-reducer';
38 import { WorkflowMiddlewareService } from './workflow-panel/workflow-middleware-service';
39 import { WORKFLOW_PANEL_ID } from './workflow-panel/workflow-panel-actions';
41 const composeEnhancers =
42 (process.env.NODE_ENV === 'development' &&
43 window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
46 export type RootState = ReturnType<ReturnType<typeof createRootReducer>>;
48 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
50 export function configureStore(history: History, services: ServiceRepository): RootStore {
51 const rootReducer = createRootReducer(services);
53 const projectPanelMiddleware = dataExplorerMiddleware(
54 new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
56 const favoritePanelMiddleware = dataExplorerMiddleware(
57 new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
59 const trashPanelMiddleware = dataExplorerMiddleware(
60 new TrashPanelMiddlewareService(services, TRASH_PANEL_ID)
62 const sharedWithMePanelMiddleware = dataExplorerMiddleware(
63 new SharedWithMeMiddlewareService(services, SHARED_WITH_ME_PANEL_ID)
65 const workflowPanelMiddleware = dataExplorerMiddleware(
66 new WorkflowMiddlewareService(services, WORKFLOW_PANEL_ID)
69 const middlewares: Middleware[] = [
70 routerMiddleware(history),
71 thunkMiddleware.withExtraArgument(services),
72 projectPanelMiddleware,
73 favoritePanelMiddleware,
75 sharedWithMePanelMiddleware,
76 workflowPanelMiddleware
78 const enhancer = composeEnhancers(applyMiddleware(...middlewares));
79 return createStore(rootReducer, enhancer);
82 const createRootReducer = (services: ServiceRepository) => combineReducers({
83 auth: authReducer(services),
84 collectionPanel: collectionPanelReducer,
85 collectionPanelFiles: collectionPanelFilesReducer,
86 contextMenu: contextMenuReducer,
87 dataExplorer: dataExplorerReducer,
88 detailsPanel: detailsPanelReducer,
89 dialog: dialogReducer,
90 favorites: favoritesReducer,
92 processLogsPanel: processLogsPanelReducer,
93 properties: propertiesReducer,
94 resources: resourcesReducer,
95 router: routerReducer,
96 snackbar: snackbarReducer,
97 treePicker: treePickerReducer,
98 fileUploader: fileUploaderReducer,
99 processPanel: processPanelReducer,
100 progressIndicator: progressIndicatorReducer