From 59a77c79b4d5a2286eeed3f33af78d0b30caea48 Mon Sep 17 00:00:00 2001 From: Lisa Knox Date: Wed, 4 Oct 2023 12:19:43 -0400 Subject: [PATCH] 15768: fixed 422 handling on untrash Arvados-DCO-1.1-Signed-off-by: Lisa Knox --- .../trashable-resource-service.ts | 20 +++--- src/store/trash/trash-actions.ts | 63 ++++++++++++------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/services/common-service/trashable-resource-service.ts b/src/services/common-service/trashable-resource-service.ts index 4d6b130b..5e4704b6 100644 --- a/src/services/common-service/trashable-resource-service.ts +++ b/src/services/common-service/trashable-resource-service.ts @@ -9,29 +9,25 @@ import { CommonResourceService } from "services/common-service/common-resource-s import { ApiActions } from "services/api/api-actions"; export class TrashableResourceService extends CommonResourceService { - constructor(serverApi: AxiosInstance, resourceType: string, actions: ApiActions, readOnlyFields: string[] = []) { super(serverApi, resourceType, actions, readOnlyFields); } trash(uuid: string): Promise { - return CommonResourceService.defaultResponse( - this.serverApi - .post(this.resourceType + `/${uuid}/trash`), - this.actions - ); + return CommonResourceService.defaultResponse(this.serverApi.post(this.resourceType + `/${uuid}/trash`), this.actions); } untrash(uuid: string): Promise { const params = { - ensure_unique_name: true + ensure_unique_name: true, }; return CommonResourceService.defaultResponse( - this.serverApi - .post(this.resourceType + `/${uuid}/untrash`, { - params: CommonResourceService.mapKeys(snakeCase)(params) - }), - this.actions + this.serverApi.post(this.resourceType + `/${uuid}/untrash`, { + params: CommonResourceService.mapKeys(snakeCase)(params), + }), + this.actions, + undefined, + false ); } } diff --git a/src/store/trash/trash-actions.ts b/src/store/trash/trash-actions.ts index ffdad04a..3f8f8346 100644 --- a/src/store/trash/trash-actions.ts +++ b/src/store/trash/trash-actions.ts @@ -18,12 +18,13 @@ export const toggleProjectTrashed = async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise => { let errorMessage = ""; let successMessage = ""; + let untrashedResource; try { if (isTrashed) { errorMessage = "Could not restore project from trash"; successMessage = "Restored project from trash"; - await services.groupsService.untrash(uuid); - dispatch(isMulti ? navigateToTrash : navigateTo(uuid)); + untrashedResource = await services.groupsService.untrash(uuid); + dispatch(isMulti || !untrashedResource ? navigateToTrash : navigateTo(uuid)); dispatch(activateSidePanelTreeItem(uuid)); } else { errorMessage = "Could not move project to trash"; @@ -32,20 +33,31 @@ export const toggleProjectTrashed = dispatch(loadSidePanelTreeProjects(ownerUuid)); dispatch(navigateTo(ownerUuid)); } - dispatch( - snackbarActions.OPEN_SNACKBAR({ - message: successMessage, - hideDuration: 2000, - kind: SnackbarKind.SUCCESS, - }) - ); + if (untrashedResource) { + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: successMessage, + hideDuration: 2000, + kind: SnackbarKind.SUCCESS, + }) + ); + } } catch (e) { - dispatch( - snackbarActions.OPEN_SNACKBAR({ - message: errorMessage, - kind: SnackbarKind.ERROR, - }) - ); + if (e.status === 422) { + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: "Could not restore project from trash: Duplicate name at destination", + kind: SnackbarKind.ERROR, + }) + ); + } else { + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: errorMessage, + kind: SnackbarKind.ERROR, + }) + ); + } } }; @@ -78,12 +90,21 @@ export const toggleCollectionTrashed = }) ); } catch (e) { - dispatch( - snackbarActions.OPEN_SNACKBAR({ - message: errorMessage, - kind: SnackbarKind.ERROR, - }) - ); + if (e.status === 422) { + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: "Could not restore collection from trash: Duplicate name at destination", + kind: SnackbarKind.ERROR, + }) + ); + } else { + dispatch( + snackbarActions.OPEN_SNACKBAR({ + message: errorMessage, + kind: SnackbarKind.ERROR, + }) + ); + } } }; -- 2.30.2