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 } 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) =>
24 async (dispatch: Dispatch, getState: () => RootState) => {
26 for (const navToFn of pluginConfig.navigateToHandlers) {
27 if (navToFn(dispatch, getState, uuid)) {
32 const kind = extractUuidKind(uuid);
34 case ResourceKind.PROJECT:
35 case ResourceKind.USER:
36 case ResourceKind.COLLECTION:
37 case ResourceKind.CONTAINER_REQUEST:
38 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
40 case ResourceKind.VIRTUAL_MACHINE:
41 dispatch<any>(navigateToAdminVirtualMachines);
43 case ResourceKind.WORKFLOW:
44 dispatch<any>(pushOrGoto(getNavUrl(uuid, getState().auth)));
45 // dispatch<any>(openDetailsPanel(uuid));
50 case SidePanelTreeCategory.PROJECTS:
51 const usr = getState().auth.user;
53 dispatch<any>(pushOrGoto(getNavUrl(usr.uuid, getState().auth)));
56 case SidePanelTreeCategory.FAVORITES:
57 dispatch<any>(navigateToFavorites);
59 case SidePanelTreeCategory.PUBLIC_FAVORITES:
60 dispatch(navigateToPublicFavorites);
62 case SidePanelTreeCategory.SHARED_WITH_ME:
63 dispatch(navigateToSharedWithMe);
65 case SidePanelTreeCategory.TRASH:
66 dispatch(navigateToTrash);
68 case SidePanelTreeCategory.GROUPS:
69 dispatch(navigateToGroups);
71 case SidePanelTreeCategory.ALL_PROCESSES:
72 dispatch(navigateToAllProcesses);
74 case USERS_PANEL_LABEL:
75 dispatch(navigateToUsers);
77 case MY_ACCOUNT_PANEL_LABEL:
78 dispatch(navigateToMyAccount);
82 dispatch(navigationNotAvailable(uuid));
86 export const navigateToNotFound = push(Routes.NO_MATCH);
88 export const navigateToRoot = push(Routes.ROOT);
90 export const navigateToFavorites = push(Routes.FAVORITES);
92 export const navigateToTrash = push(Routes.TRASH);
94 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
96 export const navigateToWorkflows = push(Routes.WORKFLOWS);
98 export const pushOrGoto = (url: string): AnyAction => {
100 return { type: "noop" };
101 } else if (url[0] === '/') {
104 window.location.href = url;
105 return { type: "noop" };
110 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
111 navigateTo(SidePanelTreeCategory.PROJECTS)(dispatch, getState);
114 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
116 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
118 export const navigateToSearchResults = (searchValue: string) => {
119 if (searchValue !== "") {
120 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
122 return push({ pathname: Routes.SEARCH_RESULTS });
126 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
128 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
130 export const navigateToRepositories = push(Routes.REPOSITORIES);
132 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
134 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
136 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
138 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
140 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
142 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
144 export const navigateToUsers = push(Routes.USERS);
146 export const navigateToUserProfile = compose(push, getUserProfileUrl);
148 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
150 export const navigateToGroups = push(Routes.GROUPS);
152 export const navigateToGroupDetails = compose(push, getGroupUrl);
154 export const navigateToLinks = push(Routes.LINKS);
156 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
158 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);