refs #master Merge branch 'origin/master' into 13901-services-repo
[arvados-workbench2.git] / src / store / store.ts
index 68c5d8238c74894857e08f7d34f8e0df90bcfb9b..37343619fe2c4319288574a615bffe01f1e3e485 100644 (file)
@@ -2,16 +2,28 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { createStore, applyMiddleware, compose, Middleware, combineReducers } from 'redux';
+import { createStore, applyMiddleware, compose, Middleware, combineReducers, Store, Action, Dispatch } from 'redux';
 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
 import thunkMiddleware from 'redux-thunk';
 import { History } from "history";
 
-import projectsReducer, { ProjectState } from "./project/project-reducer";
-import sidePanelReducer, { SidePanelState } from './side-panel/side-panel-reducer';
-import authReducer, { AuthState } from "./auth/auth-reducer";
-import dataExplorerReducer, { DataExplorerState } from './data-explorer/data-explorer-reducer';
-import collectionsReducer, { CollectionState } from "./collection/collection-reducer";
+import { projectsReducer, ProjectState } from "./project/project-reducer";
+import { sidePanelReducer, SidePanelState } from './side-panel/side-panel-reducer';
+import { authReducer, AuthState } from "./auth/auth-reducer";
+import { dataExplorerReducer, DataExplorerState } from './data-explorer/data-explorer-reducer';
+import { detailsPanelReducer, DetailsPanelState } from './details-panel/details-panel-reducer';
+import { contextMenuReducer, ContextMenuState } from './context-menu/context-menu-reducer';
+import { reducer as formReducer } from 'redux-form';
+import { FavoritesState, favoritesReducer } from './favorites/favorites-reducer';
+import { snackbarReducer, SnackbarState } from './snackbar/snackbar-reducer';
+import { dataExplorerMiddleware } from "./data-explorer/data-explorer-middleware";
+import { FAVORITE_PANEL_ID } from "./favorite-panel/favorite-panel-action";
+import { PROJECT_PANEL_ID } from "./project-panel/project-panel-action";
+import { ProjectPanelMiddlewareService } from "./project-panel/project-panel-middleware-service";
+import { FavoritePanelMiddlewareService } from "./favorite-panel/favorite-panel-middleware-service";
+import { CollectionCreatorState, collectionCreationReducer } from './collections/creator/collection-creator-reducer';
+import { CollectionPanelState, collectionPanelReducer } from './collection-panel/collection-panel-reducer';
+import { ServiceRepository } from "../services/services";
 
 const composeEnhancers =
     (process.env.NODE_ENV === 'development' &&
@@ -21,26 +33,47 @@ const composeEnhancers =
 export interface RootState {
     auth: AuthState;
     projects: ProjectState;
-    collections: CollectionState;
+    collectionCreation: CollectionCreatorState;
     router: RouterState;
     dataExplorer: DataExplorerState;
     sidePanel: SidePanelState;
+    collectionPanel: CollectionPanelState;
+    detailsPanel: DetailsPanelState;
+    contextMenu: ContextMenuState;
+    favorites: FavoritesState;
+    snackbar: SnackbarState;
 }
 
-const rootReducer = combineReducers({
-    auth: authReducer,
-    projects: projectsReducer,
-    collections: collectionsReducer,
-    router: routerReducer,
-    dataExplorer: dataExplorerReducer,
-    sidePanel: sidePanelReducer
-});
+export type RootStore = Store<RootState, Action> & { dispatch: Dispatch<any> };
 
+export function configureStore(history: History, services: ServiceRepository): RootStore {
+       const rootReducer = combineReducers({
+           auth: authReducer(services),
+           projects: projectsReducer,
+           collectionCreation: collectionCreationReducer,
+           router: routerReducer,
+           dataExplorer: dataExplorerReducer,
+           sidePanel: sidePanelReducer,
+           collectionPanel: collectionPanelReducer,
+           detailsPanel: detailsPanelReducer,
+           contextMenu: contextMenuReducer,
+           form: formReducer,
+           favorites: favoritesReducer,
+           snackbar: snackbarReducer,
+       });
+
+    const projectPanelMiddleware = dataExplorerMiddleware(
+        new ProjectPanelMiddlewareService(services, PROJECT_PANEL_ID)
+    );
+    const favoritePanelMiddleware = dataExplorerMiddleware(
+        new FavoritePanelMiddlewareService(services, FAVORITE_PANEL_ID)
+    );
 
-export default function configureStore(history: History) {
     const middlewares: Middleware[] = [
         routerMiddleware(history),
-        thunkMiddleware
+        thunkMiddleware.withExtraArgument(services),
+        projectPanelMiddleware,
+        favoritePanelMiddleware
     ];
     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
     return createStore(rootReducer, enhancer);