Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / project-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 { NewProjectIcon, RenameIcon, MoveToIcon, DetailsIcon, AdvancedIcon, OpenIcon, Link, FolderSharedIcon } from "components/icon/icon";
7 import { ToggleFavoriteAction } from "../actions/favorite-action";
8 import { toggleFavorite } from "store/favorites/favorites-actions";
9 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
10 import { openMoveProjectDialog } from "store/projects/project-move-actions";
11 import { openProjectCreateDialog } from "store/projects/project-create-actions";
12 import { openProjectUpdateDialog } from "store/projects/project-update-actions";
13 import { ToggleTrashAction } from "views-components/context-menu/actions/trash-action";
14 import { toggleProjectTrashed } from "store/trash/trash-actions";
15 import { ShareIcon } from "components/icon/icon";
16 import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions";
17 import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab";
18 import { toggleDetailsPanel } from "store/details-panel/details-panel-action";
19 import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions";
20 import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions";
21 import { ToggleLockAction } from "../actions/lock-action";
22 import { freezeProject, unfreezeProject } from "store/projects/project-lock-actions";
23
24 export const toggleFavoriteAction = {
25     component: ToggleFavoriteAction,
26     name: "ToggleFavoriteAction",
27     execute: (dispatch, resources) => {
28         dispatch(toggleFavorite(resources[0])).then(() => {
29             dispatch(favoritePanelActions.REQUEST_ITEMS());
30         });
31     },
32 };
33
34 export const openInNewTabMenuAction = {
35     icon: OpenIcon,
36     name: "Open in new tab",
37     execute: (dispatch, resources) => {
38         dispatch(openInNewTabAction(resources[0]));
39     },
40 };
41
42 export const copyToClipboardMenuAction = {
43     icon: Link,
44     name: "Copy to clipboard",
45     execute: (dispatch, resources) => {
46         dispatch(copyToClipboardAction(resources));
47     },
48 };
49
50 export const viewDetailsAction = {
51     icon: DetailsIcon,
52     name: "View details",
53     execute: dispatch => {
54         dispatch(toggleDetailsPanel());
55     },
56 };
57
58 export const advancedAction = {
59     icon: AdvancedIcon,
60     name: "API Details",
61     execute: (dispatch, resources) => {
62         dispatch(openAdvancedTabDialog(resources[0].uuid));
63     },
64 };
65
66 export const openWith3rdPartyClientAction = {
67     icon: FolderSharedIcon,
68     name: "Open with 3rd party client",
69     execute: (dispatch, resources) => {
70         dispatch(openWebDavS3InfoDialog(resources[0].uuid));
71     },
72 };
73
74 export const editProjectAction = {
75     icon: RenameIcon,
76     name: "Edit project",
77     execute: (dispatch, resources) => {
78         dispatch(openProjectUpdateDialog(resources[0]));
79     },
80 };
81
82 export const shareAction = {
83     icon: ShareIcon,
84     name: "Share",
85     execute: (dispatch, resources) => {
86         dispatch(openSharingDialog(resources[0].uuid));
87     },
88 };
89
90 export const moveToAction = {
91     icon: MoveToIcon,
92     name: "Move to",
93     execute: (dispatch, resource) => {
94         dispatch(openMoveProjectDialog(resource[0]));
95     },
96 };
97
98 export const toggleTrashAction = {
99     component: ToggleTrashAction,
100     name: "ToggleTrashAction",
101     execute: (dispatch, resources) => {
102         dispatch(toggleProjectTrashed(resources[0].uuid, resources[0].ownerUuid, resources[0].isTrashed!!, resources.length > 1));
103     },
104 };
105
106 export const freezeProjectAction = {
107     component: ToggleLockAction,
108     name: "ToggleLockAction",
109     execute: (dispatch, resources) => {
110         if (resources[0].isFrozen) {
111             dispatch(unfreezeProject(resources[0].uuid));
112         } else {
113             dispatch(freezeProject(resources[0].uuid));
114         }
115     },
116 };
117
118 export const newProjectAction: any = {
119     icon: NewProjectIcon,
120     name: "New project",
121     execute: (dispatch, resource): void => {
122         dispatch(openProjectCreateDialog(resource.uuid));
123     },
124 };
125
126 export const readOnlyProjectActionSet: ContextMenuActionSet = [
127     [toggleFavoriteAction, openInNewTabMenuAction, copyToClipboardMenuAction, viewDetailsAction, advancedAction, openWith3rdPartyClientAction],
128 ];
129
130 export const filterGroupActionSet: ContextMenuActionSet = [
131     [
132         toggleFavoriteAction,
133         openInNewTabMenuAction,
134         copyToClipboardMenuAction,
135         viewDetailsAction,
136         advancedAction,
137         openWith3rdPartyClientAction,
138         editProjectAction,
139         shareAction,
140         moveToAction,
141         toggleTrashAction,
142     ],
143 ];
144
145 export const frozenActionSet: ContextMenuActionSet = [
146     [
147         shareAction,
148         toggleFavoriteAction,
149         openInNewTabMenuAction,
150         copyToClipboardMenuAction,
151         viewDetailsAction,
152         advancedAction,
153         openWith3rdPartyClientAction,
154         freezeProjectAction,
155     ],
156 ];
157
158 export const projectActionSet: ContextMenuActionSet = [
159     [
160         toggleFavoriteAction,
161         openInNewTabMenuAction,
162         copyToClipboardMenuAction,
163         viewDetailsAction,
164         advancedAction,
165         openWith3rdPartyClientAction,
166         editProjectAction,
167         shareAction,
168         moveToAction,
169         toggleTrashAction,
170         newProjectAction,
171         freezeProjectAction,
172     ],
173 ];