19569: Add open in new tab action to process resource action set
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / process-resource-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ContextMenuActionSet } from "../context-menu-action-set";
6 import { ToggleFavoriteAction } from "../actions/favorite-action";
7 import { toggleFavorite } from "store/favorites/favorites-actions";
8 import {
9     RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon,
10     RemoveIcon, ReRunProcessIcon, OutputIcon,
11     AdvancedIcon,
12     OpenIcon
13 } from "components/icon/icon";
14 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
15 import { openMoveProcessDialog } from 'store/processes/process-move-actions';
16 import { openProcessUpdateDialog } from "store/processes/process-update-actions";
17 import { openCopyProcessDialog } from 'store/processes/process-copy-actions';
18 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
19 import { openRemoveProcessDialog, reRunProcess } from "store/processes/processes-actions";
20 import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
21 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
22 import { navigateToOutput } from "store/process-panel/process-panel-actions";
23 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
24 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
25 import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions";
26 import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
27 import { openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
28
29 export const readOnlyProcessResourceActionSet: ContextMenuActionSet = [[
30     {
31         component: ToggleFavoriteAction,
32         execute: (dispatch, resource) => {
33             dispatch<any>(toggleFavorite(resource)).then(() => {
34                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
35             });
36         }
37     },
38     {
39         icon: OpenIcon,
40         name: "Open in new tab",
41         execute: (dispatch, resource) => {
42             dispatch<any>(openInNewTabAction(resource));
43         }
44     },
45     {
46         icon: CopyIcon,
47         name: "Copy to project",
48         execute: (dispatch, resource) => {
49             dispatch<any>(openCopyProcessDialog(resource));
50         }
51     },
52     {
53         icon: ReRunProcessIcon,
54         name: "Re-run process",
55         execute: (dispatch, resource) => {
56             if(resource.workflowUuid) {
57                 dispatch<any>(reRunProcess(resource.uuid, resource.workflowUuid));
58             } else {
59                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: `You can't re-run this process`, hideDuration: 2000, kind: SnackbarKind.ERROR }));
60             }
61         }
62     },
63     {
64         icon: OutputIcon,
65         name: "Outputs",
66         execute: (dispatch, resource) => {
67             if(resource.outputUuid){
68                 dispatch<any>(navigateToOutput(resource.outputUuid));
69             }
70         }
71     },
72     {
73         icon: DetailsIcon,
74         name: "View details",
75         execute: dispatch => {
76             dispatch<any>(toggleDetailsPanel());
77         }
78     },
79     {
80         icon: AdvancedIcon,
81         name: "API Details",
82         execute: (dispatch, resource) => {
83             dispatch<any>(openAdvancedTabDialog(resource.uuid));
84         }
85     },
86 ]];
87
88 export const processResourceActionSet: ContextMenuActionSet = [[
89     ...readOnlyProcessResourceActionSet.reduce((prev, next) => prev.concat(next), []),
90     {
91         icon: RenameIcon,
92         name: "Edit process",
93         execute: (dispatch, resource) => {
94             dispatch<any>(openProcessUpdateDialog(resource));
95         }
96     },
97     {
98         icon: ShareIcon,
99         name: "Share",
100         execute: (dispatch, { uuid }) => {
101             dispatch<any>(openSharingDialog(uuid));
102         }
103     },
104     {
105         icon: MoveToIcon,
106         name: "Move to",
107         execute: (dispatch, resource) => {
108             dispatch<any>(openMoveProcessDialog(resource));
109         }
110     },
111     {
112         name: "Remove",
113         icon: RemoveIcon,
114         execute: (dispatch, resource) => {
115             dispatch<any>(openRemoveProcessDialog(resource.uuid));
116         }
117     }
118 ]];
119
120 export const processResourceAdminActionSet: ContextMenuActionSet = [[
121     ...processResourceActionSet.reduce((prev, next) => prev.concat(next), []),
122     {
123         component: TogglePublicFavoriteAction,
124         name: "Add to public favorites",
125         execute: (dispatch, resource) => {
126             dispatch<any>(togglePublicFavorite(resource)).then(() => {
127                 dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
128             });
129         }
130     },
131 ]];