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 { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute, matchSearchResultsRoute, matchSshKeysRoute, matchRepositoriesRoute, matchVirtualMachineRoute } from './routes';
8 import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog, loadSshKeys, loadRepositories, loadVirtualMachines } from '~/store/workbench/workbench-actions';
9 import { navigateToRootProject } from '~/store/navigation/navigation-action';
10 import { loadSharedWithMe, loadRunProcess, loadWorkflow, loadSearchResults } from '~//store/workbench/workbench-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 = matchRootRoute(pathname);
20 const projectMatch = matchProjectRoute(pathname);
21 const collectionMatch = matchCollectionRoute(pathname);
22 const favoriteMatch = matchFavoritesRoute(pathname);
23 const trashMatch = matchTrashRoute(pathname);
24 const processMatch = matchProcessRoute(pathname);
25 const processLogMatch = matchProcessLogRoute(pathname);
26 const repositoryMatch = matchRepositoriesRoute(pathname);
27 const searchResultsMatch = matchSearchResultsRoute(pathname);
28 const sharedWithMeMatch = matchSharedWithMeRoute(pathname);
29 const runProcessMatch = matchRunProcessRoute(pathname);
30 const virtualMachineMatch = matchVirtualMachineRoute(pathname);
31 const workflowMatch = matchWorkflowRoute(pathname);
32 const sshKeysMatch = matchSshKeysRoute(pathname);
35 store.dispatch(loadProject(projectMatch.params.id));
36 } else if (collectionMatch) {
37 store.dispatch(loadCollection(collectionMatch.params.id));
38 } else if (favoriteMatch) {
39 store.dispatch(loadFavorites());
40 } else if (trashMatch) {
41 store.dispatch(loadTrash());
42 } else if (processMatch) {
43 store.dispatch(loadProcess(processMatch.params.id));
44 } else if (processLogMatch) {
45 store.dispatch(loadProcessLog(processLogMatch.params.id));
46 } else if (rootMatch) {
47 store.dispatch(navigateToRootProject);
48 } else if (sharedWithMeMatch) {
49 store.dispatch(loadSharedWithMe);
50 } else if (runProcessMatch) {
51 store.dispatch(loadRunProcess);
52 } else if (workflowMatch) {
53 store.dispatch(loadWorkflow);
54 } else if (searchResultsMatch) {
55 store.dispatch(loadSearchResults);
56 } else if (virtualMachineMatch) {
57 store.dispatch(loadVirtualMachines);
58 } else if(repositoryMatch) {
59 store.dispatch(loadRepositories);
60 } else if (sshKeysMatch) {
61 store.dispatch(loadSshKeys);