Merge branch '15166-size-between-icons-on-workflow-panel-is-too-wide'
[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
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
22     const rootMatch = Routes.matchRootRoute(pathname);
23     const projectMatch = Routes.matchProjectRoute(pathname);
24     const collectionMatch = Routes.matchCollectionRoute(pathname);
25     const favoriteMatch = Routes.matchFavoritesRoute(pathname);
26     const publicFavoritesMatch = Routes.matchPublicFavoritesRoute(pathname);
27     const trashMatch = Routes.matchTrashRoute(pathname);
28     const processMatch = Routes.matchProcessRoute(pathname);
29     const processLogMatch = Routes.matchProcessLogRoute(pathname);
30     const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
31     const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
32     const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
33     const runProcessMatch = Routes.matchRunProcessRoute(pathname);
34     const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
35     const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
36     const workflowMatch = Routes.matchWorkflowRoute(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 computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
42     const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
43     const myAccountMatch = Routes.matchMyAccountRoute(pathname);
44     const userMatch = Routes.matchUsersRoute(pathname);
45     const groupsMatch = Routes.matchGroupsRoute(pathname);
46     const groupDetailsMatch = Routes.matchGroupDetailsRoute(pathname);
47     const linksMatch = Routes.matchLinksRoute(pathname);
48     const collectionsContentAddressMatch = Routes.matchCollectionsContentAddressRoute(pathname);
49
50     store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
51     store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
52     store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
53
54     if (projectMatch) {
55         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
56     } else if (collectionMatch) {
57         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
58     } else if (favoriteMatch) {
59         store.dispatch(WorkbenchActions.loadFavorites());
60     } else if (publicFavoritesMatch) {
61         store.dispatch(WorkbenchActions.loadPublicFavorites());
62     } else if (trashMatch) {
63         store.dispatch(WorkbenchActions.loadTrash());
64     } else if (processMatch) {
65         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
66     } else if (processLogMatch) {
67         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
68     } else if (rootMatch) {
69         store.dispatch(navigateToRootProject);
70     } else if (sharedWithMeMatch) {
71         store.dispatch(WorkbenchActions.loadSharedWithMe);
72     } else if (runProcessMatch) {
73         store.dispatch(WorkbenchActions.loadRunProcess);
74     } else if (workflowMatch) {
75         store.dispatch(WorkbenchActions.loadWorkflow);
76     } else if (searchResultsMatch) {
77         store.dispatch(WorkbenchActions.loadSearchResults);
78     } else if (virtualMachineUserMatch) {
79         store.dispatch(WorkbenchActions.loadVirtualMachines);
80     } else if (virtualMachineAdminMatch) {
81         store.dispatch(WorkbenchActions.loadVirtualMachines);
82     } else if (repositoryMatch) {
83         store.dispatch(WorkbenchActions.loadRepositories);
84     } else if (sshKeysUserMatch) {
85         store.dispatch(WorkbenchActions.loadSshKeys);
86     } else if (sshKeysAdminMatch) {
87         store.dispatch(WorkbenchActions.loadSshKeys);
88     } else if (siteManagerMatch) {
89         store.dispatch(WorkbenchActions.loadSiteManager);
90     } else if (keepServicesMatch) {
91         store.dispatch(WorkbenchActions.loadKeepServices);
92     } else if (computeNodesMatch) {
93         store.dispatch(WorkbenchActions.loadComputeNodes);
94     } else if (apiClientAuthorizationsMatch) {
95         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
96     } else if (myAccountMatch) {
97         store.dispatch(WorkbenchActions.loadMyAccount);
98     } else if (userMatch) {
99         store.dispatch(WorkbenchActions.loadUsers);
100     } else if (groupsMatch) {
101         store.dispatch(WorkbenchActions.loadGroupsPanel);
102     } else if (groupDetailsMatch) {
103         store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
104     } else if (linksMatch) {
105         store.dispatch(WorkbenchActions.loadLinks);
106     } else if (collectionsContentAddressMatch) {
107         store.dispatch(WorkbenchActions.loadCollectionContentAddress);
108     }
109 };