1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
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);
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);
41 export const navigateToRoot = push(Routes.ROOT);
43 export const navigateToFavorites = push(Routes.FAVORITES);
45 export const navigateToTrash = push(Routes.TRASH);
47 export const navigateToWorkflows = push(Routes.WORKFLOWS);
49 export const navigateToProject = compose(push, getProjectUrl);
51 export const navigateToCollection = compose(push, getCollectionUrl);
53 export const navigateToProcess = compose(push, getProcessUrl);
55 export const navigateToProcessLogs = compose(push, getProcessLogUrl);
57 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
58 const rootProjectUuid = services.authService.getUuid();
59 if (rootProjectUuid) {
60 dispatch(navigateToProject(rootProjectUuid));
64 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
66 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
68 export const navigateToSearchResults = push(Routes.SEARCH_RESULTS);
70 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
72 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
74 export const navigateToRepositories = push(Routes.REPOSITORIES);
76 export const navigateToSshKeysAdmin= push(Routes.SSH_KEYS_ADMIN);
78 export const navigateToSshKeysUser= push(Routes.SSH_KEYS_USER);
80 export const navigateToSiteManager= push(Routes.SITE_MANAGER);
82 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
84 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
86 export const navigateToComputeNodes = push(Routes.COMPUTE_NODES);
88 export const navigateToUsers = push(Routes.USERS);
90 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
92 export const navigateToGroups = push(Routes.GROUPS);
94 export const navigateToGroupDetails = compose(push, getGroupUrl);
96 export const navigateToLinks = push(Routes.LINKS);