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';
15 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
16 const handler = handleLocationChange(store);
17 handler(history.location);
18 history.listen(handler);
21 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
23 const rootMatch = Routes.matchRootRoute(pathname);
24 const projectMatch = Routes.matchProjectRoute(pathname);
25 const collectionMatch = Routes.matchCollectionRoute(pathname);
26 const favoriteMatch = Routes.matchFavoritesRoute(pathname);
27 const publicFavoritesMatch = Routes.matchPublicFavoritesRoute(pathname);
28 const trashMatch = Routes.matchTrashRoute(pathname);
29 const processMatch = Routes.matchProcessRoute(pathname);
30 const repositoryMatch = Routes.matchRepositoriesRoute(pathname);
31 const searchResultsMatch = Routes.matchSearchResultsRoute(pathname);
32 const sharedWithMeMatch = Routes.matchSharedWithMeRoute(pathname);
33 const runProcessMatch = Routes.matchRunProcessRoute(pathname);
34 const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname);
35 const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname);
36 const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname);
37 const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname);
38 const siteManagerMatch = Routes.matchSiteManagerRoute(pathname);
39 const keepServicesMatch = Routes.matchKeepServicesRoute(pathname);
40 const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname);
41 const myAccountMatch = Routes.matchMyAccountRoute(pathname);
42 const linkAccountMatch = Routes.matchLinkAccountRoute(pathname);
43 const usersMatch = Routes.matchUsersRoute(pathname);
44 const userProfileMatch = Routes.matchUserProfileRoute(pathname);
45 const groupsMatch = Routes.matchGroupsRoute(pathname);
46 const groupDetailsMatch = Routes.matchGroupDetailsRoute(pathname);
47 const linksMatch = Routes.matchLinksRoute(pathname);
48 const collectionsContentAddressMatch = Routes.matchCollectionsContentAddressRoute(pathname);
49 const allProcessesMatch = Routes.matchAllProcessesRoute(pathname);
50 const registeredWorkflowMatch = Routes.matchRegisteredWorkflowRoute(pathname);
52 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
53 store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
54 store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
56 for (const locChangeFn of pluginConfig.locationChangeHandlers) {
57 if (locChangeFn(store, pathname)) {
63 store.dispatch(WorkbenchActions.loadProject(projectMatch.params.id));
64 } else if (collectionMatch) {
65 store.dispatch(WorkbenchActions.loadCollection(collectionMatch.params.id));
66 } else if (favoriteMatch) {
67 store.dispatch(WorkbenchActions.loadFavorites());
68 } else if (publicFavoritesMatch) {
69 store.dispatch(WorkbenchActions.loadPublicFavorites());
70 } else if (trashMatch) {
71 store.dispatch(WorkbenchActions.loadTrash());
72 } else if (processMatch) {
73 store.dispatch(WorkbenchActions.loadProcess(processMatch.params.id));
74 } else if (rootMatch) {
75 store.dispatch(navigateToRootProject);
76 } else if (sharedWithMeMatch) {
77 store.dispatch(WorkbenchActions.loadSharedWithMe);
78 } else if (runProcessMatch) {
79 store.dispatch(WorkbenchActions.loadRunProcess);
80 } else if (searchResultsMatch) {
81 store.dispatch(WorkbenchActions.loadSearchResults);
82 } else if (virtualMachineUserMatch) {
83 store.dispatch(WorkbenchActions.loadVirtualMachines);
84 } else if (virtualMachineAdminMatch) {
85 store.dispatch(WorkbenchActions.loadVirtualMachinesAdmin);
86 } else if (repositoryMatch) {
87 store.dispatch(WorkbenchActions.loadRepositories);
88 } else if (sshKeysUserMatch) {
89 store.dispatch(WorkbenchActions.loadSshKeys);
90 } else if (sshKeysAdminMatch) {
91 store.dispatch(WorkbenchActions.loadSshKeys);
92 } else if (siteManagerMatch) {
93 store.dispatch(WorkbenchActions.loadSiteManager);
94 } else if (keepServicesMatch) {
95 store.dispatch(WorkbenchActions.loadKeepServices);
96 } else if (apiClientAuthorizationsMatch) {
97 store.dispatch(WorkbenchActions.loadApiClientAuthorizations);
98 } else if (myAccountMatch) {
99 store.dispatch(WorkbenchActions.loadUserProfile());
100 } else if (linkAccountMatch) {
101 store.dispatch(WorkbenchActions.loadLinkAccount);
102 } else if (usersMatch) {
103 store.dispatch(WorkbenchActions.loadUsers);
104 } else if (userProfileMatch) {
105 store.dispatch(WorkbenchActions.loadUserProfile(userProfileMatch.params.id));
106 } else if (groupsMatch) {
107 store.dispatch(WorkbenchActions.loadGroupsPanel);
108 } else if (groupDetailsMatch) {
109 store.dispatch(WorkbenchActions.loadGroupDetailsPanel(groupDetailsMatch.params.id));
110 } else if (linksMatch) {
111 store.dispatch(WorkbenchActions.loadLinks);
112 } else if (collectionsContentAddressMatch) {
113 store.dispatch(WorkbenchActions.loadCollectionContentAddress);
114 } else if (allProcessesMatch) {
115 store.dispatch(WorkbenchActions.loadAllProcesses());
116 } else if (registeredWorkflowMatch) {
117 store.dispatch(WorkbenchActions.loadRegisteredWorkflow(registeredWorkflowMatch.params.id));