15768: first step in revamp: imported context menu actions and got them to work for...
[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
36 const toggleFavoriteAction: ContextMenuAction = {
37     component: ToggleFavoriteAction,
38     name: 'ToggleFavoriteAction',
39     execute: (dispatch, resource) => {
40         dispatch<any>(toggleFavorite(resource)).then(() => {
41             dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
42         });
43     },
44 };
45
46 const commonActionSet: ContextMenuActionSet = [
47     [
48         {
49             icon: OpenIcon,
50             name: 'Open in new tab',
51             execute: (dispatch, resource) => {
52                 dispatch<any>(openInNewTabAction(resource));
53             },
54         },
55         {
56             icon: Link,
57             name: 'Copy to clipboard',
58             execute: (dispatch, resource) => {
59                 dispatch<any>(copyToClipboardAction(resource));
60             },
61         },
62         {
63             icon: CopyIcon,
64             name: 'Make a copy',
65             execute: (dispatch, resource) => {
66                 dispatch<any>(openCollectionCopyDialog(resource));
67             },
68         },
69         {
70             icon: DetailsIcon,
71             name: 'View details',
72             execute: (dispatch) => {
73                 dispatch<any>(toggleDetailsPanel());
74             },
75         },
76         {
77             icon: AdvancedIcon,
78             name: 'API Details',
79             execute: (dispatch, resource) => {
80                 dispatch<any>(openAdvancedTabDialog(resource.uuid));
81             },
82         },
83     ],
84 ];
85
86 export const readOnlyCollectionActionSet: ContextMenuActionSet = [
87     [
88         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
89         toggleFavoriteAction,
90         {
91             icon: FolderSharedIcon,
92             name: 'Open with 3rd party client',
93             execute: (dispatch, resource) => {
94                 dispatch<any>(openWebDavS3InfoDialog(resource.uuid));
95             },
96         },
97     ],
98 ];
99
100 export const collectionActionSet: ContextMenuActionSet = [
101     [
102         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
103         {
104             icon: RenameIcon,
105             name: 'Edit collection',
106             execute: (dispatch, resource) => {
107                 dispatch<any>(openCollectionUpdateDialog(resource));
108             },
109         },
110         {
111             icon: ShareIcon,
112             name: 'Share',
113             execute: (dispatch, { uuid }) => {
114                 dispatch<any>(openSharingDialog(uuid));
115             },
116         },
117         {
118             icon: MoveToIcon,
119             name: 'Move to',
120             execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource)),
121         },
122         {
123             component: ToggleTrashAction,
124             name: 'ToggleTrashAction',
125             execute: (dispatch, resource) => {
126                 dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
127             },
128         },
129     ],
130 ];
131
132 export const collectionAdminActionSet: ContextMenuActionSet = [
133     [
134         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
135         {
136             component: TogglePublicFavoriteAction,
137             name: 'TogglePublicFavoriteAction',
138             execute: (dispatch, resource) => {
139                 dispatch<any>(togglePublicFavorite(resource)).then(() => {
140                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
141                 });
142             },
143         },
144     ],
145 ];
146
147 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
148     [
149         ...commonActionSet.reduce((prev, next) => prev.concat(next), []),
150         {
151             icon: RestoreVersionIcon,
152             name: 'Restore version',
153             execute: (dispatch, { uuid }) => {
154                 dispatch<any>(openRestoreCollectionVersionDialog(uuid));
155             },
156         },
157     ],
158 ];