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