Merge branch 'origin/master' into 14478-log-in-into-clusters
[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 import { dialogActions } from '~/store/dialog/dialog-actions';
11 import { contextMenuActions } from '~/store/context-menu/context-menu-actions';
12 import { searchBarActions } from '~/store/search-bar/search-bar-actions';
13
14 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
15     const handler = handleLocationChange(store);
16     handler(history.location);
17     history.listen(handler);
18 };
19
20 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
21     const rootMatch = Routes.matchRootRoute(pathname);
22     const projectMatch = Routes.matchProjectRoute(pathname);
23     const collectionMatch = Routes.matchCollectionRoute(pathname);
24     const favoriteMatch = Routes.matchFavoritesRoute(pathname);
25     const trashMatch = Routes.matchTrashRoute(pathname);
26     const processMatch = Routes.matchProcessRoute(pathname);
27     const processLogMatch = Routes.matchProcessLogRoute(pathname);
28     const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
29     const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
30     const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
31     const runProcessMatch = Routes.matchRunProcessRoute(pathname);
32     const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
33     const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
34     const workflowMatch = Routes.matchWorkflowRoute(pathname);
35     const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
36     const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
37     const siteManagerMatch = Routes.matchSiteManagerRoute(pathname);
38     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
39     const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
40     const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
41     const myAccountMatch = Routes.matchMyAccountRoute(pathname);
42     const userMatch = Routes.matchUsersRoute(pathname);
43     const groupsMatch = Routes.matchGroupsRoute(pathname);
44     const groupDetailsMatch = Routes.matchGroupDetailsRoute(pathname);
45     const linksMatch = Routes.matchLinksRoute(pathname);
46
47     store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
48     store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
49     store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
50
51     if (projectMatch) {
52         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
53     } else if (collectionMatch) {
54         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
55     } else if (favoriteMatch) {
56         store.dispatch(WorkbenchActions.loadFavorites());
57     } else if (trashMatch) {
58         store.dispatch(WorkbenchActions.loadTrash());
59     } else if (processMatch) {
60         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
61     } else if (processLogMatch) {
62         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
63     } else if (rootMatch) {
64         store.dispatch(navigateToRootProject);
65     } else if (sharedWithMeMatch) {
66         store.dispatch(WorkbenchActions.loadSharedWithMe);
67     } else if (runProcessMatch) {
68         store.dispatch(WorkbenchActions.loadRunProcess);
69     } else if (workflowMatch) {
70         store.dispatch(WorkbenchActions.loadWorkflow);
71     } else if (searchResultsMatch) {
72         store.dispatch(WorkbenchActions.loadSearchResults);
73     } else if (virtualMachineUserMatch) {
74         store.dispatch(WorkbenchActions.loadVirtualMachines);
75     } else if (virtualMachineAdminMatch) {
76         store.dispatch(WorkbenchActions.loadVirtualMachines);
77     } else if (repositoryMatch) {
78         store.dispatch(WorkbenchActions.loadRepositories);
79     } else if (sshKeysUserMatch) {
80         store.dispatch(WorkbenchActions.loadSshKeys);
81     } else if (sshKeysAdminMatch) {
82         store.dispatch(WorkbenchActions.loadSshKeys);
83     } else if (siteManagerMatch) {
84         store.dispatch(WorkbenchActions.loadSiteManager);
85     } else if (keepServicesMatch) {
86         store.dispatch(WorkbenchActions.loadKeepServices);
87     } else if (computeNodesMatch) {
88         store.dispatch(WorkbenchActions.loadComputeNodes);
89     } else if (apiClientAuthorizationsMatch) {
90         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
91     } else if (myAccountMatch) {
92         store.dispatch(WorkbenchActions.loadMyAccount);
93     } else if (userMatch) {
94         store.dispatch(WorkbenchActions.loadUsers);
95     } else if (groupsMatch) {
96         store.dispatch(WorkbenchActions.loadGroupsPanel);
97     } else if (groupDetailsMatch) {
98         store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
99     } else if (linksMatch) {
100         store.dispatch(WorkbenchActions.loadLinks);
101     }
102 };