Merge branch '13540-add-possibility-to-open-files-in-third-party-apps'
[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, getGroupUrl } from '~/routes/routes';
12 import { RootState } from '~/store/store';
13 import { ServiceRepository } from '~/services/services';
14 import { GROUPS_PANEL_LABEL } from '~/store/breadcrumbs/breadcrumbs-actions';
15
16 export const navigateTo = (uuid: string) =>
17     async (dispatch: Dispatch) => {
18         const kind = extractUuidKind(uuid);
19         if (kind === ResourceKind.PROJECT || kind === ResourceKind.USER) {
20             dispatch<any>(navigateToProject(uuid));
21         } else if (kind === ResourceKind.COLLECTION) {
22             dispatch<any>(navigateToCollection(uuid));
23         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
24             dispatch<any>(navigateToProcess(uuid));
25         } else if (kind === ResourceKind.VIRTUAL_MACHINE) {
26             dispatch<any>(navigateToAdminVirtualMachines);
27         }
28         if (uuid === SidePanelTreeCategory.FAVORITES) {
29             dispatch<any>(navigateToFavorites);
30         } else if (uuid === SidePanelTreeCategory.SHARED_WITH_ME) {
31             dispatch(navigateToSharedWithMe);
32         } else if (uuid === SidePanelTreeCategory.WORKFLOWS) {
33             dispatch(navigateToWorkflows);
34         } else if (uuid === SidePanelTreeCategory.TRASH) {
35             dispatch(navigateToTrash);
36         } else if (uuid === GROUPS_PANEL_LABEL) {
37             dispatch(navigateToGroups);
38         }
39     };
40
41 export const navigateToRoot = push(Routes.ROOT);
42
43 export const navigateToFavorites = push(Routes.FAVORITES);
44
45 export const navigateToTrash = push(Routes.TRASH);
46
47 export const navigateToWorkflows = push(Routes.WORKFLOWS);
48
49 export const navigateToProject = compose(push, getProjectUrl);
50
51 export const navigateToCollection = compose(push, getCollectionUrl);
52
53 export const navigateToProcess = compose(push, getProcessUrl);
54
55 export const navigateToProcessLogs = compose(push, getProcessLogUrl);
56
57 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
58     const rootProjectUuid = services.authService.getUuid();
59     if (rootProjectUuid) {
60         dispatch(navigateToProject(rootProjectUuid));
61     }
62 };
63
64 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
65
66 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
67
68 export const navigateToSearchResults = push(Routes.SEARCH_RESULTS);
69
70 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
71
72 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
73
74 export const navigateToRepositories = push(Routes.REPOSITORIES);
75
76 export const navigateToSshKeysAdmin= push(Routes.SSH_KEYS_ADMIN);
77
78 export const navigateToSshKeysUser= push(Routes.SSH_KEYS_USER);
79
80 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
81
82 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
83
84 export const navigateToComputeNodes = push(Routes.COMPUTE_NODES);
85
86 export const navigateToUsers = push(Routes.USERS);
87
88 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
89
90 export const navigateToGroups = push(Routes.GROUPS);
91
92 export const navigateToGroupDetails = compose(push, getGroupUrl);
93
94 export const navigateToLinks = push(Routes.LINKS);