21128: fixed unwanted rowselects on other operational clicks Arvados-DCO-1.1-Signed...
[arvados.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 import { pluginConfig } from 'plugins';
14 import { openProjectPanel } from 'store/project-panel/project-panel-action';
15
16 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
17     const handler = handleLocationChange(store);
18     handler(history.location);
19     history.listen(handler);
20 };
21
22 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
23
24     const rootMatch = Routes.matchRootRoute(pathname);
25     const projectMatch = Routes.matchProjectRoute(pathname);
26     const collectionMatch = Routes.matchCollectionRoute(pathname);
27     const favoriteMatch = Routes.matchFavoritesRoute(pathname);
28     const publicFavoritesMatch = Routes.matchPublicFavoritesRoute(pathname);
29     const trashMatch = Routes.matchTrashRoute(pathname);
30     const processMatch = Routes.matchProcessRoute(pathname);
31     const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
32     const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
33     const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
34     const runProcessMatch = Routes.matchRunProcessRoute(pathname);
35     const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
36     const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
37     const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
38     const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
39     const siteManagerMatch = Routes.matchSiteManagerRoute(pathname);
40     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
41     const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
42     const myAccountMatch = Routes.matchMyAccountRoute(pathname);
43     const linkAccountMatch = Routes.matchLinkAccountRoute(pathname);
44     const usersMatch = Routes.matchUsersRoute(pathname);
45     const userProfileMatch = Routes.matchUserProfileRoute(pathname);
46     const groupsMatch = Routes.matchGroupsRoute(pathname);
47     const groupDetailsMatch = Routes.matchGroupDetailsRoute(pathname);
48     const linksMatch = Routes.matchLinksRoute(pathname);
49     const collectionsContentAddressMatch = Routes.matchCollectionsContentAddressRoute(pathname);
50     const allProcessesMatch = Routes.matchAllProcessesRoute(pathname);
51     const registeredWorkflowMatch = Routes.matchRegisteredWorkflowRoute(pathname);
52
53     store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
54     store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
55     store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
56
57     for (const locChangeFn of pluginConfig.locationChangeHandlers) {
58         if (locChangeFn(store, pathname)) {
59             return;
60         }
61     }
62
63     document.title = `Arvados (${store.getState().auth.config.uuidPrefix}) - ${pathname.slice(1)}`;
64
65     if (projectMatch) {
66         store.dispatch(openProjectPanel(projectMatch.params.id));
67     } else if (collectionMatch) {
68         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
69     } else if (favoriteMatch) {
70         store.dispatch(WorkbenchActions.loadFavorites());
71     } else if (publicFavoritesMatch) {
72         store.dispatch(WorkbenchActions.loadPublicFavorites());
73     } else if (trashMatch) {
74         store.dispatch(WorkbenchActions.loadTrash());
75     } else if (processMatch) {
76         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
77     } else if (rootMatch) {
78         store.dispatch(navigateToRootProject);
79     } else if (sharedWithMeMatch) {
80         store.dispatch(WorkbenchActions.loadSharedWithMe);
81     } else if (runProcessMatch) {
82         store.dispatch(WorkbenchActions.loadRunProcess);
83     } else if (searchResultsMatch) {
84         store.dispatch(WorkbenchActions.loadSearchResults);
85     } else if (virtualMachineUserMatch) {
86         store.dispatch(WorkbenchActions.loadVirtualMachines);
87     } else if (virtualMachineAdminMatch) {
88         store.dispatch(WorkbenchActions.loadVirtualMachinesAdmin);
89     } else if (repositoryMatch) {
90         store.dispatch(WorkbenchActions.loadRepositories);
91     } else if (sshKeysUserMatch) {
92         store.dispatch(WorkbenchActions.loadSshKeys);
93     } else if (sshKeysAdminMatch) {
94         store.dispatch(WorkbenchActions.loadSshKeys);
95     } else if (siteManagerMatch) {
96         store.dispatch(WorkbenchActions.loadSiteManager);
97     } else if (keepServicesMatch) {
98         store.dispatch(WorkbenchActions.loadKeepServices);
99     } else if (apiClientAuthorizationsMatch) {
100         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
101     } else if (myAccountMatch) {
102         store.dispatch(WorkbenchActions.loadUserProfile());
103     } else if (linkAccountMatch) {
104         store.dispatch(WorkbenchActions.loadLinkAccount);
105     } else if (usersMatch) {
106         store.dispatch(WorkbenchActions.loadUsers);
107     } else if (userProfileMatch) {
108         store.dispatch(WorkbenchActions.loadUserProfile(userProfileMatch.params.id));
109     } else if (groupsMatch) {
110         store.dispatch(WorkbenchActions.loadGroupsPanel);
111     } else if (groupDetailsMatch) {
112         store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
113     } else if (linksMatch) {
114         store.dispatch(WorkbenchActions.loadLinks);
115     } else if (collectionsContentAddressMatch) {
116         store.dispatch(WorkbenchActions.loadCollectionContentAddress);
117     } else if (allProcessesMatch) {
118         store.dispatch(WorkbenchActions.loadAllProcesses());
119     } else if (registeredWorkflowMatch) {
120         store.dispatch(WorkbenchActions.loadRegisteredWorkflow(registeredWorkflowMatch.params.id));
121     }
122 };