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);
18 case ResourceKind.PROJECT:
19 case ResourceKind.USER:
20 case ResourceKind.COLLECTION:
21 case ResourceKind.CONTAINER_REQUEST:
22 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
24 case ResourceKind.VIRTUAL_MACHINE:
25 dispatch<any>(navigateToAdminVirtualMachines);
30 case SidePanelTreeCategory.FAVORITES:
31 dispatch<any>(navigateToFavorites);
33 case SidePanelTreeCategory.PUBLIC_FAVORITES:
34 dispatch(navigateToPublicFavorites);
36 case SidePanelTreeCategory.SHARED_WITH_ME:
37 dispatch(navigateToSharedWithMe);
39 case SidePanelTreeCategory.WORKFLOWS:
40 dispatch(navigateToWorkflows);
42 case SidePanelTreeCategory.TRASH:
43 dispatch(navigateToTrash);
45 case GROUPS_PANEL_LABEL:
46 dispatch(navigateToGroups);
48 case SidePanelTreeCategory.ALL_PROCESSES:
49 dispatch(navigateToAllProcesses);
54 export const navigateToNotFound = push(Routes.NO_MATCH);
56 export const navigateToRoot = push(Routes.ROOT);
58 export const navigateToFavorites = push(Routes.FAVORITES);
60 export const navigateToTrash = push(Routes.TRASH);
62 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
64 export const navigateToWorkflows = push(Routes.WORKFLOWS);
66 export const pushOrGoto = (url: string): AnyAction => {
68 return { type: "noop" };
69 } else if (url[0] === '/') {
72 window.location.href = url;
73 return { type: "noop" };
78 export const navigateToProcessLogs = compose(push, getProcessLogUrl);
80 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
81 const usr = getState().auth.user;
83 dispatch<any>(navigateTo(usr.uuid));
87 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
89 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
91 export const navigateToSearchResults = (searchValue: string) => {
92 if (searchValue !== "") {
93 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
95 return push({ pathname: Routes.SEARCH_RESULTS });
99 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
101 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
103 export const navigateToRepositories = push(Routes.REPOSITORIES);
105 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
107 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
109 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
111 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
113 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
115 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
117 export const navigateToComputeNodes = push(Routes.COMPUTE_NODES);
119 export const navigateToUsers = push(Routes.USERS);
121 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
123 export const navigateToGroups = push(Routes.GROUPS);
125 export const navigateToGroupDetails = compose(push, getGroupUrl);
127 export const navigateToLinks = push(Routes.LINKS);
129 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
131 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);