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 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>(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.WORKFLOWS:
66 dispatch(navigateToWorkflows);
68 case SidePanelTreeCategory.TRASH:
69 dispatch(navigateToTrash);
71 case SidePanelTreeCategory.GROUPS:
72 dispatch(navigateToGroups);
74 case SidePanelTreeCategory.ALL_PROCESSES:
75 dispatch(navigateToAllProcesses);
77 case USERS_PANEL_LABEL:
78 dispatch(navigateToUsers);
80 case MY_ACCOUNT_PANEL_LABEL:
81 dispatch(navigateToMyAccount);
85 dispatch(navigationNotAvailable(uuid));
89 export const navigateToNotFound = push(Routes.NO_MATCH);
91 export const navigateToRoot = push(Routes.ROOT);
93 export const navigateToFavorites = push(Routes.FAVORITES);
95 export const navigateToTrash = push(Routes.TRASH);
97 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
99 export const navigateToWorkflows = push(Routes.WORKFLOWS);
101 export const pushOrGoto = (url: string): AnyAction => {
103 return { type: "noop" };
104 } else if (url[0] === '/') {
107 window.location.href = url;
108 return { type: "noop" };
113 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
114 navigateTo(SidePanelTreeCategory.PROJECTS)(dispatch, getState);
117 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
119 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
121 export const navigateToSearchResults = (searchValue: string) => {
122 if (searchValue !== "") {
123 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
125 return push({ pathname: Routes.SEARCH_RESULTS });
129 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
131 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
133 export const navigateToRepositories = push(Routes.REPOSITORIES);
135 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
137 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
139 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
141 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
143 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
145 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
147 export const navigateToUsers = push(Routes.USERS);
149 export const navigateToUserProfile = compose(push, getUserProfileUrl);
151 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
153 export const navigateToGroups = push(Routes.GROUPS);
155 export const navigateToGroupDetails = compose(push, getGroupUrl);
157 export const navigateToLinks = push(Routes.LINKS);
159 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
161 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);