21128: fixed trash panel to only show restore button Arvados-DCO-1.1-Signed-off-by...
[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 { checkFavorite } from "store/favorites/favorites-reducer";
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     isDefault: (uuid, resources, favorites)=>{
24         return !checkFavorite(uuid, favorites);
25     },
26     execute: (dispatch, resources) => {
27         dispatch(toggleFavorite(resources[0])).then(() => {
28             dispatch(favoritePanelActions.REQUEST_ITEMS());
29         });
30     },
31 };
32
33 export const msCopyToClipboardMenuAction = {
34     icon: Link,
35     name: MultiSelectMenuActionNames.COPY_TO_CLIPBOARD,
36     execute: (dispatch, resources) => {
37         dispatch(copyToClipboardAction(resources));
38     },
39 };
40
41 export const msMoveToAction = {
42     icon: MoveToIcon,
43     name: MultiSelectMenuActionNames.MOVE_TO,
44     execute: (dispatch, resource) => {
45         dispatch(openMoveProjectDialog(resource[0]));
46     },
47 };
48
49 export const msToggleTrashAction = {
50     name: MultiSelectMenuActionNames.TOGGLE_TRASH_ACTION,
51     defaultText: 'Add to Trash',
52     altText: 'Restore from Trash',
53     icon: TrashIcon,
54     altIcon: RestoreFromTrashIcon,
55     isDefault: (uuid, resources, favorites = []) => {
56         return uuid ? !(getResource(uuid)(resources) as any).isTrashed : true;
57     },
58     execute: (dispatch, resources) => {
59         for (const resource of [...resources]) {
60             dispatch(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
61         }
62     },
63 };
64
65 export const msProjectActionSet: MultiSelectMenuAction[][] = [[msCopyToClipboardMenuAction, msMoveToAction, msToggleTrashAction, msToggleFavoriteAction]];