21128: readonly collections great Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados-workbench2.git] / src / views-components / multiselect-toolbar / ms-collection-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { MoveToIcon, CopyIcon, RenameIcon } from "components/icon/icon";
6 import { openMoveCollectionDialog } from "store/collections/collection-move-actions";
7 import { openCollectionCopyDialog, openMultiCollectionCopyDialog } from "store/collections/collection-copy-actions";
8 import { toggleCollectionTrashed } from "store/trash/trash-actions";
9 import { ContextMenuResource } from "store/context-menu/context-menu-actions";
10 import { msCommonActionSet, MultiSelectMenuActionSet, MultiSelectMenuActionNames, MultiSelectMenuAction } from "./ms-menu-actions";
11 import { TrashIcon } from "components/icon/icon";
12 import { openCollectionUpdateDialog } from "store/collections/collection-update-actions";
13
14 const { MAKE_A_COPY, MOVE_TO, ADD_TO_TRASH, EDIT_COLLECTION, OPEN_IN_NEW_TAB, OPEN_W_3RD_PARTY_CLIENT, COPY_TO_CLIPBOARD, VIEW_DETAILS, API_DETAILS, ADD_TO_FAVORITES, SHARE} = MultiSelectMenuActionNames;
15
16 const msCopyCollection: MultiSelectMenuAction = {
17     name: MAKE_A_COPY,
18     icon: CopyIcon,
19     hasAlts: false,
20     isForMulti: true,
21     execute: (dispatch, [...resources]) => {
22         if (resources[0].fromContextMenu || resources.length === 1) dispatch<any>(openCollectionCopyDialog(resources[0]));
23         else dispatch<any>(openMultiCollectionCopyDialog(resources[0]));
24     },
25 }
26
27 const msMoveCollection: MultiSelectMenuAction = {
28     name: MOVE_TO,
29     icon: MoveToIcon,
30     hasAlts: false,
31     isForMulti: true,
32     execute: (dispatch, resources) => dispatch<any>(openMoveCollectionDialog(resources[0])),
33 }
34
35 const msToggleTrashAction: MultiSelectMenuAction = {
36     name: ADD_TO_TRASH,
37     icon: TrashIcon,
38     isForMulti: true,
39     hasAlts: false,
40     execute: (dispatch, resources: ContextMenuResource[]) => {
41         for (const resource of [...resources]) {
42             dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
43         }
44     },
45 }
46
47 const msEditCollection: MultiSelectMenuAction = {
48     icon: RenameIcon,
49     hasAlts: false,
50     isForMulti: false,
51     name: "Edit collection",
52     execute: (dispatch, resources) => {
53         dispatch<any>(openCollectionUpdateDialog(resources[0]));
54     },
55 }
56
57 export const msCollectionActionSet: MultiSelectMenuActionSet = [
58     [
59         ...msCommonActionSet,
60         msCopyCollection,
61         msMoveCollection,
62         msToggleTrashAction,
63         msEditCollection
64     ],
65 ];
66
67 export const msReadOnlyCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, ADD_TO_FAVORITES, OPEN_W_3RD_PARTY_CLIENT]);
68 export const msCommonCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, OPEN_W_3RD_PARTY_CLIENT, EDIT_COLLECTION, SHARE, MOVE_TO, ADD_TO_FAVORITES, ADD_TO_TRASH])
69 export const msOldCollectionActionFilter = new Set([OPEN_IN_NEW_TAB, COPY_TO_CLIPBOARD, MAKE_A_COPY, VIEW_DETAILS, API_DETAILS, OPEN_W_3RD_PARTY_CLIENT, EDIT_COLLECTION, SHARE, MOVE_TO, ADD_TO_FAVORITES, ADD_TO_TRASH])