Skip to content

ENG-7732: plumb through Upload.on_drop_rejected#5806

Merged
adhami3310 merged 1 commit into
mainfrom
masenf/upload-drop-rejected
Sep 22, 2025
Merged

ENG-7732: plumb through Upload.on_drop_rejected#5806
adhami3310 merged 1 commit into
mainfrom
masenf/upload-drop-rejected

Conversation

@masenf

@masenf masenf commented Sep 20, 2025

Copy link
Copy Markdown
Collaborator

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.

image

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.
@linear

linear Bot commented Sep 20, 2025

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. New default rejection handler: A _default_drop_rejected function that displays informative error toast messages showing rejected file names and specific rejection reasons
  2. Event handler properties: Added on_drop_rejected EventHandler fields to both Upload and GhostUpload classes with the same type signature as the existing on_drop handler
  3. Consistent event processing: Updated the component creation logic to handle on_drop_rejected events using the same pattern as on_drop, including proper EventSpec processing and argument handling
  4. 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

Edit Code Review Bot Settings | Greptile

Comment thread reflex/components/core/upload.py Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: Comment is misleading - should say 'on_drop_rejected' not 'on_drop'

Suggested change
# 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-hq

codspeed-hq Bot commented Sep 20, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5806 will not alter performance

Comparing masenf/upload-drop-rejected (e418aac) with main (4468e14)

Summary

✅ 8 untouched

@masenf masenf force-pushed the masenf/upload-drop-rejected branch from 2ee408b to e418aac Compare September 22, 2025 16:16
@adhami3310 adhami3310 merged commit a3c14e7 into main Sep 22, 2025
41 checks passed
@adhami3310 adhami3310 deleted the masenf/upload-drop-rejected branch September 22, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants