Merge branch '13776-update-process-status-calculation'
[arvados-workbench2.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 } from './routes';
8 import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog } from '~/store/workbench/workbench-actions';
9
10 export const addRouteChangeHandlers = (history: History, store: RootStore) => {
11     const handler = handleLocationChange(store);
12     handler(history.location);
13     history.listen(handler);
14 };
15
16 const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
17     const projectMatch = matchProjectRoute(pathname);
18     const collectionMatch = matchCollectionRoute(pathname);
19     const favoriteMatch = matchFavoritesRoute(pathname);
20     const trashMatch = matchTrashRoute(pathname);
21     const processMatch = matchProcessRoute(pathname);
22     const processLogMatch = matchProcessLogRoute(pathname);
23     
24     if (projectMatch) {
25         store.dispatch(loadProject(projectMatch.params.id));
26     } else if (collectionMatch) {
27         store.dispatch(loadCollection(collectionMatch.params.id));
28     } else if (favoriteMatch) {
29         store.dispatch(loadFavorites());
30     } else if (trashMatch) {
31         store.dispatch(loadTrash());
32     } else if (processMatch) {
33         store.dispatch(loadProcess(processMatch.params.id));
34     } else if (processLogMatch) {
35         store.dispatch(loadProcessLog(processLogMatch.params.id));
36     }
37 };