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, getGroupUrl, getNavUrl, getUserProfileUrl } from "routes/routes";
10 import { RootState } from "store/store";
11 import { ServiceRepository } from "services/services";
12 import { pluginConfig } from "plugins";
13 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
14 import { USERS_PANEL_LABEL, MY_ACCOUNT_PANEL_LABEL, INSTANCE_TYPES_PANEL_LABEL, VIRTUAL_MACHINES_USER_PANEL_LABEL, VIRTUAL_MACHINES_ADMIN_PANEL_LABEL, REPOSITORIES_PANEL_LABEL } from "store/breadcrumbs/breadcrumbs-actions";
16 export const navigationNotAvailable = (id: string) =>
17 snackbarActions.OPEN_SNACKBAR({
18 message: `${id} not available`,
20 kind: SnackbarKind.ERROR,
23 export const navigateTo = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState) => {
24 for (const navToFn of pluginConfig.navigateToHandlers) {
25 if (navToFn(dispatch, getState, uuid)) {
30 const kind = extractUuidKind(uuid);
32 case ResourceKind.PROJECT:
33 case ResourceKind.USER:
34 case ResourceKind.COLLECTION:
35 case ResourceKind.CONTAINER_REQUEST:
36 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
38 case ResourceKind.VIRTUAL_MACHINE:
39 dispatch<any>(navigateToAdminVirtualMachines);
41 case ResourceKind.WORKFLOW:
42 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
43 // dispatch<any>(openDetailsPanel(uuid));
48 case SidePanelTreeCategory.PROJECTS:
49 const usr = getState().auth.user;
51 dispatch<any>(pushOrGoto(getNavUrl(usr.uuid, getState().auth)));
54 case SidePanelTreeCategory.FAVORITES:
55 dispatch<any>(navigateToFavorites);
57 case SidePanelTreeCategory.PUBLIC_FAVORITES:
58 dispatch(navigateToPublicFavorites);
60 case SidePanelTreeCategory.SHARED_WITH_ME:
61 dispatch(navigateToSharedWithMe);
63 case SidePanelTreeCategory.TRASH:
64 dispatch(navigateToTrash);
66 case SidePanelTreeCategory.GROUPS:
67 dispatch(navigateToGroups);
69 case SidePanelTreeCategory.ALL_PROCESSES:
70 dispatch(navigateToAllProcesses);
72 case SidePanelTreeCategory.SHELL_ACCESS:
73 dispatch(navigateToUserVirtualMachines)
75 case USERS_PANEL_LABEL:
76 dispatch(navigateToUsers);
78 case MY_ACCOUNT_PANEL_LABEL:
79 dispatch(navigateToMyAccount);
81 case INSTANCE_TYPES_PANEL_LABEL:
82 dispatch(navigateToInstanceTypes);
84 case VIRTUAL_MACHINES_USER_PANEL_LABEL:
85 dispatch(navigateToUserVirtualMachines);
87 case VIRTUAL_MACHINES_ADMIN_PANEL_LABEL:
88 dispatch(navigateToAdminVirtualMachines);
90 case REPOSITORIES_PANEL_LABEL:
91 dispatch(navigateToRepositories);
95 dispatch(navigationNotAvailable(uuid));
98 export const navigateToNotFound = push(Routes.NO_MATCH);
100 export const navigateToRoot = push(Routes.ROOT);
102 export const navigateToFavorites = push(Routes.FAVORITES);
104 export const navigateToTrash = push(Routes.TRASH);
106 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
108 export const navigateToWorkflows = push(Routes.WORKFLOWS);
110 export const pushOrGoto = (url: string): AnyAction => {
112 return { type: "noop" };
113 } else if (url[0] === "/") {
116 window.location.href = url;
117 return { type: "noop" };
121 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
122 navigateTo(SidePanelTreeCategory.PROJECTS)(dispatch, getState);
125 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
127 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
129 export const navigateToSearchResults = (searchValue: string) => {
130 if (searchValue !== "") {
131 return push({ pathname: Routes.SEARCH_RESULTS, search: "?q=" + encodeURIComponent(searchValue) });
133 return push({ pathname: Routes.SEARCH_RESULTS });
137 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
139 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
141 export const navigateToRepositories = push(Routes.REPOSITORIES);
143 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
145 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
147 export const navigateToInstanceTypes = push(Routes.INSTANCE_TYPES);
149 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
151 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
153 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
155 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
157 export const navigateToUsers = push(Routes.USERS);
159 export const navigateToUserProfile = compose(push, getUserProfileUrl);
161 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
163 export const navigateToGroups = push(Routes.GROUPS);
165 export const navigateToGroupDetails = compose(push, getGroupUrl);
167 export const navigateToLinks = push(Routes.LINKS);
169 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
171 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);