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 { runProcessPanelReducer } from '~/store/run-process-panel/run-process-panel-reducer';
39 import { WorkflowMiddlewareService } from './workflow-panel/workflow-middleware-service';
40 import { WORKFLOW_PANEL_ID } from './workflow-panel/workflow-panel-actions';
41 import { appInfoReducer } from '~/store/app-info/app-info-reducer';
42 import { searchBarReducer } from './search-bar/search-bar-reducer';
43 import { SEARCH_RESULTS_PANEL_ID } from '~/store/search-results-panel/search-results-panel-actions';
44 import { SearchResultsMiddlewareService } from './search-results-panel/search-results-middleware-service';
45 import { resourcesDataReducer } from "~/store/resources-data/resources-data-reducer";
46 import { virtualMachinesReducer } from "~/store/virtual-machines/virtual-machines-reducer";
47 import { repositoriesReducer } from '~/store/repositories/repositories-reducer';
48 import { keepServicesReducer } from '~/store/keep-services/keep-services-reducer';
49 import { UserMiddlewareService } from '~/store/users/user-panel-middleware-service';
50 import { USERS_PANEL_ID } from '~/store/users/users-actions';
51 import { GroupsPanelMiddlewareService } from '~/store/groups-panel/groups-panel-middleware-service';
52 import { GROUPS_PANEL_ID } from '~/store/groups-panel/groups-panel-actions';
53 import { GroupDetailsPanelMiddlewareService } from '~/store/group-details-panel/group-details-panel-middleware-service';
54 import { GROUP_DETAILS_PANEL_ID } from '~/store/group-details-panel/group-details-panel-actions';
55 import { LINK_PANEL_ID } from '~/store/link-panel/link-panel-actions';
56 import { LinkMiddlewareService } from '~/store/link-panel/link-panel-middleware-service';
57 import { COMPUTE_NODE_PANEL_ID } from '~/store/compute-nodes/compute-nodes-actions';
58 import { ComputeNodeMiddlewareService } from '~/store/compute-nodes/compute-nodes-middleware-service';
59 import { API_CLIENT_AUTHORIZATION_PANEL_ID } from '~/store/api-client-authorizations/api-client-authorizations-actions';
60 import { ApiClientAuthorizationMiddlewareService } from '~/store/api-client-authorizations/api-client-authorizations-middleware-service';
62 const composeEnhancers =
63 (process.env.NODE_ENV === 'development' &&
64 window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
65 window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true, traceLimit: 25})) ||
68 export type RootState = ReturnType<ReturnType<typeof createRootReducer>>;
70 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
72 export function configureStore(history: History, services: ServiceRepository): RootStore {
73 const rootReducer = createRootReducer(services);
75 const projectPanelMiddleware = dataExplorerMiddleware(
76 new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
78 const favoritePanelMiddleware = dataExplorerMiddleware(
79 new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
81 const trashPanelMiddleware = dataExplorerMiddleware(
82 new TrashPanelMiddlewareService(services, TRASH_PANEL_ID)
84 const searchResultsPanelMiddleware = dataExplorerMiddleware(
85 new SearchResultsMiddlewareService(services, SEARCH_RESULTS_PANEL_ID)
87 const sharedWithMePanelMiddleware = dataExplorerMiddleware(
88 new SharedWithMeMiddlewareService(services, SHARED_WITH_ME_PANEL_ID)
90 const workflowPanelMiddleware = dataExplorerMiddleware(
91 new WorkflowMiddlewareService(services, WORKFLOW_PANEL_ID)
93 const userPanelMiddleware = dataExplorerMiddleware(
94 new UserMiddlewareService(services, USERS_PANEL_ID)
96 const groupsPanelMiddleware = dataExplorerMiddleware(
97 new GroupsPanelMiddlewareService(services, GROUPS_PANEL_ID)
99 const groupDetailsPanelMiddleware = dataExplorerMiddleware(
100 new GroupDetailsPanelMiddlewareService(services, GROUP_DETAILS_PANEL_ID)
102 const linkPanelMiddleware = dataExplorerMiddleware(
103 new LinkMiddlewareService(services, LINK_PANEL_ID)
105 const computeNodeMiddleware = dataExplorerMiddleware(
106 new ComputeNodeMiddlewareService(services, COMPUTE_NODE_PANEL_ID)
108 const apiClientAuthorizationMiddlewareService = dataExplorerMiddleware(
109 new ApiClientAuthorizationMiddlewareService(services, API_CLIENT_AUTHORIZATION_PANEL_ID)
111 const middlewares: Middleware[] = [
112 routerMiddleware(history),
113 thunkMiddleware.withExtraArgument(services),
114 projectPanelMiddleware,
115 favoritePanelMiddleware,
116 trashPanelMiddleware,
117 searchResultsPanelMiddleware,
118 sharedWithMePanelMiddleware,
119 workflowPanelMiddleware,
121 groupsPanelMiddleware,
122 groupDetailsPanelMiddleware,
124 computeNodeMiddleware,
125 apiClientAuthorizationMiddlewareService
127 const enhancer = composeEnhancers(applyMiddleware(...middlewares));
128 return createStore(rootReducer, enhancer);
131 const createRootReducer = (services: ServiceRepository) => combineReducers({
132 auth: authReducer(services),
133 collectionPanel: collectionPanelReducer,
134 collectionPanelFiles: collectionPanelFilesReducer,
135 contextMenu: contextMenuReducer,
136 dataExplorer: dataExplorerReducer,
137 detailsPanel: detailsPanelReducer,
138 dialog: dialogReducer,
139 favorites: favoritesReducer,
141 processLogsPanel: processLogsPanelReducer,
142 properties: propertiesReducer,
143 resources: resourcesReducer,
144 resourcesData: resourcesDataReducer,
145 router: routerReducer,
146 snackbar: snackbarReducer,
147 treePicker: treePickerReducer,
148 fileUploader: fileUploaderReducer,
149 processPanel: processPanelReducer,
150 progressIndicator: progressIndicatorReducer,
151 runProcessPanel: runProcessPanelReducer,
152 appInfo: appInfoReducer,
153 searchBar: searchBarReducer,
154 virtualMachines: virtualMachinesReducer,
155 repositories: repositoriesReducer,
156 keepServices: keepServicesReducer