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: multiple file support for file_drop #562

Conversation

hkayabilisim
Copy link
Contributor

Added multiple file support to file_drop component.
Same as the original component, directories are simply ignored. Multiple file support was actually embedded in the underlying VUE scripts. I've done minor changes.

Compatibility:
on_file callback function now accepts List[FileInfo] as opposed to single FileInfo object. This may bring some problems for existing codes. As a remedy, if the number of files is just one, we can return a single FileInfo. If not, we return list. I leave it up to you to decide.

This is related to: #260

Copy link
Contributor

@mariobuikhuizen mariobuikhuizen left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @hkayabilisim!

We would like to keep this component backward compatible. We could accomplish this by adding an argument multiple with a default value of False and have on_file also work with a single file (see this for an example of the typing, note the argument optional: Literal[False])

solara/components/file_drop.vue Outdated Show resolved Hide resolved
solara/components/file_drop.vue Outdated Show resolved Hide resolved
Copy link
Contributor Author

@hkayabilisim hkayabilisim left a comment

Choose a reason for hiding this comment

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

missing ';' at the end of the "padding:" line was causing CSS problem.

Copy link
Contributor Author

@hkayabilisim hkayabilisim left a comment

Choose a reason for hiding this comment

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

Changes required for backward compatibility:

  1. multiple property is added to FileDrop
  2. Two different on_file callback signature used: FileInfo and List[FileInfo]
  3. FileDrop is overloaded to match two different on_file signatures.
  4. FileDrop apidoc is updated
  5. FileDrop example is updated
  6. bullet list in VUE template is removed
  7. isFile property is always set to True (this was a hidden bug)
  8. app/scatter.py is reverted to original version

Copy link
Contributor Author

@hkayabilisim hkayabilisim left a comment

Choose a reason for hiding this comment

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

@maartenbreddels
Copy link
Contributor

Looking good!
A few issues

Looking forward to see this green in CI, and get this merged 🥳

@hkayabilisim hkayabilisim force-pushed the multiple_file_support_for_file_drop branch from 7d44858 to 0c33e33 Compare March 21, 2024 20:27
@hkayabilisim hkayabilisim reopened this Mar 21, 2024
@hkayabilisim
Copy link
Contributor Author

hkayabilisim commented Mar 21, 2024

  • Used "multiple" option in file_drop.vue to list single file in drop zone when multiple is not selected. However, I couldn't propogate "multiple" to further inside Vue to prevent processing multiple file when multiple is not selected. I don't think this is a big issue.
  • I could select a wrong return type from FileDrop. I guess, it must have been reacton.core.something but couldn't find it properly.
  • I used pre-commit to clean style issues but couldn't solve the following one. So, I had to disable pre-commit right before commit:
image

@hkayabilisim
Copy link
Contributor Author

Hi @maartenbreddels

There is only one error I couldn't resolve. Help needed!

image

@maartenbreddels
Copy link
Contributor

Hi Huseyin,

we had quite a long discussion internally on this PR.
For ToggleButton https://github.com/widgetti/solara/blob/master/solara/components/togglebuttons.py we had two different components

  • ToggleButtonsSingle
  • ToggleButtonsMultiple

This is because otherwise the typing becomes quite complex (as you can see now for FileDrop), and it only works for literals. So if you want to take advantage of the typing you need to do:

if multiple:
  FileDrop(..., multiple=True)
else:
  FileDrop(..., multiple=False)

