17098: Adds ability to recover an old version collection as the head version.
[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 { ContextMenuActionSet } from "../context-menu-action-set";
6 import { ToggleFavoriteAction } from "../actions/favorite-action";
7 import { toggleFavorite } from "~/store/favorites/favorites-actions";
8 import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, AdvancedIcon, OpenIcon, Link, RecoverVersionIcon } from "~/components/icon/icon";
9 import { openCollectionUpdateDialog } from "~/store/collections/collection-update-actions";
10 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
11 import { openMoveCollectionDialog } from '~/store/collections/collection-move-actions';
12 import { openCollectionCopyDialog } from "~/store/collections/collection-copy-actions";
13 import { ToggleTrashAction } from "~/views-components/context-menu/actions/trash-action";
14 import { toggleCollectionTrashed } from "~/store/trash/trash-actions";
15 import { openSharingDialog } from '~/store/sharing-dialog/sharing-dialog-actions';
16 import { openAdvancedTabDialog } from "~/store/advanced-tab/advanced-tab";
17 import { toggleDetailsPanel } from '~/store/details-panel/details-panel-action';
18 import { copyToClipboardAction, openInNewTabAction } from "~/store/open-in-new-tab/open-in-new-tab.actions";
19 import { recoverVersion } from "~/store/collections/collection-version-actions";
20 import { TogglePublicFavoriteAction } from "../actions/public-favorite-action";
21 import { togglePublicFavorite } from "~/store/public-favorites/public-favorites-actions";
22 import { publicFavoritePanelActions } from "~/store/public-favorites-panel/public-favorites-action";
23
24 export const readOnlyCollectionActionSet: ContextMenuActionSet = [[
25     {
26         component: ToggleFavoriteAction,
27         name: 'ToggleFavoriteAction',
28         execute: (dispatch, resource) => {
29             dispatch<any>(toggleFavorite(resource)).then(() => {
30                 dispatch<any>(favoritePanelActions.REQUEST_ITEMS());
31             });
32         }
33     },
34     {
35         icon: OpenIcon,
36         name: "Open in new tab",
37         execute: (dispatch, resource) => {
38             dispatch<any>(openInNewTabAction(resource));
39         }
40     },
41     {
42         icon: Link,
43         name: "Copy to clipboard",
44         execute: (dispatch, resource) => {
45             dispatch<any>(copyToClipboardAction(resource));
46         }
47     },
48     {
49         icon: CopyIcon,
50         name: "Make a copy",
51         execute: (dispatch, resource) => {
52             dispatch<any>(openCollectionCopyDialog(resource));
53         }
54
55     },
56     {
57         icon: DetailsIcon,
58         name: "View details",
59         execute: dispatch => {
60             dispatch<any>(toggleDetailsPanel());
61         }
62     },
63     {
64         icon: AdvancedIcon,
65         name: "Advanced",
66         execute: (dispatch, resource) => {
67             dispatch<any>(openAdvancedTabDialog(resource.uuid));
68         }
69     },
70 ]];
71
72 export const collectionActionSet: ContextMenuActionSet = [
73     [
74         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
75         {
76             icon: RenameIcon,
77             name: "Edit collection",
78             execute: (dispatch, resource) => {
79                 dispatch<any>(openCollectionUpdateDialog(resource));
80             }
81         },
82         {
83             icon: ShareIcon,
84             name: "Share",
85             execute: (dispatch, { uuid }) => {
86                 dispatch<any>(openSharingDialog(uuid));
87             }
88         },
89         {
90             icon: MoveToIcon,
91             name: "Move to",
92             execute: (dispatch, resource) => dispatch<any>(openMoveCollectionDialog(resource))
93         },
94         {
95             component: ToggleTrashAction,
96             name: 'ToggleTrashAction',
97             execute: (dispatch, resource) => {
98                 dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
99             }
100         },
101     ]
102 ];
103
104 export const collectionAdminActionSet: ContextMenuActionSet = [
105     [
106         ...collectionActionSet.reduce((prev, next) => prev.concat(next), []),
107         {
108             component: TogglePublicFavoriteAction,
109             name: 'TogglePublicFavoriteAction',
110             execute: (dispatch, resource) => {
111                 dispatch<any>(togglePublicFavorite(resource)).then(() => {
112                     dispatch<any>(publicFavoritePanelActions.REQUEST_ITEMS());
113                 });
114             }
115         },
116     ]
117 ];
118
119 export const oldCollectionVersionActionSet: ContextMenuActionSet = [
120     [
121         ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []),
122         {
123             icon: RecoverVersionIcon,
124             name: 'Recover version',
125             execute: (dispatch, { uuid }) => {
126                 dispatch<any>(recoverVersion(uuid));
127             }
128         },
129     ]
130 ];