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<any>(loadSidePanelTreeProjects(ownerUuid));
33 dispatch(snackbarActions.OPEN_SNACKBAR({
34 message: "Added to trash",
36 kind: SnackbarKind.SUCCESS
40 dispatch(snackbarActions.OPEN_SNACKBAR({
41 message: "Could not move project to trash",
42 kind: SnackbarKind.ERROR
47 export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>
48 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
51 const { location } = getState().router;
52 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash...", kind: SnackbarKind.INFO }));
53 await services.collectionService.untrash(uuid);
54 if (matchCollectionRoute(location ? location.pathname : '')) {
55 dispatch(navigateToTrash);
57 dispatch(trashPanelActions.REQUEST_ITEMS());
58 dispatch(snackbarActions.OPEN_SNACKBAR({
59 message: "Restored from trash",
61 kind: SnackbarKind.SUCCESS
64 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash...", kind: SnackbarKind.INFO }));
65 await services.collectionService.trash(uuid);
66 dispatch(projectPanelActions.REQUEST_ITEMS());
67 dispatch(snackbarActions.OPEN_SNACKBAR({
68 message: "Added to trash",
70 kind: SnackbarKind.SUCCESS
74 dispatch(snackbarActions.OPEN_SNACKBAR({
75 message: "Could not move collection to trash",
76 kind: SnackbarKind.ERROR
81 export const toggleTrashed = (kind: ResourceKind, uuid: string, ownerUuid: string, isTrashed: boolean) =>
82 (dispatch: Dispatch) => {
83 if (kind === ResourceKind.PROJECT) {
84 dispatch<any>(toggleProjectTrashed(uuid, ownerUuid, isTrashed!!));
85 } else if (kind === ResourceKind.COLLECTION) {
86 dispatch<any>(toggleCollectionTrashed(uuid, isTrashed!!));