Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(content-uploader): add onSelection callback (#3839) #3841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link

Description

This PR adds an onSelection callback to the ContentUploader component to allow developers to control file selection before upload begins. This implements the suggestion from issue #3839.

Changes

  • Added onSelection prop to ContentUploader component
  • Added TypeScript and Flow type definitions
  • Implemented file selection validation in UploadInput component
  • Added comprehensive test coverage for the new callback

Usage

<ContentUploader
  onSelection={(files) => {
    // Return false to prevent upload
    // Return true to allow upload to proceed
    return files.length <= 5; // Example: Only allow up to 5 files
  }}
  {...otherProps}
/>

Testing

  • Added unit tests for UploadInput component
  • Verified all tests pass
  • Ran lint checks via precommit hooks

Link to Devin run: https://app.devin.ai/sessions/acbecd8da4154ad8aba8d8d81d7bd661

Co-Authored-By: gregorywong@box.com <gregorywong@box.com>
@devin-ai-integration devin-ai-integration bot requested review from a team as code owners January 13, 2025 22:22
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@@ -42,7 +45,16 @@ const UploadInput = ({
data-testid="upload-input"
directory={isFolderUpload ? '' : undefined}
multiple={isMultiple}
onChange={onChange}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {

Choose a reason for hiding this comment

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

That comes handy when trying to upload files and their size exceeded 50mb (5010001000 as I figured Box doesn't like 5010241024 too much ;)).
Currnetly I handled it by observing classList string and reacting to the change after the onBeforeUpload fired and contentExplorer changed it's button classes etc.

if (onSelection && files) {
const shouldContinue = onSelection(files);
if (!shouldContinue) {
return;

Choose a reason for hiding this comment

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

Is there a way to clear out the file list other than doing files = ''?
I know there's clearCache for remote but it'd be helpful to be able to reset the form other than clicking cancel.

Lukortech added a commit to Lukortech/developer.box.com that referenced this pull request Jan 14, 2025
I've found some information scattered around the web about this UI element but the documentation doesn't mention this event and even more intruiguing is that it doesn't really work as I would expect it to. 

I should be able to validate files (like exceeded size, fileType) before even allowing user to click "upload" button. That's not the case and I've already got davin to write some code: 

box/box-ui-elements#3841
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