21128: added hasAlts field Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[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 import { getResource } from "store/resources/resources";
15 import { checkFavorite } from "store/favorites/favorites-reducer";
16
17 export const msToggleFavoriteAction = {
18     name: MultiSelectMenuActionNames.ADD_TO_FAVORITES,
19     icon: AddFavoriteIcon,
20     hasAlts: true,
21     altText: 'Remove from Favorites',
22     altIcon: RemoveFavoriteIcon,
23     isForMulti: false,
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     name: MultiSelectMenuActionNames.COPY_TO_CLIPBOARD,
36     icon: Link,
37     hasAlts: false,
38     isForMulti: false,
39     execute: (dispatch, resources) => {
40         dispatch(copyToClipboardAction(resources));
41     },
42 };
43
44 export const msMoveToAction = {
45     name: MultiSelectMenuActionNames.MOVE_TO,
46     icon: MoveToIcon,
47     hasAlts: false,
48     isForMulti: true,
49     execute: (dispatch, resource) => {
50         dispatch(openMoveProjectDialog(resource[0]));
51     },
52 };
53
54 export const msToggleTrashAction = {
55     name: MultiSelectMenuActionNames.ADD_TO_TRASH,
56     icon: TrashIcon,
57     hasAlts: true,
58     altText: 'Restore from Trash',
59     altIcon: RestoreFromTrashIcon,
60     isForMulti: true,
61     isDefault: (uuid, resources, favorites = []) => {
62         return uuid ? !(getResource(uuid)(resources) as any).isTrashed : true;
63     },
64     execute: (dispatch, resources) => {
65         for (const resource of [...resources]) {
66             dispatch(toggleProjectTrashed(resource.uuid, resource.ownerUuid, resource.isTrashed!!, resources.length > 1));
67         }
68     },
69 };
70
71 export const msProjectActionSet: MultiSelectMenuAction[][] = [[msCopyToClipboardMenuAction, msMoveToAction, msToggleTrashAction, msToggleFavoriteAction]];