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