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 R from '~/routes/routes';
8 import * as WA 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 { match } from 'react-router-dom';
14 import { Dispatch } from 'redux';
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 store.dispatch(dialogActions.CLOSE_ALL_DIALOGS());
25 store.dispatch(contextMenuActions.CLOSE_CONTEXT_MENU());
26 store.dispatch(searchBarActions.CLOSE_SEARCH_VIEW());
28 locationChangeHandlers.find(handler => handler(store.dispatch, pathname));
32 type MatchRoute<Params> = (route: string) => match<Params> | null;
33 type ActionCreator<Params> = (params: Params) => void;
35 const handle = <Params>(matchRoute: MatchRoute<Params>, actionCreator: ActionCreator<Params>) =>
36 (dispatch: Dispatch, route: string) => {
37 const match = matchRoute(route);
40 dispatch<any>(actionCreator(match.params)),
46 const locationChangeHandlers = [
49 R.matchApiClientAuthorizationsRoute,
50 () => WA.loadApiClientAuthorizations
54 R.matchCollectionRoute,
55 ({ id }) => WA.loadCollection(id)
59 R.matchComputeNodesRoute,
60 () => WA.loadComputeNodes
64 R.matchFavoritesRoute,
65 () => WA.loadFavorites
69 R.matchGroupDetailsRoute,
70 ({ id }) => WA.loadGroupDetailsPanel(id)
75 () => WA.loadGroupsPanel
79 R.matchKeepServicesRoute,
80 () => WA.loadKeepServices
89 R.matchMyAccountRoute,
90 () => WA.loadMyAccount
94 R.matchProcessLogRoute,
95 ({ id }) => WA.loadProcessLog(id)
100 ({ id }) => WA.loadProcess(id)
105 ({ id }) => WA.loadProject(id)
109 R.matchRepositoriesRoute,
110 () => WA.loadRepositories
115 () => navigateToRootProject
119 R.matchRunProcessRoute,
120 () => WA.loadRunProcess
124 R.matchSearchResultsRoute,
125 () => WA.loadSearchResults
129 R.matchSharedWithMeRoute,
130 () => WA.loadSharedWithMe
134 R.matchSiteManagerRoute,
135 () => WA.loadSiteManager
139 R.matchSshKeysAdminRoute,
144 R.matchSshKeysUserRoute,
159 R.matchAdminVirtualMachineRoute,
160 () => WA.loadVirtualMachines
164 R.matchUserVirtualMachineRoute,
165 () => WA.loadVirtualMachines
169 R.matchWorkflowRoute,
170 () => WA.loadWorkflow