Skip to content

Commit 9a90a6b

Browse files
file upload changes commit
1 parent 6d322c6 commit 9a90a6b

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/frontend/src/components/uploadButton.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
5252
const [batchId, setBatchId] = useState<string>(uuidv4());
5353
const [allUploadsComplete, setAllUploadsComplete] = useState(false);
5454
const [fileLimitExceeded, setFileLimitExceeded] = useState(false);
55+
const [fileRejectionErrors, setFileRejectionErrors] = useState<string[]>([]);
5556
const [showFileLimitDialog, setShowFileLimitDialog] = useState(false);
5657
const navigate = useNavigate();
5758

@@ -187,8 +188,22 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
187188
if (onFileUpload) onFileUpload(acceptedFiles);
188189
}
189190

190-
if (onFileReject && fileRejections.length > 0) {
191-
onFileReject(fileRejections);
191+
if (fileRejections.length > 0) {
192+
// Build error messages for each rejection
193+
const errors: string[] = [];
194+
fileRejections.forEach(rejection => {
195+
rejection.errors.forEach(err => {
196+
if (err.code === "file-too-large") {
197+
errors.push(`File '${rejection.file.name}' exceeds the 200MB size limit.`);
198+
} else if (err.code === "file-invalid-type") {
199+
errors.push(`File '${rejection.file.name}' is not a valid SQL file.`);
200+
} else {
201+
errors.push(`File '${rejection.file.name}': ${err.message}`);
202+
}
203+
});
204+
});
205+
setFileRejectionErrors(errors);
206+
if (onFileReject) onFileReject(fileRejections);
192207
}
193208
},
194209
[onFileUpload, onFileReject, uploadingFiles.length]
@@ -521,6 +536,22 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
521536
</div>
522537

523538
<div style={{ display: 'flex', flexDirection: 'column', gap: '13px', width: '837px', paddingBottom: 10, borderRadius: '4px', }}>
539+
{/* Show file rejection errors for invalid type or size */}
540+
{fileRejectionErrors.length > 0 && (
541+
<MessageBar
542+
messageBarType={MessageBarType.error}
543+
isMultiline={true}
544+
onDismiss={() => setFileRejectionErrors([])}
545+
dismissButtonAriaLabel="Close"
546+
styles={{ root: { display: "flex", alignItems: "left", background: "#fff4f4" } }}
547+
>
548+
<div style={{ display: "flex", flexDirection: "column", alignItems: "left" }}>
549+
{fileRejectionErrors.map((err, idx) => (
550+
<span key={idx} style={{ marginBottom: "4px" }}>{err}</span>
551+
))}
552+
</div>
553+
</MessageBar>
554+
)}
524555
{/* Show network error message bar if any file has error */}
525556
{uploadingFiles.some(f => f.status === 'error') && (
526557
<MessageBar

0 commit comments

Comments
 (0)