add compute nodes with store, service and all dialogs
[arvados-workbench2.git] / src / routes / route-change-handlers.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { History, Location } from 'history';
6 import { RootStore } from '~/store/store';
7 import * as Routes from '~/routes/routes';
8 import * as WorkbenchActions from '~/store/workbench/workbench-actions';
9 import { navigateToRootProject } from '~/store/navigation/navigation-action';
10
11 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
12     const handler = handleLocationChange(store);
13     handler(history.location);
14     history.listen(handler);
15 };
16
17 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
18     const rootMatch = Routes.matchRootRoute(pathname);
19     const projectMatch = Routes.matchProjectRoute(pathname);
20     const collectionMatch = Routes.matchCollectionRoute(pathname);
21     const favoriteMatch = Routes.matchFavoritesRoute(pathname);
22     const trashMatch = Routes.matchTrashRoute(pathname);
23     const processMatch = Routes.matchProcessRoute(pathname);
24     const processLogMatch = Routes.matchProcessLogRoute(pathname);
25     const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
26     const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
27     const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
28     const runProcessMatch = Routes.matchRunProcessRoute(pathname);
29     const virtualMachineMatch = Routes.matchVirtualMachineRoute(pathname);
30     const workflowMatch = Routes.matchWorkflowRoute(pathname);
31     const sshKeysMatch = Routes.matchSshKeysRoute(pathname);
32     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
33     const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
34
35     if (projectMatch) {
36         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
37     } else if (collectionMatch) {
38         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
39     } else if (favoriteMatch) {
40         store.dispatch(WorkbenchActions.loadFavorites());
41     } else if (trashMatch) {
42         store.dispatch(WorkbenchActions.loadTrash());
43     } else if (processMatch) {
44         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
45     } else if (processLogMatch) {
46         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
47     } else if (rootMatch) {
48         store.dispatch(navigateToRootProject);
49     } else if (sharedWithMeMatch) {
50         store.dispatch(WorkbenchActions.loadSharedWithMe);
51     } else if (runProcessMatch) {
52         store.dispatch(WorkbenchActions.loadRunProcess);
53     } else if (workflowMatch) {
54         store.dispatch(WorkbenchActions.loadWorkflow);
55     } else if (searchResultsMatch) {
56         store.dispatch(WorkbenchActions.loadSearchResults);
57     } else if (virtualMachineMatch) {
58         store.dispatch(WorkbenchActions.loadVirtualMachines);
59     } else if(repositoryMatch) {
60         store.dispatch(WorkbenchActions.loadRepositories);
61     } else if (sshKeysMatch) {
62         store.dispatch(WorkbenchActions.loadSshKeys);
63     } else if (keepServicesMatch) {
64         store.dispatch(WorkbenchActions.loadKeepServices);
65     } else if (computeNodesMatch) {
66         store.dispatch(WorkbenchActions.loadComputeNodes);
67     }
68 };