Skip to content

Commit

Permalink
updated due to dropzone changes and fixed legacy bug in example
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrances17 committed Nov 25, 2024
1 parent f7cf56f commit f5d9764
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/react-core/src/components/FileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
dropzoneProps.onDropAccepted && dropzoneProps.onDropAccepted(acceptedFiles, event);
};

const onDropRejected = (rejectedFiles: FileRejection[], event: DropEvent, error: ErrorCode) => {
dropzoneProps.onDropRejected && dropzoneProps.onDropRejected(rejectedFiles, event, error);
const onDropRejected = (rejectedFiles: FileRejection[], event: DropEvent) => {
dropzoneProps.onDropRejected && dropzoneProps.onDropRejected(rejectedFiles, event);
};

const onClearButtonClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,25 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
setValue(value);
};

const handleClear = (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
const reset = () => {
setFilename('');
setValue('');
};

const handleClear = (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
reset();
setIsRejected(false);
};

const handleFileRejected = () => {
reset();
setIsRejected(true);
};

const handleFileAccepted = () => {
setIsRejected(false);
};

const handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(true);
};
Expand Down Expand Up @@ -69,11 +78,14 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
maxSize: 1024,
onDropRejected: (rejections) => {
const error = rejections[0].errors[0];
if (error.code === DropzoneErrorCode.FileInvalidType) {
setMessage('File must be a valid CSV file');
if (error.code === DropzoneErrorCode.FileTooLarge) {
setMessage('File is too big');
} else if (error.code === DropzoneErrorCode.FileInvalidType) {
setMessage('File is not a CSV file');
}
handleFileRejected();
}
},
onDropAccepted: handleFileAccepted
}}
validated={isRejected ? 'error' : 'default'}
browseButtonText="Upload"
Expand All @@ -84,7 +96,7 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
<HelperTextItem id="restricted-file-example-helpText" variant={isRejected ? 'error' : 'default'}>
{isRejected ? (
<>
<Icon status="danger">{/* <ExclamationCircleIcon /> */}</Icon>
<Icon status="danger" />
{message}
</>
) : (
Expand Down

0 comments on commit f5d9764

Please sign in to comment.