15803: toggleIsActive will use unsetup to deactivate user
[arvados.git] / src / store / store.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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";
9
10 import { authReducer } from "./auth/auth-reducer";
11 import { configReducer } from "./config/config-reducer";
12 import { dataExplorerReducer } from './data-explorer/data-explorer-reducer';
13 import { detailsPanelReducer } from './details-panel/details-panel-reducer';
14 import { contextMenuReducer } from './context-menu/context-menu-reducer';
15 import { reducer as formReducer } from 'redux-form';
16 import { favoritesReducer } from './favorites/favorites-reducer';
17 import { snackbarReducer } from './snackbar/snackbar-reducer';
18 import { collectionPanelFilesReducer } from './collection-panel/collection-panel-files/collection-panel-files-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 { collectionPanelReducer } from './collection-panel/collection-panel-reducer';
25 import { dialogReducer } from './dialog/dialog-reducer';
26 import { ServiceRepository } from "~/services/services";
27 import { treePickerReducer } from './tree-picker/tree-picker-reducer';
28 import { resourcesReducer } from '~/store/resources/resources-reducer';
29 import { propertiesReducer } from './properties/properties-reducer';
30 import { RootState } from './store';
31 import { fileUploaderReducer } from './file-uploader/file-uploader-reducer';
32 import { TrashPanelMiddlewareService } from "~/store/trash-panel/trash-panel-middleware-service";
33 import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
34 import { processLogsPanelReducer } from './process-logs-panel/process-logs-panel-reducer';
35 import { processPanelReducer } from '~/store/process-panel/process-panel-reducer';
36 import { SHARED_WITH_ME_PANEL_ID } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
37 import { SharedWithMeMiddlewareService } from './shared-with-me-panel/shared-with-me-middleware-service';
38 import { progressIndicatorReducer } from './progress-indicator/progress-indicator-reducer';
39 import { runProcessPanelReducer } from '~/store/run-process-panel/run-process-panel-reducer';
40 import { WorkflowMiddlewareService } from './workflow-panel/workflow-middleware-service';
41 import { WORKFLOW_PANEL_ID } from './workflow-panel/workflow-panel-actions';
42 import { appInfoReducer } from '~/store/app-info/app-info-reducer';
43 import { searchBarReducer } from './search-bar/search-bar-reducer';
44 import { SEARCH_RESULTS_PANEL_ID } from '~/store/search-results-panel/search-results-panel-actions';
45 import { SearchResultsMiddlewareService } from './search-results-panel/search-results-middleware-service';
46 import { resourcesDataReducer } from "~/store/resources-data/resources-data-reducer";
47 import { virtualMachinesReducer } from "~/store/virtual-machines/virtual-machines-reducer";
48 import { repositoriesReducer } from '~/store/repositories/repositories-reducer';
49 import { keepServicesReducer } from '~/store/keep-services/keep-services-reducer';
50 import { UserMiddlewareService } from '~/store/users/user-panel-middleware-service';
51 import { USERS_PANEL_ID } from '~/store/users/users-actions';
52 import { GroupsPanelMiddlewareService } from '~/store/groups-panel/groups-panel-middleware-service';
53 import { GROUPS_PANEL_ID } from '~/store/groups-panel/groups-panel-actions';
54 import { GroupDetailsPanelMiddlewareService } from '~/store/group-details-panel/group-details-panel-middleware-service';
55 import { GROUP_DETAILS_PANEL_ID } from '~/store/group-details-panel/group-details-panel-actions';
56 import { LINK_PANEL_ID } from '~/store/link-panel/link-panel-actions';
57 import { LinkMiddlewareService } from '~/store/link-panel/link-panel-middleware-service';
58 import { COMPUTE_NODE_PANEL_ID } from '~/store/compute-nodes/compute-nodes-actions';
59 import { ComputeNodeMiddlewareService } from '~/store/compute-nodes/compute-nodes-middleware-service';
60 import { API_CLIENT_AUTHORIZATION_PANEL_ID } from '~/store/api-client-authorizations/api-client-authorizations-actions';
61 import { ApiClientAuthorizationMiddlewareService } from '~/store/api-client-authorizations/api-client-authorizations-middleware-service';
62 import { PublicFavoritesMiddlewareService } from '~/store/public-favorites-panel/public-favorites-middleware-service';
63 import { PUBLIC_FAVORITE_PANEL_ID } from '~/store/public-favorites-panel/public-favorites-action';
64 import { publicFavoritesReducer } from '~/store/public-favorites/public-favorites-reducer';
65 import { linkAccountPanelReducer } from './link-account-panel/link-account-panel-reducer';
66 import { CollectionsWithSameContentAddressMiddlewareService } from '~/store/collections-content-address-panel/collections-content-address-middleware-service';
67 import { COLLECTIONS_CONTENT_ADDRESS_PANEL_ID } from '~/store/collections-content-address-panel/collections-content-address-panel-actions';
68 import { ownerNameReducer } from '~/store/owner-name/owner-name-reducer';
69
70 const composeEnhancers =
71     (process.env.NODE_ENV === 'development' &&
72         window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
73         window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ trace: true, traceLimit: 25 })) ||
74     compose;
75
76 export type RootState = ReturnType<ReturnType<typeof createRootReducer>>;
77
78 export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
79
80 export function configureStore(history: History, services: ServiceRepository): RootStore {
81     const rootReducer = createRootReducer(services);
82
83     const projectPanelMiddleware = dataExplorerMiddleware(
84         new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
85     );
86     const favoritePanelMiddleware = dataExplorerMiddleware(
87         new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
88     );
89     const trashPanelMiddleware = dataExplorerMiddleware(
90         new TrashPanelMiddlewareService(services, TRASH_PANEL_ID)
91     );
92     const searchResultsPanelMiddleware = dataExplorerMiddleware(
93         new SearchResultsMiddlewareService(services, SEARCH_RESULTS_PANEL_ID)
94     );
95     const sharedWithMePanelMiddleware = dataExplorerMiddleware(
96         new SharedWithMeMiddlewareService(services, SHARED_WITH_ME_PANEL_ID)
97     );
98     const workflowPanelMiddleware = dataExplorerMiddleware(
99         new WorkflowMiddlewareService(services, WORKFLOW_PANEL_ID)
100     );
101     const userPanelMiddleware = dataExplorerMiddleware(
102         new UserMiddlewareService(services, USERS_PANEL_ID)
103     );
104     const groupsPanelMiddleware = dataExplorerMiddleware(
105         new GroupsPanelMiddlewareService(services, GROUPS_PANEL_ID)
106     );
107     const groupDetailsPanelMiddleware = dataExplorerMiddleware(
108         new GroupDetailsPanelMiddlewareService(services, GROUP_DETAILS_PANEL_ID)
109     );
110     const linkPanelMiddleware = dataExplorerMiddleware(
111         new LinkMiddlewareService(services, LINK_PANEL_ID)
112     );
113     const computeNodeMiddleware = dataExplorerMiddleware(
114         new ComputeNodeMiddlewareService(services, COMPUTE_NODE_PANEL_ID)
115     );
116     const apiClientAuthorizationMiddlewareService = dataExplorerMiddleware(
117         new ApiClientAuthorizationMiddlewareService(services, API_CLIENT_AUTHORIZATION_PANEL_ID)
118     );
119     const publicFavoritesMiddleware = dataExplorerMiddleware(
120         new PublicFavoritesMiddlewareService(services, PUBLIC_FAVORITE_PANEL_ID)
121     );
122     const collectionsContentAddress = dataExplorerMiddleware(
123         new CollectionsWithSameContentAddressMiddlewareService(services, COLLECTIONS_CONTENT_ADDRESS_PANEL_ID)
124     );
125
126     const middlewares: Middleware[] = [
127         routerMiddleware(history),
128         thunkMiddleware.withExtraArgument(services),
129         projectPanelMiddleware,
130         favoritePanelMiddleware,
131         trashPanelMiddleware,
132         searchResultsPanelMiddleware,
133         sharedWithMePanelMiddleware,
134         workflowPanelMiddleware,
135         userPanelMiddleware,
136         groupsPanelMiddleware,
137         groupDetailsPanelMiddleware,
138         linkPanelMiddleware,
139         computeNodeMiddleware,
140         apiClientAuthorizationMiddlewareService,
141         publicFavoritesMiddleware,
142         collectionsContentAddress
143     ];
144     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
145     return createStore(rootReducer, enhancer);
146 }
147
148 const createRootReducer = (services: ServiceRepository) => combineReducers({
149     auth: authReducer(services),
150     config: configReducer,
151     collectionPanel: collectionPanelReducer,
152     collectionPanelFiles: collectionPanelFilesReducer,
153     contextMenu: contextMenuReducer,
154     dataExplorer: dataExplorerReducer,
155     detailsPanel: detailsPanelReducer,
156     dialog: dialogReducer,
157     favorites: favoritesReducer,
158     ownerName: ownerNameReducer,
159     publicFavorites: publicFavoritesReducer,
160     form: formReducer,
161     processLogsPanel: processLogsPanelReducer,
162     properties: propertiesReducer,
163     resources: resourcesReducer,
164     resourcesData: resourcesDataReducer,
165     router: routerReducer,
166     snackbar: snackbarReducer,
167     treePicker: treePickerReducer,
168     fileUploader: fileUploaderReducer,
169     processPanel: processPanelReducer,
170     progressIndicator: progressIndicatorReducer,
171     runProcessPanel: runProcessPanelReducer,
172     appInfo: appInfoReducer,
173     searchBar: searchBarReducer,
174     virtualMachines: virtualMachinesReducer,
175     repositories: repositoriesReducer,
176     keepServices: keepServicesReducer,
177     linkAccountPanel: linkAccountPanelReducer
178 });