1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from "~/store/store";
7 import { ServiceRepository } from "~/services/services";
8 import { snackbarActions, SnackbarKind } 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 import { ResourceKind } from "~/models/resource";
14 export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) =>
15 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
18 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash..." }));
19 await services.groupsService.untrash(uuid);
20 dispatch<any>(activateSidePanelTreeItem(uuid));
21 dispatch(trashPanelActions.REQUEST_ITEMS());
22 dispatch(snackbarActions.OPEN_SNACKBAR({
23 message: "Restored from trash",
25 kind: SnackbarKind.SUCCESS
28 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash..." }));
29 await services.groupsService.trash(uuid);
30 dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
31 dispatch(snackbarActions.OPEN_SNACKBAR({
32 message: "Added to trash",
34 kind: SnackbarKind.SUCCESS
38 dispatch(snackbarActions.OPEN_SNACKBAR({
39 message: "Could not move project to trash",
40 kind: SnackbarKind.ERROR
45 export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>
46 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
49 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash..." }));
50 await services.collectionService.untrash(uuid);
51 dispatch(trashPanelActions.REQUEST_ITEMS());
52 dispatch(snackbarActions.OPEN_SNACKBAR({
53 message: "Restored from trash",
55 kind: SnackbarKind.SUCCESS
58 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash..." }));
59 await services.collectionService.trash(uuid);
60 dispatch(projectPanelActions.REQUEST_ITEMS());
61 dispatch(snackbarActions.OPEN_SNACKBAR({
62 message: "Added to trash",
64 kind: SnackbarKind.SUCCESS
68 dispatch(snackbarActions.OPEN_SNACKBAR({
69 message: "Could not move collection to trash",
70 kind: SnackbarKind.ERROR
75 export const toggleTrashed = (kind: ResourceKind, uuid: string, ownerUuid: string, isTrashed: boolean) =>
76 (dispatch: Dispatch) => {
77 if (kind === ResourceKind.PROJECT) {
78 dispatch<any>(toggleProjectTrashed(uuid, ownerUuid, isTrashed!!));
79 } else if (kind === ResourceKind.COLLECTION) {
80 dispatch<any>(toggleCollectionTrashed(uuid, isTrashed!!));