Skip to content

File Uploader#2013

Merged
karriebear merged 38 commits intostreamlit:feature/file-uploaderfrom
karriebear:file-uploader
Oct 8, 2020
Merged

File Uploader#2013
karriebear merged 38 commits intostreamlit:feature/file-uploaderfrom
karriebear:file-uploader

Conversation

@karriebear
Copy link
Copy Markdown
Contributor

@karriebear karriebear commented Sep 18, 2020

Completely redesigned st.file_uploader with the following additional features. The redesigned file uploader also closes out the following bugs. This redesign does not include file persistence on disk or file picker functionalities. (Closes #1202, Closes #831)

Features

Bugs

Demos

This is the initial set of changes. There are open items needed prior to release


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@karriebear karriebear force-pushed the file-uploader branch 5 times, most recently from 046f908 to 4901905 Compare September 22, 2020 06:54
@karriebear karriebear force-pushed the file-uploader branch 2 times, most recently from 977ccf4 to 2a7a575 Compare September 22, 2020 20:36
@karriebear karriebear force-pushed the file-uploader branch 17 times, most recently from 452be3b to 16513d0 Compare September 25, 2020 09:41
Copy link
Copy Markdown
Collaborator

@kantuni kantuni left a comment

Choose a reason for hiding this comment

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

Marvelous job! 🎸

P.S. Few comments (mostly nitpicking).


const multipleFiles: boolean = element.get("multipleFiles")
private delete = (fileId: string): void => {
const file = this.state.files.find(file => file.id === fileId)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will mutate the state as the file is returned as a reference. Instead copy the whole array first, then change the individual value. And again you would have to use setState((prevState) => {}) way of setting the state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup but here the mutation wouldn't trigger a component update and since we update the state right below, the mutation becomes outdated.

I don't think the function to update state is not necessary given that you can only delete one file at a time. There shouldn't be conflicting updates occurring.

I'm definitely an over optimizer so I find it unnecessary to do the above but can do so if it's thats our preference. Let me know!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From React documentation:

Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state.

I have spent too many hours debugging bugs caused by passing an object to setState.
Thus, I have a very strong opinion on this matter!

}
private removeFile = (fileId: string): void => {
const filteredFiles = this.state.files.filter(file => file.id !== fileId)
this.setState({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

)

return { files }
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kmcgrady, I would disagree. IMO, it's the correct way of setting the state here.

}

public onNext = (): void => {
this.setState({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should use the updater function.

unit: FileSizes,
rounding = 1
): string => {
if (!unit) unit = FileSizes.Byte
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any strong feelings with regards to one-line if statements?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nope, but if you do, we should put it as a linting rule instead

Copy link
Copy Markdown
Collaborator

@kantuni kantuni Oct 7, 2020

Choose a reason for hiding this comment

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

I do. It does look a lot cleaner to me. I'll add a task to the infra board.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@karriebear karriebear force-pushed the file-uploader branch 2 times, most recently from d51d2d4 to b2b8821 Compare October 7, 2020 17:59
@kmcgrady
Copy link
Copy Markdown
Collaborator

kmcgrady commented Oct 7, 2020

Awesome, work here are some bugs/UX challenges I observed.

Visual cutoff of error
image

Single File Upload doesn't indicate single file, especially when multiple rejected files exist.
image

Multiple of the same file combined with rejected files is confusing. My preference for single file is successful file first, followed by rejected in alphabetical order. Multiple files either in alphabetical order all together or successful in upload order followed by rejected in alphabetical order
image

Icon Buttons do not have hover/active/focus states.

Single File Uploader, removing the valid used file does not use the next valid file.
image

Display order does not match execution order.
image

color: $primary;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but disabled is not really used here. Probably not a use case right now, but one to note.

Copy link
Copy Markdown
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Changes to address challenges are in the works. Most issues are minor UX challenges that present a longer discussion. To merge in a feature branch, this is functional.

@karriebear karriebear removed the request for review from randyzwitch October 7, 2020 21:50
Copy link
Copy Markdown
Collaborator

@kantuni kantuni left a comment

Choose a reason for hiding this comment

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

Again, great work! 🚀

@karriebear karriebear merged commit 2c7a78e into streamlit:feature/file-uploader Oct 8, 2020
karriebear added a commit that referenced this pull request Oct 8, 2020
* File Uploader (#2013)

* Copying over

* Linting

* Missed copy - Hashing + Media support

* Sidebar UX cleanup

* Testing cleanup

* linting + cleanup

* E2E

* linting

* Fix unit tests

* Get snapshots

* Styling cleanup

* File sizing + state updating cleanup

* File sizing + state updating cleanup

* button cleanup + file deletion

* Separate dropzone instructions into a new file

* Separate dropzone instructions into a new file

* Linting

* Small/Error text styled componenting

* a11y uploaded files

* Spacing var

* Whoops + button updates

* Multile file uploader should return [] when empty

* Visual design updates

* linting/cleanup

* Revert rejectFiles change

* Fix tests

* Address PR comments

* Fix test

* addressing quick pr comments

* Whoops

* fix tests

* Readable tests

* setState with function

* [File Uploader] Update deprecation (#2123)

* Update deprecation

* Update test for deprecation

* Fix docstrings (#2121)

* [File Uploader] Missed visual tweaks (#2124)

* Quick visual tweaks

* linting

* [File uploader] Single upload reruns only once (#2122)

* Single file uploader replaces in 1 request

* Update comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants