conflicts
[arvados-workbench2.git] / src / routes / route-change-handlers.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { History, Location } from 'history';
6 import { RootStore } from '~/store/store';
7 import {
8     matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute,
9     matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute,
10     matchSearchResultsRoute, matchSshKeysRoute, matchRepositoriesRoute, matchVirtualMachineRoute,
11     matchKeepServicesRoute
12 } from './routes';
13 import {
14     loadSharedWithMe, loadRunProcess, loadWorkflow, loadSearchResults,
15     loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog,
16     loadSshKeys, loadRepositories, loadVirtualMachines, loadKeepServices
17 } from '~/store/workbench/workbench-actions';
18 import { navigateToRootProject } from '~/store/navigation/navigation-action';
19
20 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
21     const handler = handleLocationChange(store);
22     handler(history.location);
23     history.listen(handler);
24 };
25
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
43     if (projectMatch) {
44         store.dispatch(loadProject(projectMatch.params.id));
45     } else if (collectionMatch) {
46         store.dispatch(loadCollection(collectionMatch.params.id));
47     } else if (favoriteMatch) {
48         store.dispatch(loadFavorites());
49     } else if (trashMatch) {
50         store.dispatch(loadTrash());
51     } else if (processMatch) {
52         store.dispatch(loadProcess(processMatch.params.id));
53     } else if (processLogMatch) {
54         store.dispatch(loadProcessLog(processLogMatch.params.id));
55     } else if (rootMatch) {
56         store.dispatch(navigateToRootProject);
57     } else if (sharedWithMeMatch) {
58         store.dispatch(loadSharedWithMe);
59     } else if (runProcessMatch) {
60         store.dispatch(loadRunProcess);
61     } else if (workflowMatch) {
62         store.dispatch(loadWorkflow);
63     } else if (searchResultsMatch) {
64         store.dispatch(loadSearchResults);
65     } else if (virtualMachineMatch) {
66         store.dispatch(loadVirtualMachines);
67     } else if(repositoryMatch) {
68         store.dispatch(loadRepositories);
69     } else if (sshKeysMatch) {
70         store.dispatch(loadSshKeys);
71     } else if (keepServicesMatch) {
72         store.dispatch(loadKeepServices);
73     }
74 };