Merge branch '14102-actions-repository'
[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 } 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         }
22         if (uuid === SidePanelTreeCategory.FAVORITES) {
23             dispatch<any>(navigateToFavorites);
24         }
25     };
26
27 export const navigateToFavorites = push(Routes.FAVORITES);
28
29 export const navigateToProject = compose(push, getProjectUrl);
30
31 export const navigateToCollection = compose(push, getCollectionUrl);