Which is a bit odd. For this reason, it might be better to have
FileDrop and FileDropMultiple (they can call the same internal component btw, it's just the public API)

However, also that would be inconsistent in the naming, so either solution is not perfect.

Two questions:

  1. What do you think about the typing and one vs two components
  2. If you also prefer FileDropMultiple, are you willing to do the changes? If not, we're happy to help.

Let us know, and thanks you for your help on this.

Regards,

Maarten

@hkayabilisim
Copy link
Contributor Author

Hi Maarten,

Getting rid of some complexity by creating two variants (FileDrop and FileDropMultiple) seems a good idea.

I've just created FileDropMultiple and commited to the branch and tested little bit (fa6cd23). It seems ok, and CI checks are green. Yet, you should revise my implementation in case if I missed some points.

Sincerely
Huseyin

@maartenbreddels
Copy link
Contributor

Hi Huseyin,

whow, many thank for doing all this work!
CI looks green (ignore that failing one, that's not related to what you do)
Will review after the weekend probably. Have a good weekend.

Regards,

Maarten

Copy link
Contributor

@maartenbreddels maartenbreddels left a comment

Choose a reason for hiding this comment

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

Awesome work.
Let me know if you have the energy to do these last changes. I know we're asking a lot from you, so we are happy to do the last mile.

solara/components/file_drop.py Outdated Show resolved Hide resolved
solara/components/file_drop.py Outdated Show resolved Hide resolved
solara/components/file_drop.py Outdated Show resolved Hide resolved
@hkayabilisim
Copy link
Contributor Author

No problem Maarten! I've added _FileDrop to prevent code repetitions. I hope this is what you have in your mind!

Copy link
Contributor Author

@hkayabilisim hkayabilisim left a comment

Choose a reason for hiding this comment

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

It may not fit 100% to the code styling requirements but I think my last commit e5e6f40 solves most of the highlighted issues.

One of the checks keeps failing but I couldn't understand why.

@maartenbreddels maartenbreddels force-pushed the multiple_file_support_for_file_drop branch from e5e6f40 to 4ca3871 Compare March 25, 2024 14:00
@iisakkirotko
Copy link
Collaborator

Hi @hkayabilisim! Just wanted to let you know that the CI failure is still unrelated, it should be fixed by #574. We'll try to get this PR in soon™️ :)

@maartenbreddels maartenbreddels force-pushed the multiple_file_support_for_file_drop branch 2 times, most recently from fb71402 to 2589372 Compare March 27, 2024 10:36
hkayabilisim and others added 2 commits March 27, 2024 12:17
Co-authored-by: Iisakki Rotko <iisakki.rotko@gmail.com>
"Navigation to X is interrupted to another navigation to Y"

In the logs we see:
```
FAILED tests/integration/ssg_test.py::test_ssg[starlette-chromium] - playwright._impl._errors.Error: Navigation to "http://localhost:18768/" is interrupted by another navigation to "http://localhost:18768/"
FAILED tests/integration/starlette_test.py::test_starlette_mount[starlette-chromium] - playwright._impl._errors.Error: Navigation to "http://localhost:18770/solara_mount/" is interrupted by another navigation to "http://localhost:18768/"
ERROR tests/integration/widget_test.py::test_widget_button_solara[starlette-chromium] - playwright._impl._errors.Error: Navigation to "http://localhost:18768/?id=4004e29b-a9e6-4b1e-9652-7b1c61ef86cd" is interrupted by another navigation to "http://localhost:18770/solara_mount/"
ERROR tests/integration/widget_test.py::test_solara_button_all[starlette-solara-chromium] - playwright._impl._errors.Error: Navigation to "http://localhost:18768/?id=c8f0b1fb-abdb-4969-b340-1156d2699783" is interrupted by another navigation to "http://localhost:18768/?id=4004e29b-a9e6-4b1e-9652-7b1c61ef86cd"
ERROR tests/integration/widget_test.py::test_slider_all[starlette-solara-chromium] - playwright._impl._errors.Error: Navigation to "http://localhost:18768/?id=680f1fc7-5a19-4e1c-a382-088f2ec96b78" is interrupted by another navigation to "http://localhost:18768/?id=c8f0b1fb-abdb-4969-b340-1156d2699783"
```
@maartenbreddels maartenbreddels force-pushed the multiple_file_support_for_file_drop branch from 2589372 to 5075405 Compare March 27, 2024 11:17
@maartenbreddels maartenbreddels merged commit c8ab5f6 into widgetti:master Mar 27, 2024
23 checks passed
@maartenbreddels
Copy link
Contributor

This branch had some flakiness that we wanted to attack (see the last commit) before merging it. Thanks for your patience!

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.

None yet

4 participants