From: Lucas Di Pentima Date: Wed, 12 May 2021 20:54:06 +0000 (-0300) Subject: 17637: Fixes supurious "not found" error when trashing project being viewed. X-Git-Tag: 2.2.0~6^2~5 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/de3b8d1fa96ec9a5d28b05dade868abf8132904b?hp=59eaefe09c2bc7e20c8bd2f2944e6c53cd4f38b6 17637: Fixes supurious "not found" error when trashing project being viewed. Also, fixed error snackbar when an untrash operation fails. Also, removed superfluous "about to do X..." snackbar messages. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/store/trash/trash-actions.ts b/src/store/trash/trash-actions.ts index b810b1e4..6a33e6a0 100644 --- a/src/store/trash/trash-actions.ts +++ b/src/store/trash/trash-actions.ts @@ -8,41 +8,44 @@ import { ServiceRepository } from "~/services/services"; import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions"; import { trashPanelActions } from "~/store/trash-panel/trash-panel-action"; import { activateSidePanelTreeItem, loadSidePanelTreeProjects } from "~/store/side-panel-tree/side-panel-tree-actions"; -import { projectPanelActions } from "~/store/project-panel/project-panel-action"; +import { getProjectPanelCurrentUuid, projectPanelActions } from "~/store/project-panel/project-panel-action"; import { ResourceKind } from "~/models/resource"; -import { navigateToTrash } from '~/store/navigation/navigation-action'; +import { navigateTo, navigateToTrash } from '~/store/navigation/navigation-action'; import { matchCollectionRoute } from '~/routes/routes'; export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise => { + let errorMessage = ''; + let successMessage = ''; try { if (isTrashed) { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Restoring from trash...", kind: SnackbarKind.INFO })); + errorMessage = "Could not restore project from trash"; + successMessage = "Restored from trash"; await services.groupsService.untrash(uuid); dispatch(activateSidePanelTreeItem(uuid)); dispatch(trashPanelActions.REQUEST_ITEMS()); - dispatch(snackbarActions.OPEN_SNACKBAR({ - message: "Restored from trash", - hideDuration: 2000, - kind: SnackbarKind.SUCCESS - })); } else { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Moving to trash...", kind: SnackbarKind.INFO })); + errorMessage = "Could not move project to trash"; + successMessage = "Added to trash"; await services.groupsService.trash(uuid); - dispatch(projectPanelActions.REQUEST_ITEMS()); + if (getProjectPanelCurrentUuid(getState()) === uuid) { + dispatch(navigateTo(ownerUuid)); + } else { + dispatch(projectPanelActions.REQUEST_ITEMS()); + } dispatch(loadSidePanelTreeProjects(ownerUuid)); - dispatch(snackbarActions.OPEN_SNACKBAR({ - message: "Added to trash", - hideDuration: 2000, - kind: SnackbarKind.SUCCESS - })); } } catch (e) { dispatch(snackbarActions.OPEN_SNACKBAR({ - message: "Could not move project to trash", + message: errorMessage, kind: SnackbarKind.ERROR })); } + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: successMessage, + hideDuration: 2000, + kind: SnackbarKind.SUCCESS + })); }; export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>