ENG-7732: plumb through Upload.on_drop_rejected#5806
Conversation
Allow user to supply an event handler for dropped files that do not meet the defined criteria. By default it will display an error toast with the file names and rejection reasons.
There was a problem hiding this comment.
Greptile Summary
This PR adds support for handling rejected files in the Upload component by introducing an on_drop_rejected event handler. The implementation provides user feedback when dropped files don't meet the specified criteria (file type, size, count limits, etc.).
The key changes include:
- New default rejection handler: A
_default_drop_rejectedfunction that displays informative error toast messages showing rejected file names and specific rejection reasons - Event handler properties: Added
on_drop_rejectedEventHandler fields to bothUploadandGhostUploadclasses with the same type signature as the existingon_drophandler - Consistent event processing: Updated the component creation logic to handle
on_drop_rejectedevents using the same pattern ason_drop, including proper EventSpec processing and argument handling - Backward compatibility: The implementation maintains full backward compatibility by providing sensible defaults while allowing customization
The integration follows Reflex's established patterns for event handling in the Upload component. The default toast-based feedback uses toast.error() with formatted rejection messages, providing immediate visual feedback to users about why their files weren't accepted. The implementation leverages the existing _on_drop_spec type signature and event processing infrastructure, ensuring consistency with the component's architecture.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it extends existing functionality without breaking changes
- Score reflects well-implemented feature following established patterns, but lacks visible test coverage
- Pay close attention to the event handler processing logic and default toast implementation
2 files reviewed, 3 comments
| upload_props["on_drop"] = on_drop | ||
|
|
||
| if upload_props.get("on_drop_rejected") is None: | ||
| # If on_drop is not provided, save files to be uploaded later. |
There was a problem hiding this comment.
syntax: Comment is misleading - should say 'on_drop_rejected' not 'on_drop'
| # If on_drop is not provided, save files to be uploaded later. | |
| # If on_drop_rejected is not provided, use the default rejection handler. |
CodSpeed Performance ReportMerging #5806 will not alter performanceComparing Summary
|
2ee408b to
e418aac
Compare
Allow user to supply an event handler for dropped files that do not meet the defined criteria.
By default it will display an error toast with the file names and rejection reasons.