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';
12 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
13 const handler = handleLocationChange(store);
14 handler(history.location);
15 history.listen(handler);
18 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
19 const rootMatch = Routes.matchRootRoute(pathname);
20 const projectMatch = Routes.matchProjectRoute(pathname);
21 const collectionMatch = Routes.matchCollectionRoute(pathname);
22 const favoriteMatch = Routes.matchFavoritesRoute(pathname);
23 const trashMatch = Routes.matchTrashRoute(pathname);
24 const processMatch = Routes.matchProcessRoute(pathname);
25 const processLogMatch = Routes.matchProcessLogRoute(pathname);
26 const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
27 const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
28 const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
29 const runProcessMatch = Routes.matchRunProcessRoute(pathname);
30 const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
31 const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
32 const workflowMatch = Routes.matchWorkflowRoute(pathname);
33 const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
34 const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
35 const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
36 const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
37 const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
38 const myAccountMatch = Routes.matchMyAccountRoute(pathname);
39 const userMatch = Routes.matchUsersRoute(pathname);
40 const linksMatch = Routes.matchLinksRoute(pathname);
42 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
45 store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
46 } else if (collectionMatch) {
47 store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
48 } else if (favoriteMatch) {
49 store.dispatch(WorkbenchActions.loadFavorites());
50 } else if (trashMatch) {
51 store.dispatch(WorkbenchActions.loadTrash());
52 } else if (processMatch) {
53 store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
54 } else if (processLogMatch) {
55 store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
56 } else if (rootMatch) {
57 store.dispatch(navigateToRootProject);
58 } else if (sharedWithMeMatch) {
59 store.dispatch(WorkbenchActions.loadSharedWithMe);
60 } else if (runProcessMatch) {
61 store.dispatch(WorkbenchActions.loadRunProcess);
62 } else if (workflowMatch) {
63 store.dispatch(WorkbenchActions.loadWorkflow);
64 } else if (searchResultsMatch) {
65 store.dispatch(WorkbenchActions.loadSearchResults);
66 } else if (virtualMachineUserMatch) {
67 store.dispatch(WorkbenchActions.loadVirtualMachines);
68 } else if (virtualMachineAdminMatch) {
69 store.dispatch(WorkbenchActions.loadVirtualMachines);
70 } else if (repositoryMatch) {
71 store.dispatch(WorkbenchActions.loadRepositories);
72 } else if (sshKeysUserMatch) {
73 store.dispatch(WorkbenchActions.loadSshKeys);
74 } else if (sshKeysAdminMatch) {
75 store.dispatch(WorkbenchActions.loadSshKeys);
76 } else if (keepServicesMatch) {
77 store.dispatch(WorkbenchActions.loadKeepServices);
78 } else if (computeNodesMatch) {
79 store.dispatch(WorkbenchActions.loadComputeNodes);
80 } else if (apiClientAuthorizationsMatch) {
81 store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
82 } else if (myAccountMatch) {
83 store.dispatch(WorkbenchActions.loadMyAccount);
84 } else if (userMatch) {
85 store.dispatch(WorkbenchActions.loadUsers);
86 } else if (linksMatch) {
87 store.dispatch(WorkbenchActions.loadLinks);