-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add error handling for failed file uploads #3369
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { visuallyHidden } from "@mui/utils"; | |
import { FileUploadSlot } from "@planx/components/FileUpload/Public"; | ||
import ImagePreview from "components/ImagePreview"; | ||
import React from "react"; | ||
import ErrorWrapper from "ui/shared/ErrorWrapper"; | ||
|
||
interface Props extends FileUploadSlot { | ||
removeFile: () => void; | ||
|
@@ -19,12 +20,12 @@ interface Props extends FileUploadSlot { | |
} | ||
|
||
const Root = styled(Box)(({ theme }) => ({ | ||
border: `1px solid ${theme.palette.border.main}`, | ||
marginBottom: theme.spacing(0.5), | ||
marginTop: theme.spacing(5), | ||
})); | ||
|
||
const FileCard = styled(Box)(({ theme }) => ({ | ||
border: `1px solid ${theme.palette.border.main}`, | ||
position: "relative", | ||
height: "auto", | ||
display: "flex", | ||
|
@@ -91,74 +92,89 @@ export const UploadedFileCard: React.FC<Props> = ({ | |
removeFile, | ||
onChange, | ||
tags, | ||
status, | ||
}) => ( | ||
<Root> | ||
<FileCard> | ||
<ProgressBar | ||
width={`${Math.min(Math.ceil(progress * 100), 100)}%`} | ||
role="progressbar" | ||
aria-valuenow={progress * 100 || 0} | ||
aria-label={file.path} | ||
/> | ||
<FilePreview> | ||
{file instanceof File && file?.type?.includes("image") ? ( | ||
<ImagePreview file={file} url={url} /> | ||
) : ( | ||
<FileIcon /> | ||
)} | ||
</FilePreview> | ||
<Box | ||
sx={{ display: "flex", justifyContent: "space-between", width: "100%" }} | ||
> | ||
<Box mr={2}> | ||
<Typography | ||
variant="body1" | ||
pb="0.25em" | ||
sx={{ overflowWrap: "break-word", wordBreak: "break-all" }} | ||
<ErrorWrapper | ||
error={ | ||
status === "error" | ||
? "Upload failed, please remove file and try again" | ||
: undefined | ||
} | ||
> | ||
Comment on lines
+98
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this wrapper is the change here, the diff below is purely a whitespace change due to the extra indentation but git hasn't quite caught this. |
||
<> | ||
<FileCard> | ||
<ProgressBar | ||
width={`${Math.min(Math.ceil(progress * 100), 100)}%`} | ||
role="progressbar" | ||
aria-valuenow={progress * 100 || 0} | ||
aria-label={file.path} | ||
/> | ||
<FilePreview> | ||
{file instanceof File && file?.type?.includes("image") ? ( | ||
<ImagePreview file={file} url={url} /> | ||
) : ( | ||
<FileIcon /> | ||
)} | ||
</FilePreview> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "space-between", | ||
width: "100%", | ||
}} | ||
> | ||
{file.path} | ||
</Typography> | ||
<FileSize variant="body2">{formatBytes(file.size)}</FileSize> | ||
</Box> | ||
{removeFile && ( | ||
<IconButton | ||
size="small" | ||
aria-label={`Delete ${file.path}`} | ||
title={`Delete ${file.path}`} | ||
onClick={removeFile} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
)} | ||
</Box> | ||
</FileCard> | ||
{tags && ( | ||
<TagRoot> | ||
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 1 }}> | ||
{tags.map((tag) => ( | ||
<ListItem key={tag} disablePadding sx={{ width: "auto" }}> | ||
<Chip | ||
label={tag} | ||
variant="uploadedFileTag" | ||
<Box mr={2}> | ||
<Typography | ||
variant="body1" | ||
pb="0.25em" | ||
sx={{ overflowWrap: "break-word", wordBreak: "break-all" }} | ||
> | ||
{file.path} | ||
</Typography> | ||
<FileSize variant="body2">{formatBytes(file.size)}</FileSize> | ||
</Box> | ||
{removeFile && ( | ||
<IconButton | ||
size="small" | ||
data-testid="uploaded-file-chip" | ||
/> | ||
</ListItem> | ||
))} | ||
</Box> | ||
<Link | ||
onClick={() => onChange && onChange()} | ||
sx={{ fontFamily: "inherit", fontSize: "inherit" }} | ||
component="button" | ||
variant="body2" | ||
> | ||
Change | ||
<Box sx={visuallyHidden} component="span"> | ||
the list of what file {file.path} shows | ||
aria-label={`Delete ${file.path}`} | ||
title={`Delete ${file.path}`} | ||
onClick={removeFile} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
)} | ||
</Box> | ||
</Link> | ||
</TagRoot> | ||
)} | ||
</FileCard> | ||
{tags && ( | ||
<TagRoot> | ||
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 1 }}> | ||
{tags.map((tag) => ( | ||
<ListItem key={tag} disablePadding sx={{ width: "auto" }}> | ||
<Chip | ||
label={tag} | ||
variant="uploadedFileTag" | ||
size="small" | ||
data-testid="uploaded-file-chip" | ||
/> | ||
</ListItem> | ||
))} | ||
</Box> | ||
<Link | ||
onClick={() => onChange && onChange()} | ||
sx={{ fontFamily: "inherit", fontSize: "inherit" }} | ||
component="button" | ||
variant="body2" | ||
> | ||
Change | ||
<Box sx={visuallyHidden} component="span"> | ||
the list of what file {file.path} shows | ||
</Box> | ||
</Link> | ||
</TagRoot> | ||
)} | ||
</> | ||
</ErrorWrapper> | ||
</Root> | ||
); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ianjon3s Having a condition here on the
isValid
prop means that the "Continue" button is disabled, which goes against our general a11y principles.Did we ever discuss this one, or is removing this here the right way to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I think I missed this one when inventoring / fixing disabled "Continue" buttons here if you want to add to existing Trello checklist for collective memory! https://trello.com/c/elmTB1Pq/2828-disabled-buttons-and-unexpected-input-functionality-usability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually removed it in this PR - added to checklist and marked as done!