refs #13828 Merge branch 'origin/13828-trash-view'
[arvados-workbench2.git] / src / store / navigation / navigation-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch, compose } from 'redux';
6 import { push } from "react-router-redux";
7 import { ResourceKind, extractUuidKind } from '~/models/resource';
8 import { getCollectionUrl } from "~/models/collection";
9 import { getProjectUrl } from "~/models/project";
10
11 import { SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions';
12 import { Routes, getProcessUrl, getProcessLogUrl } from '~/routes/routes';
13
14 export const navigateTo = (uuid: string) =>
15     async (dispatch: Dispatch) => {
16         const kind = extractUuidKind(uuid);
17         if (kind === ResourceKind.PROJECT || kind === ResourceKind.USER) {
18             dispatch<any>(navigateToProject(uuid));
19         } else if (kind === ResourceKind.COLLECTION) {
20             dispatch<any>(navigateToCollection(uuid));
21         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
22             dispatch<any>(navigateToProcess(uuid));
23         } 
24         if (uuid === SidePanelTreeCategory.FAVORITES) {
25             dispatch<any>(navigateToFavorites);
26         }
27     };
28
29 export const navigateToFavorites = push(Routes.FAVORITES);
30
31 export const navigateToTrash = push(Routes.TRASH);
32
33 export const navigateToProject = compose(push, getProjectUrl);
34
35 export const navigateToCollection = compose(push, getCollectionUrl);
36
37 export const navigateToProcess = compose(push, getProcessUrl);
38
39 export const navigateToProcessLogs = compose(push, getProcessLogUrl);