1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch, compose, AnyAction } from 'redux';
6 import { push } from "react-router-redux";
7 import { ResourceKind, extractUuidKind } from '~/models/resource';
8 import { SidePanelTreeCategory } from '../side-panel-tree/side-panel-tree-actions';
9 import { Routes, getProcessLogUrl, getGroupUrl, getNavUrl } from '~/routes/routes';
10 import { RootState } from '~/store/store';
11 import { ServiceRepository } from '~/services/services';
12 import { GROUPS_PANEL_LABEL } from '~/store/breadcrumbs/breadcrumbs-actions';
14 export const navigateTo = (uuid: string) =>
15 async (dispatch: Dispatch, getState: () => RootState) => {
16 const kind = extractUuidKind(uuid);
17 if (kind === ResourceKind.PROJECT || kind === ResourceKind.USER || kind === ResourceKind.COLLECTION || kind === ResourceKind.CONTAINER_REQUEST) {
18 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
19 } else if (kind === ResourceKind.VIRTUAL_MACHINE) {
20 dispatch<any>(navigateToAdminVirtualMachines);
22 if (uuid === SidePanelTreeCategory.FAVORITES) {
23 dispatch<any>(navigateToFavorites);
24 } else if (uuid === SidePanelTreeCategory.PUBLIC_FAVORITES) {
25 dispatch(navigateToPublicFavorites);
26 } else if (uuid === SidePanelTreeCategory.SHARED_WITH_ME) {
27 dispatch(navigateToSharedWithMe);
28 } else if (uuid === SidePanelTreeCategory.WORKFLOWS) {
29 dispatch(navigateToWorkflows);
30 } else if (uuid === SidePanelTreeCategory.TRASH) {
31 dispatch(navigateToTrash);
32 } else if (uuid === GROUPS_PANEL_LABEL) {
33 dispatch(navigateToGroups);
37 export const navigateToRoot = push(Routes.ROOT);
39 export const navigateToFavorites = push(Routes.FAVORITES);
41 export const navigateToTrash = push(Routes.TRASH);
43 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
45 export const navigateToWorkflows = push(Routes.WORKFLOWS);
47 export const pushOrGoto = (url: string): AnyAction => {
49 return { type: "noop" };
50 } else if (url[0] === '/') {
53 window.location.href = url;
54 return { type: "noop" };
59 export const navigateToProcessLogs = compose(push, getProcessLogUrl);
61 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
62 const usr = getState().auth.user;
64 dispatch<any>(navigateTo(usr.uuid));
68 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
70 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
72 export const navigateToSearchResults = (searchValue: string) => {
73 if (searchValue !== "") {
74 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
76 return push({ pathname: Routes.SEARCH_RESULTS });
80 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
82 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
84 export const navigateToRepositories = push(Routes.REPOSITORIES);
86 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
88 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
90 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
92 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
94 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
96 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
98 export const navigateToComputeNodes = push(Routes.COMPUTE_NODES);
100 export const navigateToUsers = push(Routes.USERS);
102 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
104 export const navigateToGroups = push(Routes.GROUPS);
106 export const navigateToGroupDetails = compose(push, getGroupUrl);
108 export const navigateToLinks = push(Routes.LINKS);
110 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);