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

Enhance FileChooser to allow better app-level handling of file rejections #3350

Open
amcclain opened this issue May 3, 2023 · 2 comments · May be fixed by #3538
Open

Enhance FileChooser to allow better app-level handling of file rejections #3350

amcclain opened this issue May 3, 2023 · 2 comments · May be fixed by #3538

Comments

@amcclain
Copy link
Member

amcclain commented May 3, 2023

The underlying react-dropzone that powers this component can be configured to reject files based on type and size, both of which are exposed as options in our API within FileChooserProps.

However the handling around rejected files is very limited. The model will set an observable lastRejectedCount property when a rejection occurs, but this does not appear to be cleared or otherwise incremented. This means that if you attempt to add a single file and its rejected, you will see the count go to 1, but if you try another (single) file the count will remain at 1 and no observable change occurs (this I would say is a straight-up bug, or at least useless enough to be effectively broken).

There is some code in the Hoist component that reads this value and looks like it should show a message, but I'm not seeing this work at all with our in-app usage.

The underlying API provides much more info on rejections in the form of a FileRejectionEvent with nested errors including messages that (presumably) help to explain what happened. If that were properly observable, or if the app could directly register a custom handler, an app could decide how it wanted to relay info to a user about why a file failed to "take" when dragged over the chooser or selected from the OS file browser. Right now it's just this silent failure, with no apparent workaround.

@amcclain
Copy link
Member Author

amcclain commented May 3, 2023

While we have this component open for surgery, let's also discuss if we want to make a breaking change to move its primary configuration to the model vs. component props.

@amcclain
Copy link
Member Author

amcclain commented May 3, 2023

In case we don't get to take this ticket on in the near future, here was a workaround I managed to implement - this function is run in a reaction to fileChooserModel.lastRejectedCount - note the need to reach in and reset that count to zero, as well as (continued) inability to explain precisely why we didn't accept it:

onFileRejected(rejected) {
        if (rejected > 0) {
            dangerToast(
                `Unable to accept file for upload - it may exceed the size limit of ${Math.round(
                    this.maxFileSize / 1000000
                )}MB or be of an unsupported type.`
            );
            runInAction(() => {
                this.fileChooserModel.lastRejectedCount = 0;
            });
        }
    }

@leogretz2 leogretz2 linked a pull request Nov 27, 2023 that will close this issue
6 tasks
@amcclain amcclain added the ready label Jun 20, 2024
@amcclain amcclain changed the title Enhance FileChooser to allow better app-level handling of file rejections Enhance FileChooser to allow better app-level handling of file rejections Jun 27, 2024
@PeteDarinzo PeteDarinzo self-assigned this Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants