Add site manager and initial validation
[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 siteManagerMatch = Routes.matchSiteManagerRoute(pathname);
33     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
34     const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
35
36     if (projectMatch) {
37         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
38     } else if (collectionMatch) {
39         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
40     } else if (favoriteMatch) {
41         store.dispatch(WorkbenchActions.loadFavorites());
42     } else if (trashMatch) {
43         store.dispatch(WorkbenchActions.loadTrash());
44     } else if (processMatch) {
45         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
46     } else if (processLogMatch) {
47         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
48     } else if (rootMatch) {
49         store.dispatch(navigateToRootProject);
50     } else if (sharedWithMeMatch) {
51         store.dispatch(WorkbenchActions.loadSharedWithMe);
52     } else if (runProcessMatch) {
53         store.dispatch(WorkbenchActions.loadRunProcess);
54     } else if (workflowMatch) {
55         store.dispatch(WorkbenchActions.loadWorkflow);
56     } else if (searchResultsMatch) {
57         store.dispatch(WorkbenchActions.loadSearchResults);
58     } else if (virtualMachineMatch) {
59         store.dispatch(WorkbenchActions.loadVirtualMachines);
60     } else if(repositoryMatch) {
61         store.dispatch(WorkbenchActions.loadRepositories);
62     } else if (sshKeysMatch) {
63         store.dispatch(WorkbenchActions.loadSshKeys);
64     } else if (siteManagerMatch) {
65         store.dispatch(WorkbenchActions.loadSiteManager);
66     } else if (keepServicesMatch) {
67         store.dispatch(WorkbenchActions.loadKeepServices);
68     } else if (computeNodesMatch) {
69         store.dispatch(WorkbenchActions.loadComputeNodes);
70     }
71 };