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 { navigateTo, navigateToTrash } from "store/navigation/navigation-action";
14 import { matchCollectionRoute } from "routes/routes";
16 export const toggleProjectTrashed =
17 (uuid: string, ownerUuid: string, isTrashed: boolean, isMulti: boolean) =>
18 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
19 let errorMessage = "";
20 let successMessage = "";
23 errorMessage = "Could not restore project from trash";
24 successMessage = "Restored project from trash";
25 await services.groupsService.untrash(uuid);
26 dispatch<any>(isMulti ? navigateToTrash : navigateTo(uuid));
27 dispatch<any>(activateSidePanelTreeItem(uuid));
29 errorMessage = "Could not move project to trash";
30 successMessage = "Added to trash";
31 await services.groupsService.trash(uuid);
32 dispatch<any>(loadSidePanelTreeProjects(ownerUuid));
33 dispatch<any>(navigateTo(ownerUuid));
37 snackbarActions.OPEN_SNACKBAR({
38 message: errorMessage,
39 kind: SnackbarKind.ERROR,
44 snackbarActions.OPEN_SNACKBAR({
45 message: successMessage,
47 kind: SnackbarKind.SUCCESS,
52 export const toggleCollectionTrashed =
53 (uuid: string, isTrashed: boolean) =>
54 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
55 let errorMessage = "";
56 let successMessage = "";
59 const { location } = getState().router;
60 errorMessage = "Could not restore collection from trash";
61 successMessage = "Restored from trash";
62 await services.collectionService.untrash(uuid);
63 if (matchCollectionRoute(location ? location.pathname : "")) {
64 dispatch(navigateToTrash);
66 dispatch(trashPanelActions.REQUEST_ITEMS());
68 errorMessage = "Could not move collection to trash";
69 successMessage = "Added to trash";
70 await services.collectionService.trash(uuid);
71 dispatch(projectPanelActions.REQUEST_ITEMS());
74 snackbarActions.OPEN_SNACKBAR({
75 message: successMessage,
77 kind: SnackbarKind.SUCCESS,
82 snackbarActions.OPEN_SNACKBAR({
83 message: errorMessage,
84 kind: SnackbarKind.ERROR,
90 export const toggleTrashed = (kind: ResourceKind, uuid: string, ownerUuid: string, isTrashed: boolean) => (dispatch: Dispatch) => {
91 if (kind === ResourceKind.PROJECT) {
92 dispatch<any>(toggleProjectTrashed(uuid, ownerUuid, isTrashed!!, false));
93 } else if (kind === ResourceKind.COLLECTION) {
94 dispatch<any>(toggleCollectionTrashed(uuid, isTrashed!!));