Merge branch 'master' into 14480-show-link-to-process-which-created-a-collection
[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 virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
30     const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
31     const workflowMatch = Routes.matchWorkflowRoute(pathname);
32     const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
33     const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
34     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
35     const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
36     const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
37     const myAccountMatch = Routes.matchMyAccountRoute(pathname);
38     const userMatch = Routes.matchUsersRoute(pathname);
39
40     if (projectMatch) {
41         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
42     } else if (collectionMatch) {
43         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
44     } else if (favoriteMatch) {
45         store.dispatch(WorkbenchActions.loadFavorites());
46     } else if (trashMatch) {
47         store.dispatch(WorkbenchActions.loadTrash());
48     } else if (processMatch) {
49         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
50     } else if (processLogMatch) {
51         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
52     } else if (rootMatch) {
53         store.dispatch(navigateToRootProject);
54     } else if (sharedWithMeMatch) {
55         store.dispatch(WorkbenchActions.loadSharedWithMe);
56     } else if (runProcessMatch) {
57         store.dispatch(WorkbenchActions.loadRunProcess);
58     } else if (workflowMatch) {
59         store.dispatch(WorkbenchActions.loadWorkflow);
60     } else if (searchResultsMatch) {
61         store.dispatch(WorkbenchActions.loadSearchResults);
62     } else if (virtualMachineUserMatch) {
63         store.dispatch(WorkbenchActions.loadVirtualMachines);
64     } else if (virtualMachineAdminMatch) {
65         store.dispatch(WorkbenchActions.loadVirtualMachines);
66     } else if (repositoryMatch) {
67         store.dispatch(WorkbenchActions.loadRepositories);
68     } else if (sshKeysUserMatch) {
69         store.dispatch(WorkbenchActions.loadSshKeys);
70     } else if (sshKeysAdminMatch) {
71         store.dispatch(WorkbenchActions.loadSshKeys);
72     } else if (keepServicesMatch) {
73         store.dispatch(WorkbenchActions.loadKeepServices);
74     } else if (computeNodesMatch) {
75         store.dispatch(WorkbenchActions.loadComputeNodes);
76     } else if (apiClientAuthorizationsMatch) {
77         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
78     } else if (myAccountMatch) {
79         store.dispatch(WorkbenchActions.loadMyAccount);
80     } else if (userMatch) {
81         store.dispatch(WorkbenchActions.loadUsers);
82     }
83 };