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 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);
46 case SidePanelTreeCategory.PROJECTS:
47 const usr = getState().auth.user;
49 dispatch<any>(pushOrGoto(getNavUrl(usr.uuid, getState().auth)));
52 case SidePanelTreeCategory.FAVORITES:
53 dispatch<any>(navigateToFavorites);
55 case SidePanelTreeCategory.PUBLIC_FAVORITES:
56 dispatch(navigateToPublicFavorites);
58 case SidePanelTreeCategory.SHARED_WITH_ME:
59 dispatch(navigateToSharedWithMe);
61 case SidePanelTreeCategory.WORKFLOWS:
62 dispatch(navigateToWorkflows);
64 case SidePanelTreeCategory.TRASH:
65 dispatch(navigateToTrash);
67 case SidePanelTreeCategory.GROUPS:
68 dispatch(navigateToGroups);
70 case SidePanelTreeCategory.ALL_PROCESSES:
71 dispatch(navigateToAllProcesses);
73 case USERS_PANEL_LABEL:
74 dispatch(navigateToUsers);
76 case MY_ACCOUNT_PANEL_LABEL:
77 dispatch(navigateToMyAccount);
81 dispatch(navigationNotAvailable(uuid));
85 export const navigateToNotFound = push(Routes.NO_MATCH);
87 export const navigateToRoot = push(Routes.ROOT);
89 export const navigateToFavorites = push(Routes.FAVORITES);
91 export const navigateToTrash = push(Routes.TRASH);
93 export const navigateToPublicFavorites = push(Routes.PUBLIC_FAVORITES);
95 export const navigateToWorkflows = push(Routes.WORKFLOWS);
97 export const pushOrGoto = (url: string): AnyAction => {
99 return { type: "noop" };
100 } else if (url[0] === '/') {
103 window.location.href = url;
104 return { type: "noop" };
109 export const navigateToRootProject = (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
110 navigateTo(SidePanelTreeCategory.PROJECTS)(dispatch, getState);
113 export const navigateToSharedWithMe = push(Routes.SHARED_WITH_ME);
115 export const navigateToRunProcess = push(Routes.RUN_PROCESS);
117 export const navigateToSearchResults = (searchValue: string) => {
118 if (searchValue !== "") {
119 return push({ pathname: Routes.SEARCH_RESULTS, search: '?q=' + encodeURIComponent(searchValue) });
121 return push({ pathname: Routes.SEARCH_RESULTS });
125 export const navigateToUserVirtualMachines = push(Routes.VIRTUAL_MACHINES_USER);
127 export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN);
129 export const navigateToRepositories = push(Routes.REPOSITORIES);
131 export const navigateToSshKeysAdmin = push(Routes.SSH_KEYS_ADMIN);
133 export const navigateToSshKeysUser = push(Routes.SSH_KEYS_USER);
135 export const navigateToSiteManager = push(Routes.SITE_MANAGER);
137 export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
139 export const navigateToLinkAccount = push(Routes.LINK_ACCOUNT);
141 export const navigateToKeepServices = push(Routes.KEEP_SERVICES);
143 export const navigateToUsers = push(Routes.USERS);
145 export const navigateToUserProfile = compose(push, getUserProfileUrl);
147 export const navigateToApiClientAuthorizations = push(Routes.API_CLIENT_AUTHORIZATIONS);
149 export const navigateToGroups = push(Routes.GROUPS);
151 export const navigateToGroupDetails = compose(push, getGroupUrl);
153 export const navigateToLinks = push(Routes.LINKS);
155 export const navigateToCollectionsContentAddress = push(Routes.COLLECTIONS_CONTENT_ADDRESS);
157 export const navigateToAllProcesses = push(Routes.ALL_PROCESSES);