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";
13 import { navigateToTrash } from '~/store/navigation/navigation-action';
14 import { matchCollectionRoute } from '~/routes/routes';
16 export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) =>
17 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
20 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash...", kind: SnackbarKind.INFO }));
21 await services.groupsService.untrash(uuid);
22 dispatch<any>(activateSidePanelTreeItem(uuid));
23 dispatch(trashPanelActions.REQUEST_ITEMS());
24 dispatch(snackbarActions.OPEN_SNACKBAR({
25 message: "Restored from trash",
27 kind: SnackbarKind.SUCCESS
30 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash...", kind: SnackbarKind.INFO }));
31 await services.groupsService.trash(uuid);
32 dispatch(projectPanelActions.REQUEST_ITEMS());
33 dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
34 dispatch(snackbarActions.OPEN_SNACKBAR({
35 message: "Added to trash",
37 kind: SnackbarKind.SUCCESS
41 dispatch(snackbarActions.OPEN_SNACKBAR({
42 message: "Could not move project to trash",
43 kind: SnackbarKind.ERROR
48 export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>
49 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
52 const { location } = getState().router;
53 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash...", kind: SnackbarKind.INFO }));
54 await services.collectionService.untrash(uuid);
55 if (matchCollectionRoute(location ? location.pathname : '')) {
56 dispatch(navigateToTrash);
58 dispatch(trashPanelActions.REQUEST_ITEMS());
59 dispatch(snackbarActions.OPEN_SNACKBAR({
60 message: "Restored from trash",
62 kind: SnackbarKind.SUCCESS
65 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash...", kind: SnackbarKind.INFO }));
66 await services.collectionService.trash(uuid);
67 dispatch(projectPanelActions.REQUEST_ITEMS());
68 dispatch(snackbarActions.OPEN_SNACKBAR({
69 message: "Added to trash",
71 kind: SnackbarKind.SUCCESS
75 dispatch(snackbarActions.OPEN_SNACKBAR({
76 message: "Could not move collection to trash",
77 kind: SnackbarKind.ERROR
82 export const toggleTrashed = (kind: ResourceKind, uuid: string, ownerUuid: string, isTrashed: boolean) =>
83 (dispatch: Dispatch) => {
84 if (kind === ResourceKind.PROJECT) {
85 dispatch<any>(toggleProjectTrashed(uuid, ownerUuid, isTrashed!!));
86 } else if (kind === ResourceKind.COLLECTION) {
87 dispatch<any>(toggleCollectionTrashed(uuid, isTrashed!!));