fix: only show loading in FileSelectComponent when listing files#3157
fix: only show loading in FileSelectComponent when listing files#3157dl-alexandre wants to merge 5 commits intolivebook-dev:mainfrom
Conversation
|
Only one nitpick and we're good to go |
| dir_changed? = dir != assigns.current_dir | ||
|
|
||
| # Only show loading when changing directories (which requires listing files) | ||
| socket = if dir_changed?, do: assign(socket, :loading, true), else: socket |
There was a problem hiding this comment.
We set loading to true here, but at the end of this function we set it to false. This means that loading is actually never true when we render the UI.
The listing files should happen in a task via start_async.
| refute render_component(FileSelectComponent, attrs(file: file)) =~ ".." | ||
| end | ||
|
|
||
| test "shows loading when changing directories" do |
There was a problem hiding this comment.
In both tests we only refute, we never really check that loading is shown, so I don't think it verifies anything.
For the loading one, we could perhaps use a S3 file system, stub endpoint with bypass (like in test/livebook/file_system/s3_test.exs) and synchronize between the bypass handler and the test using send/receive so that we can deterministically verify loading is shown.
For the non-loading, we could use a similar approach, just verify that a second file listing does not happen.
|
Hi @aleDsz and @jonatanklosko, Thank you both for the thorough reviews! I've addressed the feedback: Changes made:
Regarding testing the intermediate Please let me know if you'd like any additional changes! |
|
@dl-alexandre Could you rebase your PR with the main branch? Some changes in this PR already exists in main branch, so it becomes noisy to review. |
Moves loading state management from event handlers into update_file_infos/2 to ensure loading indicator only appears when actually fetching directory listings, not when running_files changes (e.g., notebooks start/stop). - Remove upfront loading assignments in set_file_system and set_path - Set loading only when dir != current_dir in update_file_infos - Add tests for loading behavior with directory vs running_files changes Fixes livebook-dev#3111
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
d1d6740 to
d349ea1
Compare
|
@@aleDsz Done! I've rebased the PR with the main branch. What was cleaned up:
Files changed:
The PR is now clean and ready for review! |
|
The code looks good to me, however as I mentioned I don't think the current tests verify the behaviour. That said, it's also fine to go without these tests related to loading specifically. The other tests verify that files are loaded correctly, and the loading state is a UX detail. |
Ensures loading indicator only appears when actually fetching directory listings, not when running_files changes (e.g., notebooks start/stop).
Fixes #3111