@@ -40,7 +40,7 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
4040 onFileReject,
4141 onUploadStateChange,
4242 maxSize = 200 * 1024 * 1024 ,
43- acceptedFileTypes = [ '.sql' ] , // Accept only .sql files
43+ acceptedFileTypes = [ '.sql' ] , // Accept only .sql files by extension
4444 selectedCurrentLanguage,
4545 selectedTargetLanguage
4646} ) => {
@@ -163,34 +163,42 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
163163
164164 const onDrop = useCallback (
165165 ( acceptedFiles : File [ ] , fileRejections : FileRejection [ ] ) => {
166+ // Manual extension check: only allow .sql files
167+ const validFiles = acceptedFiles . filter ( file => file . name . toLowerCase ( ) . endsWith ( '.sql' ) ) ;
168+ const invalidFiles = acceptedFiles . filter ( file => ! file . name . toLowerCase ( ) . endsWith ( '.sql' ) ) ;
169+
166170 // Check current files count and determine how many more can be added
167171 const remainingSlots = MAX_FILES - uploadingFiles . length ;
168172
173+
174+ if ( validFiles . length > 0 ) {
175+ setFileRejectionErrors ( [ ] ) ; // Clear error notification when valid file is selected
176+ }
177+
169178 if ( remainingSlots <= 0 ) {
170- // Already at max files, show dialog
171179 setShowFileLimitDialog ( true ) ;
172180 return ;
173181 }
174182
175183 // If more files are dropped than slots available
176- if ( acceptedFiles . length > remainingSlots ) {
177- // Take only the first `remainingSlots` files
178- const filesToUpload = acceptedFiles . slice ( 0 , remainingSlots ) ;
184+ if ( validFiles . length > remainingSlots ) {
185+ const filesToUpload = validFiles . slice ( 0 , remainingSlots ) ;
179186 filesToUpload . forEach ( file => simulateFileUpload ( file ) ) ;
180-
181187 if ( onFileUpload ) onFileUpload ( filesToUpload ) ;
182-
183- // Show dialog about exceeding limit
184188 setShowFileLimitDialog ( true ) ;
185189 } else {
186- // Normal case, upload all files
187- acceptedFiles . forEach ( file => simulateFileUpload ( file ) ) ;
188- if ( onFileUpload ) onFileUpload ( acceptedFiles ) ;
190+ validFiles . forEach ( file => simulateFileUpload ( file ) ) ;
191+ if ( onFileUpload ) onFileUpload ( validFiles ) ;
189192 }
190193
194+ // Build error messages for invalid extension files
195+ const errors : string [ ] = [ ] ;
196+ invalidFiles . forEach ( file => {
197+ errors . push ( `File '${ file . name } ' is not a valid SQL file. Only .sql files are allowed.` ) ;
198+ } ) ;
199+
200+ // Existing fileRejections (size/type)
191201 if ( fileRejections . length > 0 ) {
192- // Build error messages for each rejection
193- const errors : string [ ] = [ ] ;
194202 fileRejections . forEach ( rejection => {
195203 rejection . errors . forEach ( err => {
196204 if ( err . code === "file-too-large" ) {
@@ -202,9 +210,11 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
202210 }
203211 } ) ;
204212 } ) ;
205- setFileRejectionErrors ( errors ) ;
206213 if ( onFileReject ) onFileReject ( fileRejections ) ;
207214 }
215+ if ( errors . length > 0 ) {
216+ setFileRejectionErrors ( errors ) ;
217+ }
208218 } ,
209219 [ onFileUpload , onFileReject , uploadingFiles . length ]
210220 ) ;
@@ -213,7 +223,7 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
213223 onDrop,
214224 noClick : true ,
215225 maxSize,
216- accept : acceptedFileTypes , // Only .sql files
226+ accept : acceptedFileTypes , // Only .sql files regardless of mime type
217227 //maxFiles: MAX_FILES,
218228 } ;
219229
@@ -362,22 +372,6 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
362372
363373 return (
364374 < div style = { { width : '100%' , minWidth : '720px' , maxWidth : '800px' , margin : '0 auto' , marginTop : '0' , padding : '16px' , paddingBottom : '60px' } } >
365- { /* Show file rejection errors for invalid type or size at the very top */ }
366- { fileRejectionErrors . length > 0 && (
367- < MessageBar
368- messageBarType = { MessageBarType . error }
369- isMultiline = { true }
370- onDismiss = { ( ) => setFileRejectionErrors ( [ ] ) }
371- dismissButtonAriaLabel = "Close"
372- styles = { { root : { display : "flex" , alignItems : "left" , background : "#fff4f4" , marginBottom : "16px" } } }
373- >
374- < div style = { { display : "flex" , flexDirection : "column" , alignItems : "left" } } >
375- { fileRejectionErrors . map ( ( err , idx ) => (
376- < span key = { idx } style = { { marginBottom : "4px" } } > { err } </ span >
377- ) ) }
378- </ div >
379- </ MessageBar >
380- ) }
381375 < ConfirmationDialog
382376 open = { showCancelDialog }
383377 setOpen = { setShowCancelDialog }
@@ -554,13 +548,11 @@ const FileUploadZone: React.FC<FileUploadZoneProps> = ({
554548 < div style = { { display : 'flex' , flexDirection : 'column' , gap : '13px' , width : '837px' , paddingBottom : 10 , borderRadius : '4px' , } } >
555549 { /* Show file rejection errors for invalid type or size */ }
556550 { fileRejectionErrors . length > 0 && (
557- < MessageBar
558- messageBarType = { MessageBarType . error }
559- isMultiline = { true }
560- onDismiss = { ( ) => setFileRejectionErrors ( [ ] ) }
561- dismissButtonAriaLabel = "Close"
562- styles = { { root : { display : "flex" , alignItems : "left" , background : "#fff4f4" } } }
563- >
551+ < MessageBar
552+ messageBarType = { MessageBarType . error }
553+ isMultiline = { true }
554+ styles = { { root : { display : "flex" , alignItems : "left" , background : "#fff4f4" , width : "inherit" } } }
555+ >
564556 < div style = { { display : "flex" , flexDirection : "column" , alignItems : "left" } } >
565557 { fileRejectionErrors . map ( ( err , idx ) => (
566558 < span key = { idx } style = { { marginBottom : "4px" } } > { err } </ span >
0 commit comments