refs #14312-workflows-inputs-overflow
[arvados.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 { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute } from './routes';
8 import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog } from '~/store/workbench/workbench-actions';
9 import { navigateToRootProject } from '~/store/navigation/navigation-action';
10 import { loadSharedWithMe, loadRunProcess, loadWorkflow } from '../store/workbench/workbench-actions';
11
12 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
13     const handler = handleLocationChange(store);
14     handler(history.location);
15     history.listen(handler);
16 };
17
18 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
19     const rootMatch = matchRootRoute(pathname);
20     const projectMatch = matchProjectRoute(pathname);
21     const collectionMatch = matchCollectionRoute(pathname);
22     const favoriteMatch = matchFavoritesRoute(pathname);
23     const trashMatch = matchTrashRoute(pathname);
24     const processMatch = matchProcessRoute(pathname);
25     const processLogMatch = matchProcessLogRoute(pathname);
26     const sharedWithMeMatch = matchSharedWithMeRoute(pathname);
27     const runProcessMatch = matchRunProcessRoute(pathname);
28     const workflowMatch = matchWorkflowRoute(pathname);
29
30     if (projectMatch) {
31         store.dispatch(loadProject(projectMatch.params.id));
32     } else if (collectionMatch) {
33         store.dispatch(loadCollection(collectionMatch.params.id));
34     } else if (favoriteMatch) {
35         store.dispatch(loadFavorites());
36     } else if (trashMatch) {
37         store.dispatch(loadTrash());
38     } else if (processMatch) {
39         store.dispatch(loadProcess(processMatch.params.id));
40     } else if (processLogMatch) {
41         store.dispatch(loadProcessLog(processLogMatch.params.id));
42     } else if (rootMatch) {
43         store.dispatch(navigateToRootProject);
44     } else if (sharedWithMeMatch) {
45         store.dispatch(loadSharedWithMe);
46     } else if (runProcessMatch) {
47         store.dispatch(loadRunProcess);
48     } else if (workflowMatch) {
49         store.dispatch(loadWorkflow);
50     }
51 };