created-admin-menu-and-extracted-virtual-machines-to-separated-components
[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 * as Routes from '~/routes/routes';
8 import * as WorkbenchActions from '~/store/workbench/workbench-actions';
9 import { navigateToRootProject } from '~/store/navigation/navigation-action';
10
11 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
12     const handler = handleLocationChange(store);
13     handler(history.location);
14     history.listen(handler);
15 };
16
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 virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
30     const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
31     const workflowMatch = Routes.matchWorkflowRoute(pathname);
32     const sshKeysMatch = Routes.matchSshKeysRoute(pathname);
33     const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
34     const computeNodesMatch = Routes.matchComputeNodesRoute(pathname);
35     const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
36     const myAccountMatch = Routes.matchMyAccountRoute(pathname);
37     const userMatch = Routes.matchUsersRoute(pathname);
38
39     if (projectMatch) {
40         store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
41     } else if (collectionMatch) {
42         store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
43     } else if (favoriteMatch) {
44         store.dispatch(WorkbenchActions.loadFavorites());
45     } else if (trashMatch) {
46         store.dispatch(WorkbenchActions.loadTrash());
47     } else if (processMatch) {
48         store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
49     } else if (processLogMatch) {
50         store.dispatch(WorkbenchActions.loadProcessLog(processLogMatch.params.id));
51     } else if (rootMatch) {
52         store.dispatch(navigateToRootProject);
53     } else if (sharedWithMeMatch) {
54         store.dispatch(WorkbenchActions.loadSharedWithMe);
55     } else if (runProcessMatch) {
56         store.dispatch(WorkbenchActions.loadRunProcess);
57     } else if (workflowMatch) {
58         store.dispatch(WorkbenchActions.loadWorkflow);
59     } else if (searchResultsMatch) {
60         store.dispatch(WorkbenchActions.loadSearchResults);
61     } else if (virtualMachineUserMatch) {
62         store.dispatch(WorkbenchActions.loadVirtualMachines);
63     } else if (virtualMachineAdminMatch) {
64         store.dispatch(WorkbenchActions.loadVirtualMachines);
65     } else if (repositoryMatch) {
66         store.dispatch(WorkbenchActions.loadRepositories);
67     } else if (sshKeysMatch) {
68         store.dispatch(WorkbenchActions.loadSshKeys);
69     } else if (keepServicesMatch) {
70         store.dispatch(WorkbenchActions.loadKeepServices);
71     } else if (computeNodesMatch) {
72         store.dispatch(WorkbenchActions.loadComputeNodes);
73     } else if (apiClientAuthorizationsMatch) {
74         store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
75     } else if (myAccountMatch) {
76         store.dispatch(WorkbenchActions.loadMyAccount);
77     } else if (userMatch) {
78         store.dispatch(WorkbenchActions.loadUsers);
79     }
80 };