21128: icon toggles in place Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox...
[arvados-workbench2.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 import { getResource } from "store/resources/resources";
15 import { ContextMenuResource } from "store/context-menu/context-menu-actions";
16 import { checkFavorite } from "store/favorites/favorites-reducer";
17
18 export const msToggleFavoriteAction = {
19     name: MultiSelectMenuActionNames.TOGGLE_FAVORITE_ACTION,
20     defaultText: 'Add to Favorites',
21     altText: 'Remove from Favorites',
22     icon: AddFavoriteIcon,
23     altIcon: RemoveFavoriteIcon,
24     isDefault: (uuid, resources, favorites)=>{
25         return !checkFavorite(uuid, favorites);
26     },
27     execute: (dispatch, resources) => {
28         dispatch(toggleFavorite(resources[0])).then(() => {
29             dispatch(favoritePanelActions.REQUEST_ITEMS());
30         });
31     },
32 };
33
34 export const msCopyToClipboardMenuAction = {
35     icon: Link,
36     name: MultiSelectMenuActionNames.COPY_TO_CLIPBOARD,
37     execute: (dispatch, resources) => {
38         dispatch(copyToClipboardAction(resources));
39     },
40 };
41
42 export const msMoveToAction = {
43     icon: MoveToIcon,
44     name: MultiSelectMenuActionNames.MOVE_TO,
45     execute: (dispatch, resource) => {
46         dispatch(openMoveProjectDialog(resource[0]));
47     },
48 };
49
50 export const msToggleTrashAction = {
51     name: MultiSelectMenuActionNames.TOGGLE_TRASH_ACTION,
52     defaultText: 'Add to Trash',
53     altText: 'Restore from Trash',
54     icon: TrashIcon,
55     altIcon: RestoreFromTrashIcon,
56     isDefault: (uuid, resources, favorites = []) => {
57         return uuid ? !(getResource(uuid)(resources) as any).isTrashed : true;
58     },
59     execute: (dispatch, resources) => {
60         for (const resource of [...resources]) {
61             dispatch(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
62         }
63     },
64 };
65
66 export const msProjectActionSet: MultiSelectMenuAction[][] = [[msCopyToClipboardMenuAction, msMoveToAction, msToggleTrashAction, msToggleFavoriteAction]];