15768: changed all context menu actions to take an array of resources Arvados-DCO...
[arvados-workbench2.git] / src / views-components / context-menu / action-sets / collection-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ContextMenuAction, 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,
10     ShareIcon,
11     MoveToIcon,
12     CopyIcon,
13     DetailsIcon,
14     AdvancedIcon,
15     OpenIcon,
16     Link,
17     RestoreVersionIcon,
18     FolderSharedIcon,
19 } from 'components/icon/icon';
20 import { openCollectionUpdateDialog } from 'store/collections/collection-update-actions';
21 import { favoritePanelActions } from 'store/favorite-panel/favorite-panel-action';
22 import { openMoveCollectionDialog } from 'store/collections/collection-move-actions';
23 import { openCollectionCopyDialog } from 'store/collections/collection-copy-actions';
24 import { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions';
25 import { ToggleTrashAction } from 'views-components/context-menu/actions/trash-action';
26 import { toggleCollectionTrashed } from 'store/trash/trash-actions';
27 import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions';
28 import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab';
29 import { toggleDetailsPanel } from 'store/details-panel/details-panel-action';
30 import { copyToClipboardAction, openInNewTabAction } from 'store/open-in-new-tab/open-in-new-tab.actions';
31 import { openRestoreCollectionVersionDialog } from 'store/collections/collection-version-actions';
32 import { TogglePublicFavoriteAction } from '../actions/public-favorite-action';
33 import { togglePublicFavorite } from 'store/public-favorites/public-favorites-actions';
34 import { publicFavoritePanelActions } from 'store/public-favorites-panel/public-favorites-action';
35 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
36
37 const toggleFavoriteAction: ContextMenuAction = {
38     component: ToggleFavoriteAction,
39     name: 'ToggleFavoriteAction',
40     execute: (dispatch, resources) => {
41         resources.forEach((resource) =>
42             dispatch<any>(toggleFavorite(resource)).then(() => {
43                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
44             })
45         );
46     },
47 };
48
49 const commonActionSet: ContextMenuActionSet = [
50     [
51         {
52             icon: OpenIcon,
53             name: 'Open in new tab',
54             execute: (dispatch, resource) => {
55                 dispatch<any>(openInNewTabAction(resource));
56             },
57         },
58         {
59             icon: Link,
60             name: 'Copy to clipboard',
61             execute: (dispatch, resource) => {
62                 dispatch<any>(copyToClipboardAction(resource));
63             },
64         },
65         {
66             icon: CopyIcon,
67             name: 'Make a copy',
68             execute: (dispatch, resources) => {
69                 resources.forEach((resource) => dispatch<any>(openCollectionCopyDialog(resource)));
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, resources) => {
83                 resources.forEach((resource) => dispatch<any>(openAdvancedTabDialog(resource.uuid)));
84             },
85         },
86     ],
87 ];
88
89 export const readOnlyCollectionActionSet: ContextMenuActionSet = [
90     [
91         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
92         toggleFavoriteAction,
93         {
94             icon: FolderSharedIcon,
95             name: 'Open with 3rd party client',
96             execute: (dispatch, resources) => {
97                 resources.forEach((resource) => dispatch<any>(openWebDavS3InfoDialog(resource.uuid)));
98             },
99         },
100     ],
101 ];
102
103 export const collectionActionSet: ContextMenuActionSet = [
104     [
105         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
106         {
107             icon: RenameIcon,
108             name: 'Edit collection',
109             execute: (dispatch, resources) => {
110                 resources.forEach((resource) => dispatch<any>(openCollectionUpdateDialog(resource)));
111             },
112         },
113         {
114             icon: ShareIcon,
115             name: 'Share',
116             execute: (dispatch, resources) => {
117                 resources.forEach(({ uuid }) => dispatch<any>(openSharingDialog(uuid)));
118             },
119         },
120         {
121             icon: MoveToIcon,
122             name: 'Move to',
123             execute: (dispatch, resources) => resources.forEach((resource) => dispatch<any>(openMoveCollectionDialog(resource))),
124         },
125         {
126             component: ToggleTrashAction,
127             name: 'ToggleTrashAction',
128             // execute: (dispatch, resource) => {
129             execute: (dispatch, resources: ContextMenuResource[]) => {
130                 resources.forEach((resource) => dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!)));
131             },
132         },
133     ],
134 ];
135
136 export const collectionAdminActionSet: ContextMenuActionSet = [
137     [
138         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
139         {
140             component: TogglePublicFavoriteAction,
141             name: 'TogglePublicFavoriteAction',
142             execute: (dispatch, resources) => {
143                 resources.forEach((resource) =>
144                     dispatch<any>(togglePublicFavorite(resource)).then(() => {
145                         dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
146                     })
147                 );
148             },
149         },
150     ],
151 ];
152
153 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
154     [
155         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
156         {
157             icon: RestoreVersionIcon,
158             name: 'Restore version',
159             execute: (dispatch, resources) => {
160                 resources.forEach(({ uuid }) => dispatch<any>(openRestoreCollectionVersionDialog(uuid)));
161             },
162         },
163     ],
164 ];