1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { History, Location } from 'history';
6 import { match } from 'react-router-dom';
7 import { Dispatch } from 'redux';
8 import { ThunkAction } from 'redux-thunk';
9 import { RootStore } from '~/store/store';
10 import * as R from '~/routes/routes';
11 import * as WA from '~/store/workbench/workbench-actions';
12 import { navigateToRootProject } from '~/store/navigation/navigation-action';
13 import { dialogActions } from '~/store/dialog/dialog-actions';
14 import { contextMenuActions } from '~/store/context-menu/context-menu-actions';
15 import { searchBarActions } from '~/store/search-bar/search-bar-actions';
17 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
18 const handler = handleLocationChange(store);
19 handler(history.location);
20 history.listen(handler);
23 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
25 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
26 store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
27 store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
29 locationChangeHandlers.find(handler => handler(store.dispatch, pathname));
33 type MatchRoute<Params> = (route: string) => match<Params> | null;
34 type ActionCreator<Params> = (params: Params) => void;
36 const handle = <Params>(matchRoute: MatchRoute<Params>, actionCreator: ActionCreator<Params>) =>
37 (dispatch: Dispatch, route: string) => {
38 const match = matchRoute(route);
41 dispatch<any>(actionCreator(match.params)),
47 const locationChangeHandlers = [
50 R.matchApiClientAuthorizationsRoute,
51 () => WA.loadApiClientAuthorizations
55 R.matchCollectionRoute,
56 ({ id }) => WA.loadCollection(id)
60 R.matchComputeNodesRoute,
61 () => WA.loadComputeNodes
65 R.matchFavoritesRoute,
66 () => WA.loadFavorites
70 R.matchGroupDetailsRoute,
71 ({ id }) => WA.loadGroupDetailsPanel(id)
76 () => WA.loadGroupsPanel
80 R.matchKeepServicesRoute,
81 () => WA.loadKeepServices
90 R.matchMyAccountRoute,
91 () => WA.loadMyAccount
95 R.matchProcessLogRoute,
96 ({ id }) => WA.loadProcessLog(id)
101 ({ id }) => WA.loadProcess(id)
106 ({ id }) => WA.loadProject(id)
110 R.matchRepositoriesRoute,
111 () => WA.loadRepositories
116 () => navigateToRootProject
120 R.matchRunProcessRoute,
121 () => WA.loadRunProcess
125 R.matchSearchResultsRoute,
126 () => WA.loadSearchResults
130 R.matchSharedWithMeRoute,
131 () => WA.loadSharedWithMe
135 R.matchSiteManagerRoute,
136 () => WA.loadSiteManager
140 R.matchSshKeysAdminRoute,
145 R.matchSshKeysUserRoute,
160 R.matchAdminVirtualMachineRoute,
161 () => WA.loadVirtualMachines
165 R.matchUserVirtualMachineRoute,
166 () => WA.loadVirtualMachines
170 R.matchWorkflowRoute,
171 () => WA.loadWorkflow