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 } from "~/store/snackbar/snackbar-actions";
9 import { sidePanelActions } from "~/store/side-panel/side-panel-action";
10 import { SidePanelId } from "~/store/side-panel/side-panel-reducer";
11 import { trashPanelActions } from "~/store/trash-panel/trash-panel-action";
12 import { getProjectList, projectActions } from "~/store/project/project-action";
14 export const toggleCollectionTrashed = (resource: { uuid: string; name: string, isTrashed?: boolean, ownerUuid?: string }) =>
15 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
16 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Working..." }));
17 if (resource.isTrashed) {
18 return services.collectionService.untrash(resource.uuid).then(() => {
19 dispatch<any>(getProjectList(resource.ownerUuid)).then(() => {
20 dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(SidePanelId.PROJECTS));
21 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN({ itemId: resource.ownerUuid!!, open: true, recursive: true }));
23 dispatch(trashPanelActions.REQUEST_ITEMS());
24 dispatch(snackbarActions.CLOSE_SNACKBAR());
25 dispatch(snackbarActions.OPEN_SNACKBAR({
26 message: "Restored from trash",
31 return services.collectionService.trash(resource.uuid).then(() => {
32 dispatch(snackbarActions.CLOSE_SNACKBAR());
33 dispatch(snackbarActions.OPEN_SNACKBAR({
34 message: "Added to trash",