1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
14 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
15 const handler = handleLocationChange(store);
16 handler(history.location);
17 history.listen(handler);
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 keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
38 const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
39 const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
40 const myAccountMatch = Routes.matchMyAccountRoute(pathname);
41 const userMatch = Routes.matchUsersRoute(pathname);
42 const linksMatch = Routes.matchLinksRoute(pathname);
44 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
45 store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
46 store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
49 store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
50 } else if (collectionMatch) {
51 store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
52 } else if (favoriteMatch) {
53 store.dispatch(WorkbenchActions.loadFavorites());
54 } else if (trashMatch) {
55 store.dispatch(WorkbenchActions.loadTrash());
56 } else if (processMatch) {
57 store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
58 } else if (processLogMatch) {
59 store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
60 } else if (rootMatch) {
61 store.dispatch(navigateToRootProject);
62 } else if (sharedWithMeMatch) {
63 store.dispatch(WorkbenchActions.loadSharedWithMe);
64 } else if (runProcessMatch) {
65 store.dispatch(WorkbenchActions.loadRunProcess);
66 } else if (workflowMatch) {
67 store.dispatch(WorkbenchActions.loadWorkflow);
68 } else if (searchResultsMatch) {
69 store.dispatch(WorkbenchActions.loadSearchResults);
70 } else if (virtualMachineUserMatch) {
71 store.dispatch(WorkbenchActions.loadVirtualMachines);
72 } else if (virtualMachineAdminMatch) {
73 store.dispatch(WorkbenchActions.loadVirtualMachines);
74 } else if (repositoryMatch) {
75 store.dispatch(WorkbenchActions.loadRepositories);
76 } else if (sshKeysUserMatch) {
77 store.dispatch(WorkbenchActions.loadSshKeys);
78 } else if (sshKeysAdminMatch) {
79 store.dispatch(WorkbenchActions.loadSshKeys);
80 } else if (keepServicesMatch) {
81 store.dispatch(WorkbenchActions.loadKeepServices);
82 } else if (computeNodesMatch) {
83 store.dispatch(WorkbenchActions.loadComputeNodes);
84 } else if (apiClientAuthorizationsMatch) {
85 store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
86 } else if (myAccountMatch) {
87 store.dispatch(WorkbenchActions.loadMyAccount);
88 } else if (userMatch) {
89 store.dispatch(WorkbenchActions.loadUsers);
90 } else if (linksMatch) {
91 store.dispatch(WorkbenchActions.loadLinks);