Merge branch '17337-files-not-visible-in-arvados'
[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
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 linkAccountMatch = Routes.matchLinkAccountRoute(pathname);
45     const userMatch = Routes.matchUsersRoute(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
52     store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
53     store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
54     store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
55
56     if (projectMatch) {
57         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
58     } else if (collectionMatch) {
59         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
60     } else if (favoriteMatch) {
61         store.dispatch(WorkbenchActions.loadFavorites());
62     } else if (publicFavoritesMatch) {
63         store.dispatch(WorkbenchActions.loadPublicFavorites());
64     } else if (trashMatch) {
65         store.dispatch(WorkbenchActions.loadTrash());
66     } else if (processMatch) {
67         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
68     } else if (processLogMatch) {
69         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
70     } else if (rootMatch) {
71         store.dispatch(navigateToRootProject);
72     } else if (sharedWithMeMatch) {
73         store.dispatch(WorkbenchActions.loadSharedWithMe);
74     } else if (runProcessMatch) {
75         store.dispatch(WorkbenchActions.loadRunProcess);
76     } else if (workflowMatch) {
77         store.dispatch(WorkbenchActions.loadWorkflow);
78     } else if (searchResultsMatch) {
79         store.dispatch(WorkbenchActions.loadSearchResults);
80     } else if (virtualMachineUserMatch) {
81         store.dispatch(WorkbenchActions.loadVirtualMachines);
82     } else if (virtualMachineAdminMatch) {
83         store.dispatch(WorkbenchActions.loadVirtualMachines);
84     } else if (repositoryMatch) {
85         store.dispatch(WorkbenchActions.loadRepositories);
86     } else if (sshKeysUserMatch) {
87         store.dispatch(WorkbenchActions.loadSshKeys);
88     } else if (sshKeysAdminMatch) {
89         store.dispatch(WorkbenchActions.loadSshKeys);
90     } else if (siteManagerMatch) {
91         store.dispatch(WorkbenchActions.loadSiteManager);
92     } else if (keepServicesMatch) {
93         store.dispatch(WorkbenchActions.loadKeepServices);
94     } else if (computeNodesMatch) {
95         store.dispatch(WorkbenchActions.loadComputeNodes);
96     } else if (apiClientAuthorizationsMatch) {
97         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
98     } else if (myAccountMatch) {
99         store.dispatch(WorkbenchActions.loadMyAccount);
100     } else if (linkAccountMatch) {
101         store.dispatch(WorkbenchActions.loadLinkAccount);
102     } else if (userMatch) {
103         store.dispatch(WorkbenchActions.loadUsers);
104     } else if (groupsMatch) {
105         store.dispatch(WorkbenchActions.loadGroupsPanel);
106     } else if (groupDetailsMatch) {
107         store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
108     } else if (linksMatch) {
109         store.dispatch(WorkbenchActions.loadLinks);
110     } else if (collectionsContentAddressMatch) {
111         store.dispatch(WorkbenchActions.loadCollectionContentAddress);
112     } else if (allProcessesMatch) {
113         store.dispatch(WorkbenchActions.loadAllProcesses());
114     }
115 };