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 * as Routes from 'routes/routes';
8 import * as WorkbenchActions from 'store/workbench/workbench-actions';
9 import { navigateToRootProject } from 'store/navigation/navigation-action';
10 import { dialogActions } from 'store/dialog/dialog-actions';
11 import { contextMenuActions } from 'store/context-menu/context-menu-actions';
12 import { searchBarActions } from 'store/search-bar/search-bar-actions';
13 import { pluginConfig } from 'plugins';
14 import { openProjectPanel } from 'store/project-panel/project-panel-action';
16 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
17 const handler = handleLocationChange(store);
18 handler(history.location);
19 history.listen(handler);
22 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
24 const rootMatch = Routes.matchRootRoute(pathname);
25 const projectMatch = Routes.matchProjectRoute(pathname);
26 const collectionMatch = Routes.matchCollectionRoute(pathname);
27 const favoriteMatch = Routes.matchFavoritesRoute(pathname);
28 const publicFavoritesMatch = Routes.matchPublicFavoritesRoute(pathname);
29 const trashMatch = Routes.matchTrashRoute(pathname);
30 const processMatch = Routes.matchProcessRoute(pathname);
31 const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
32 const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
33 const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
34 const runProcessMatch = Routes.matchRunProcessRoute(pathname);
35 const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
36 const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
37 const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
38 const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
39 const instanceTypesMatch = Routes.matchInstanceTypesRoute(pathname);
40 const siteManagerMatch = Routes.matchSiteManagerRoute(pathname);
41 const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
42 const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
43 const myAccountMatch = Routes.matchMyAccountRoute(pathname);
44 const linkAccountMatch = Routes.matchLinkAccountRoute(pathname);
45 const usersMatch = Routes.matchUsersRoute(pathname);
46 const userProfileMatch = Routes.matchUserProfileRoute(pathname);
47 const groupsMatch = Routes.matchGroupsRoute(pathname);
48 const groupDetailsMatch = Routes.matchGroupDetailsRoute(pathname);
49 const linksMatch = Routes.matchLinksRoute(pathname);
50 const collectionsContentAddressMatch = Routes.matchCollectionsContentAddressRoute(pathname);
51 const allProcessesMatch = Routes.matchAllProcessesRoute(pathname);
52 const registeredWorkflowMatch = Routes.matchRegisteredWorkflowRoute(pathname);
54 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
55 store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
56 store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
58 for (const locChangeFn of pluginConfig.locationChangeHandlers) {
59 if (locChangeFn(store, pathname)) {
64 document.title = `Arvados (${store.getState().auth.config.uuidPrefix}) - ${pathname.slice(1)}`;
67 store.dispatch(openProjectPanel(projectMatch.params.id));
68 } else if (collectionMatch) {
69 store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
70 } else if (favoriteMatch) {
71 store.dispatch(WorkbenchActions.loadFavorites());
72 } else if (publicFavoritesMatch) {
73 store.dispatch(WorkbenchActions.loadPublicFavorites());
74 } else if (trashMatch) {
75 store.dispatch(WorkbenchActions.loadTrash());
76 } else if (processMatch) {
77 store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
78 } else if (rootMatch) {
79 store.dispatch(navigateToRootProject);
80 } else if (sharedWithMeMatch) {
81 store.dispatch(WorkbenchActions.loadSharedWithMe);
82 } else if (runProcessMatch) {
83 store.dispatch(WorkbenchActions.loadRunProcess);
84 } else if (searchResultsMatch) {
85 store.dispatch(WorkbenchActions.loadSearchResults);
86 } else if (virtualMachineUserMatch) {
87 store.dispatch(WorkbenchActions.loadVirtualMachines);
88 } else if (virtualMachineAdminMatch) {
89 store.dispatch(WorkbenchActions.loadVirtualMachinesAdmin);
90 } else if (repositoryMatch) {
91 store.dispatch(WorkbenchActions.loadRepositories);
92 } else if (sshKeysUserMatch) {
93 store.dispatch(WorkbenchActions.loadSshKeys);
94 } else if (sshKeysAdminMatch) {
95 store.dispatch(WorkbenchActions.loadSshKeys);
96 } else if (instanceTypesMatch) {
97 store.dispatch(WorkbenchActions.loadInstanceTypes);
98 } else if (siteManagerMatch) {
99 store.dispatch(WorkbenchActions.loadSiteManager);
100 } else if (keepServicesMatch) {
101 store.dispatch(WorkbenchActions.loadKeepServices);
102 } else if (apiClientAuthorizationsMatch) {
103 store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
104 } else if (myAccountMatch) {
105 store.dispatch(WorkbenchActions.loadUserProfile());
106 } else if (linkAccountMatch) {
107 store.dispatch(WorkbenchActions.loadLinkAccount);
108 } else if (usersMatch) {
109 store.dispatch(WorkbenchActions.loadUsers);
110 } else if (userProfileMatch) {
111 store.dispatch(WorkbenchActions.loadUserProfile(userProfileMatch.params.id));
112 } else if (groupsMatch) {
113 store.dispatch(WorkbenchActions.loadGroupsPanel);
114 } else if (groupDetailsMatch) {
115 store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
116 } else if (linksMatch) {
117 store.dispatch(WorkbenchActions.loadLinks);
118 } else if (collectionsContentAddressMatch) {
119 store.dispatch(WorkbenchActions.loadCollectionContentAddress);
120 } else if (allProcessesMatch) {
121 store.dispatch(WorkbenchActions.loadAllProcesses());
122 } else if (registeredWorkflowMatch) {
123 store.dispatch(WorkbenchActions.loadRegisteredWorkflow(registeredWorkflowMatch.params.id));