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