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';
11 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
12 const handler = handleLocationChange(store);
13 handler(history.location);
14 history.listen(handler);
17 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
18 const rootMatch = Routes.matchRootRoute(pathname);
19 const projectMatch = Routes.matchProjectRoute(pathname);
20 const collectionMatch = Routes.matchCollectionRoute(pathname);
21 const favoriteMatch = Routes.matchFavoritesRoute(pathname);
22 const trashMatch = Routes.matchTrashRoute(pathname);
23 const processMatch = Routes.matchProcessRoute(pathname);
24 const processLogMatch = Routes.matchProcessLogRoute(pathname);
25 const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
26 const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
27 const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
28 const runProcessMatch = Routes.matchRunProcessRoute(pathname);
29 const virtualMachineMatch = Routes.matchVirtualMachineRoute(pathname);
30 const workflowMatch = Routes.matchWorkflowRoute(pathname);
31 const sshKeysMatch = Routes.matchSshKeysRoute(pathname);
32 const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
33 const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
34 const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
35 const myAccountMatch = Routes.matchMyAccountRoute(pathname);
36 const userMatch = Routes.matchUsersRoute(pathname);
39 store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
40 } else if (collectionMatch) {
41 store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
42 } else if (favoriteMatch) {
43 store.dispatch(WorkbenchActions.loadFavorites());
44 } else if (trashMatch) {
45 store.dispatch(WorkbenchActions.loadTrash());
46 } else if (processMatch) {
47 store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
48 } else if (processLogMatch) {
49 store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
50 } else if (rootMatch) {
51 store.dispatch(navigateToRootProject);
52 } else if (sharedWithMeMatch) {
53 store.dispatch(WorkbenchActions.loadSharedWithMe);
54 } else if (runProcessMatch) {
55 store.dispatch(WorkbenchActions.loadRunProcess);
56 } else if (workflowMatch) {
57 store.dispatch(WorkbenchActions.loadWorkflow);
58 } else if (searchResultsMatch) {
59 store.dispatch(WorkbenchActions.loadSearchResults);
60 } else if (virtualMachineMatch) {
61 store.dispatch(WorkbenchActions.loadVirtualMachines);
62 } else if(repositoryMatch) {
63 store.dispatch(WorkbenchActions.loadRepositories);
64 } else if (sshKeysMatch) {
65 store.dispatch(WorkbenchActions.loadSshKeys);
66 } else if (keepServicesMatch) {
67 store.dispatch(WorkbenchActions.loadKeepServices);
68 } else if (computeNodesMatch) {
69 store.dispatch(WorkbenchActions.loadComputeNodes);
70 } else if (apiClientAuthorizationsMatch) {
71 store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
72 } else if (myAccountMatch) {
73 store.dispatch(WorkbenchActions.loadMyAccount);
74 }else if (userMatch) {
75 store.dispatch(WorkbenchActions.loadUsers);