From 0c1905ae0d57ba825885774f4115f7545af34787 Mon Sep 17 00:00:00 2001 From: PintoGideon Date: Fri, 10 May 2024 10:14:25 -0400 Subject: [PATCH] feat: Improve error handling for folder downloads in the Cart --- src/components/NewLibrary/Cart.tsx | 50 +++++++++++++++------ src/components/NewLibrary/context/index.tsx | 2 + 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/components/NewLibrary/Cart.tsx b/src/components/NewLibrary/Cart.tsx index 4afa27f1f..085759132 100644 --- a/src/components/NewLibrary/Cart.tsx +++ b/src/components/NewLibrary/Cart.tsx @@ -3,7 +3,7 @@ import type { FileBrowserFolder, Feed, } from "@fnndsc/chrisapi"; -import { Button, Grid, GridItem, Tooltip } from "@patternfly/react-core"; +import { Button, Grid, GridItem, Tooltip, Text } from "@patternfly/react-core"; import { Drawer, List } from "antd"; import { useContext } from "react"; import { DotsIndicator } from "../Common"; @@ -71,6 +71,8 @@ export const Status = ({ item }: { item: SelectionPayload }) => { variant="plain" icon={} /> + ) : currentStatus === FolderDownloadTypes.cancelled ? ( + Cancelled ) : currentStatus ? ( ) : null} @@ -121,18 +123,32 @@ const Cart = ({ FolderDownloadTypes.started, ), ); + try { + const path = payload.data.path; + const cannotDownload = [ + "home", + `home/${username}`, + `home/${username}/uploads`, + "SERVICES", + ]; + + if (cannotDownload.includes(path)) { + throw new Error( + `Please avoid zipping folders listed here: ${cannotDownload.join( + ", ", + )}`, + ); + } - const path = payload.data.path; - const client = ChrisAPIClient.getClient(); + const client = ChrisAPIClient.getClient(); - dispatch( - downloadFolderStatus( - payload as FileBrowserFolder, - FolderDownloadTypes.creatingFeed, - ), - ); + dispatch( + downloadFolderStatus( + payload as FileBrowserFolder, + FolderDownloadTypes.creatingFeed, + ), + ); - try { const dircopy = await getPlugin("pl-dircopy"); if (!dircopy) { @@ -173,9 +189,9 @@ const Cart = ({ name: "zip v20240311", }); - if (!pipelineList) { + if (!pipelineList.data) { throw new Error( - "Is the zip pipeline registered with the name zip v20240311", + "Is the zip pipeline registered with the name zip v20240311?", ); } @@ -239,7 +255,13 @@ const Cart = ({ } } } catch (e) { - // biome-ignore lint/complexity/noUselessCatch: + console.log("ERROR"); + dispatch( + downloadFolderStatus( + payload as FileBrowserFolder, + FolderDownloadTypes.cancelled, + ), + ); throw e; } } @@ -333,7 +355,7 @@ const Cart = ({ ); }} /> - {isError && } + {isError && } ); }; diff --git a/src/components/NewLibrary/context/index.tsx b/src/components/NewLibrary/context/index.tsx index e3612efc5..7e4223198 100644 --- a/src/components/NewLibrary/context/index.tsx +++ b/src/components/NewLibrary/context/index.tsx @@ -53,6 +53,7 @@ export enum DownloadTypes { started = "STARTED", progress = "PROGRESS", finished = "FINISHED", + cancelled = "CANCELLED", } export enum FolderDownloadTypes { @@ -61,6 +62,7 @@ export enum FolderDownloadTypes { zippingFolder = "ZIPPING_FOLDER", startingDownload = "STARTING_DOWNLOAD", finished = "FINISHED", + cancelled = "CANCELLED", } export type LibraryPayload = {