Add login in/out handling, fix async validation
[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 import { SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions';
11 import { Routes, getProcessUrl, getProcessLogUrl } from '~/routes/routes';
12 import { RootState } from '~/store/store';
13 import { ServiceRepository } from '~/services/services';
14
15 export const navigateTo = (uuid: string) =>
16     async (dispatch: Dispatch) => {
17         const kind = extractUuidKind(uuid);
18         if (kind === ResourceKind.PROJECT || kind === ResourceKind.USER) {
19             dispatch<any>(navigateToProject(uuid));
20         } else if (kind === ResourceKind.COLLECTION) {
21             dispatch<any>(navigateToCollection(uuid));
22         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
23             dispatch<any>(navigateToProcess(uuid));
24         }
25         if (uuid === SidePanelTreeCategory.FAVORITES) {
26             dispatch<any>(navigateToFavorites);
27         } else if (uuid === SidePanelTreeCategory.SHARED_WITH_ME) {
28             dispatch(navigateToSharedWithMe);
29         } else if (uuid === SidePanelTreeCategory.WORKFLOWS) {
30             dispatch(navigateToWorkflows);
31         } else if (uuid === SidePanelTreeCategory.TRASH) {
32             dispatch(navigateToTrash);
33         }
34     };
35
36 export const navigateToRoot = push(Routes.ROOT);
37
38 export const navigateToFavorites = push(Routes.FAVORITES);
39
40 export const navigateToTrash = push(Routes.TRASH);
41
42 export const navigateToWorkflows = push(Routes.WORKFLOWS);
43
44 export const navigateToProject = compose(push, getProjectUrl);
45
46 export const navigateToCollection = compose(push, getCollectionUrl);
47
48 export const navigateToProcess = compose(push, getProcessUrl);
49
50 export const navigateToProcessLogs = compose(push, getProcessLogUrl);
51
52 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
53     const rootProjectUuid = services.authService.getUuid();
54     if (rootProjectUuid) {
55         dispatch(navigateToProject(rootProjectUuid));
56     }
57 };
58
59 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
60
61 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
62
63 export const navigateToSearchResults = push(Routes.SEARCH_RESULTS);
64
65 export const navigateToVirtualMachines = push(Routes.VIRTUAL_MACHINES);
66
67 export const navigateToRepositories = push(Routes.REPOSITORIES);
68
69 export const navigateToSshKeys= push(Routes.SSH_KEYS);
70
71 export const navigateToSiteManager= push(Routes.SITE_MANAGER);
72
73 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
74
75 export const navigateToComputeNodes = push(Routes.COMPUTE_NODES);