21128: created ms-menu-action-set and moved name consts into it Arvados-DCO-1.1-Signe...
[arvados.git] / src / views-components / multiselect-toolbar / ms-project-action-set.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { MultiSelectMenuAction, MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-action-set";
6 import { MoveToIcon, Link } from "components/icon/icon";
7 import { openMoveProjectDialog } from "store/projects/project-move-actions";
8 import { toggleProjectTrashed } from "store/trash/trash-actions";
9 import { copyToClipboardAction } from "store/open-in-new-tab/open-in-new-tab.actions";
10 import { toggleFavorite } from "store/favorites/favorites-actions";
11 import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action";
12 import { AddFavoriteIcon, RemoveFavoriteIcon } from "components/icon/icon";
13 import { RestoreFromTrashIcon, TrashIcon } from "components/icon/icon";
14
15
16
17 export const msToggleFavoriteAction = {
18     name: MultiSelectMenuActionNames.TOGGLE_FAVORITE_ACTION,
19     defaultText: 'Add to Favorites',
20     altText: 'Remove from Favorites',
21     icon: AddFavoriteIcon,
22     altIcon: RemoveFavoriteIcon,
23     execute: (dispatch, resources) => {
24         dispatch(toggleFavorite(resources[0])).then(() => {
25             dispatch(favoritePanelActions.REQUEST_ITEMS());
26         });
27     },
28 };
29
30 export const msCopyToClipboardMenuAction = {
31     icon: Link,
32     name: MultiSelectMenuActionNames.COPY_TO_CLIPBOARD,
33     execute: (dispatch, resources) => {
34         dispatch(copyToClipboardAction(resources));
35     },
36 };
37
38 export const msMoveToAction = {
39     icon: MoveToIcon,
40     name: MultiSelectMenuActionNames.MOVE_TO,
41     execute: (dispatch, resource) => {
42         dispatch(openMoveProjectDialog(resource[0]));
43     },
44 };
45
46 export const msToggleTrashAction = {
47     name: MultiSelectMenuActionNames.TOGGLE_TRASH_ACTION,
48     defaultText: 'Add to Trash',
49     altText: 'Restore from Trash',
50     icon: TrashIcon,
51     altIcon: RestoreFromTrashIcon,
52     execute: (dispatch, resources) => {
53         for (const resource of [...resources]) {
54             dispatch(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
55         }
56     },
57 };
58
59 export const msProjectActionSet: MultiSelectMenuAction[][] = [[msCopyToClipboardMenuAction, msMoveToAction, msToggleTrashAction, msToggleFavoriteAction]];