Remove doubled ContextMenuResource, spearate menu for trash view
[arvados-workbench2.git] / src / store / trash / trash-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { RootState } from "~/store/store";
7 import { ServiceRepository } from "~/services/services";
8 import { snackbarActions } from "~/store/snackbar/snackbar-actions";
9 import { trashPanelActions } from "~/store/trash-panel/trash-panel-action";
10 import { activateSidePanelTreeItem, loadSidePanelTreeProjects } from "~/store/side-panel-tree/side-panel-tree-actions";
11 import { projectPanelActions } from "~/store/project-panel/project-panel-action";
12
13 export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) =>
14     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
15         if (isTrashed) {
16             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash..." }));
17             await services.groupsService.untrash(uuid);
18             dispatch<any>(activateSidePanelTreeItem(uuid));
19             dispatch(trashPanelActions.REQUEST_ITEMS());
20             dispatch(snackbarActions.CLOSE_SNACKBAR());
21             dispatch(snackbarActions.OPEN_SNACKBAR({
22                 message: "Restored from trash",
23                 hideDuration: 2000
24             }));
25         } else {
26             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash..." }));
27             await services.groupsService.trash(uuid);
28             dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
29             dispatch(snackbarActions.CLOSE_SNACKBAR());
30             dispatch(snackbarActions.OPEN_SNACKBAR({
31                 message: "Added to trash",
32                 hideDuration: 2000
33             }));
34         }
35     };
36
37 export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>
38     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
39         if (isTrashed) {
40             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash..." }));
41             await services.collectionService.untrash(uuid);
42             dispatch(trashPanelActions.REQUEST_ITEMS());
43             dispatch(snackbarActions.OPEN_SNACKBAR({
44                 message: "Restored from trash",
45                 hideDuration: 2000
46             }));
47         } else {
48             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash..." }));
49             await services.collectionService.trash(uuid);
50             dispatch(projectPanelActions.REQUEST_ITEMS());
51             dispatch(snackbarActions.OPEN_SNACKBAR({
52                 message: "Added to trash",
53                 hideDuration: 2000
54             }));
55         }
56     };