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 { openDetailsPanel } from 'store/details-panel/details-panel-action';
12 import { ServiceRepository } from 'services/services';
13 import { pluginConfig } from 'plugins';
14 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
15 import { USERS_PANEL_LABEL, MY_ACCOUNT_PANEL_LABEL } from 'store/breadcrumbs/breadcrumbs-actions';
17 export const navigationNotAvailable = (id: string) =>
18 snackbarActions.OPEN_SNACKBAR({
19 message: `${id} not available`,
21 kind: SnackbarKind.ERROR
24 export const navigateTo = (uuid: string) =>
25 async (dispatch: Dispatch, getState: () => RootState) => {
27 for (const navToFn of pluginConfig.navigateToHandlers) {
28 if (navToFn(dispatch, getState, uuid)) {
33 const kind = extractUuidKind(uuid);
35 case ResourceKind.PROJECT:
36 case ResourceKind.USER:
37 case ResourceKind.COLLECTION:
38 case ResourceKind.CONTAINER_REQUEST:
39 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
41 case ResourceKind.VIRTUAL_MACHINE:
42 dispatch<any>(navigateToAdminVirtualMachines);
44 case ResourceKind.WORKFLOW:
45 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
46 // dispatch<any>(openDetailsPanel(uuid));
51 case SidePanelTreeCategory.PROJECTS:
52 const usr = getState().auth.user;
54 dispatch<any>(pushOrGoto(getNavUrl(usr.uuid, getState().auth)));
57 case SidePanelTreeCategory.FAVORITES:
58 dispatch<any>(navigateToFavorites);
60 case SidePanelTreeCategory.PUBLIC_FAVORITES:
61 dispatch(navigateToPublicFavorites);
63 case SidePanelTreeCategory.SHARED_WITH_ME:
64 dispatch(navigateToSharedWithMe);
66 case SidePanelTreeCategory.TRASH:
67 dispatch(navigateToTrash);
69 case SidePanelTreeCategory.GROUPS:
70 dispatch(navigateToGroups);
72 case SidePanelTreeCategory.ALL_PROCESSES:
73 dispatch(navigateToAllProcesses);
75 case USERS_PANEL_LABEL:
76 dispatch(navigateToUsers);
78 case MY_ACCOUNT_PANEL_LABEL:
79 dispatch(navigateToMyAccount);
83 dispatch(navigationNotAvailable(uuid));
87 export const navigateToNotFound = push(Routes.NO_MATCH);
89 export const navigateToRoot = push(Routes.ROOT);
91 export const navigateToFavorites = push(Routes.FAVORITES);
93 export const navigateToTrash = push(Routes.TRASH);
95 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
97 export const navigateToWorkflows = push(Routes.WORKFLOWS);
99 export const pushOrGoto = (url: string): AnyAction => {
101 return { type: "noop" };
102 } else if (url[0] === '/') {
105 window.location.href = url;
106 return { type: "noop" };
111 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
112 navigateTo(SidePanelTreeCategory.PROJECTS)(dispatch, getState);
115 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
117 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
119 export const navigateToSearchResults = (searchValue: string) => {
120 if (searchValue !== "") {
121 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
123 return push({ pathname: Routes.SEARCH_RESULTS });
127 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
129 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
131 export const navigateToRepositories = push(Routes.REPOSITORIES);
133 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
135 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
137 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
139 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
141 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
143 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
145 export const navigateToUsers = push(Routes.USERS);
147 export const navigateToUserProfile = compose(push, getUserProfileUrl);
149 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
151 export const navigateToGroups = push(Routes.GROUPS);
153 export const navigateToGroupDetails = compose(push, getGroupUrl);
155 export const navigateToLinks = push(Routes.LINKS);
157 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
159 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);