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

Add functionality to upload folder by dragging to file browser #10596

Merged
merged 21 commits into from
Jul 25, 2024

Conversation

Nazeeh21
Copy link
Contributor

@Nazeeh21 Nazeeh21 commented Jul 10, 2021

References

Add folder upload functionality, fixes #9838

Code changes

in packages/filebrowser/src/listing.ts
I have commented the previous code, which was displaying the dialog box if anyone tries to upload folders, and added the code to upload the folder.

User-facing changes

I haven't added any UI components. I have just removed the error dialog popping up while trying to upload the folder as shown below.
error-dialog
Instead of that, now it will upload the files from the folder.

Backwards-incompatible changes

I haven't implemented any backward-incompatible changes.

@welcome
Copy link

welcome bot commented Jul 10, 2021

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-dev-mode
Copy link

Thanks for making a pull request to JupyterLab!

To try out this branch on binder, follow this link: Binder

@krassowski
Copy link
Member

Thank you for working on this. Feel free to remove the commented code :)

I tried it on binder and found that while files are indeed uploaded, the directory structure is lost.

files-get-uploaded-but-dir-structure-lost

I think that ideally we would want to recreate the folders structures at upload. What do you think?

@krassowski
Copy link
Member

krassowski commented Jul 11, 2021

We had some short discussion with @blink1073 on the use of experimental API in this PR. I think that we are fine because over 90% of users and all browsers that we support already support this experimental API. However as recommended by MDN docs we should be very careful and defensive when using it; I would suggest checking support first and if it is not there then falling back to the error dialog.

Please let me know if you need help with creating new folders using JupyterLab filebrowser API.

@Nazeeh21
Copy link
Contributor Author

Thank you for working on this. Feel free to remove the commented code :)

I tried it on binder and found that while files are indeed uploaded, the directory structure is lost.

files-get-uploaded-but-dir-structure-lost

I think that ideally we would want to recreate the folders structures at upload. What do you think?

Yes, I also feel that retrieving the folder structure is necessary.
I will implement it soon and also I will remove the commented code in the next commit.

@Nazeeh21
Copy link
Contributor Author

We had some short discussion with @blink1073 on the use of experimental API in this PR. I think that we are fine because over 90% of users and all browsers that we support already support this experimental API. However as recommended by MDN docs we should be very careful and defensive when using it; I would suggest checking support first and if it is not there then falling back to the error dialog.

Please let me know if you need help with creating new folders using JupyterLab filebrowser API.

Yeah sure, I will check their support and will implement accordingly.

I'll try to implement folder creation. In case, I'll need your help I'll surely let you know. Thanks for asking. 😃

@Nazeeh21
Copy link
Contributor Author

We had some short discussion with @blink1073 on the use of experimental API in this PR. I think that we are fine because over 90% of users and all browsers that we support already support this experimental API. However as recommended by MDN docs we should be very careful and defensive when using it; I would suggest checking support first and if it is not there then falling back to the error dialog.

Please let me know if you need help with creating new folders using JupyterLab filebrowser API.

I got my head around with the createNewDirectory() function from browser.ts. But I am unable to figure out that how to access the FileBrowser class in addDirectory() function in listing.ts to create a new folder and renaming that folder.

Will you please help me with the same?

Also, after creating the folder. I am planning to call this._model.cd('/${folderName}') and upload files in that folder.

Will you please tell me if I am following the correct workflow or not? 😅

@krassowski
Copy link
Member

Yes you are going in the right direction. A very quick note that you probably do not want to use FileBrowser.createNewDirectory because in addition to creating a new directory it prompts user to rename it; instead we want to create a new directory and set its name programatically. Following the code I see that it calls manager's newUnititled() method. It seems to me from a quick glance that listing and browser share the same model so you should be able to get the manager from listing's model (something like this._model.manager.newUntitled). You would call the same newUntitled method but then instead of starting rename in browser GUI, trigger programatic rename using managers IDocumentManager.rename.

@Nazeeh21
Copy link
Contributor Author

Hey @krassowski, I have implemented the addExisting() , rename() and cd() functions here. But it is not renaming the newly created folder and is also not changing the current path. I tried working my head around with that but didn't get any workaround.

I have pushed the code. Will you please help me with the same?

@blink1073 blink1073 added this to the 4.0 milestone Jul 24, 2021
@Nazeeh21
Copy link
Contributor Author

@krassowski I made the addDirectory function async but that didn't work. From the errors, it seems that it is throwing an error in .cd() function while changing the directory only for the nested folders. I tried finding out the workaround but didn't find anything.

@krassowski
Copy link
Member

Ok, this is working now. Still may need some work to work faster. Ideally would have a test case. Still, I think it is an improvement worth considering for 4.3.0.

@krassowski
Copy link
Member

We can probably avoid changing the directory by adding a path argument to upload() method of the model. I will take a look another day.

Copy link
Member

@krassowski krassowski left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I would appreciate another review

@krassowski krassowski closed this Jul 24, 2024
@krassowski krassowski reopened this Jul 24, 2024
/**
* Signal emitted on when all files were uploaded after native drag.
*/
protected get uploadedAll(): ISignal<DirListing, void> {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like allUploaded reads better, and would be similar to the naming of other signals?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, done!

Copy link
Contributor

@JasonWeill JasonWeill left a comment

Choose a reason for hiding this comment

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

This looks great! I tested the change locally, and I noticed that it worked successfully. A progress meter would be useful when uploading a large directory or a directory with many large files in it, but that's already covered by #4687, so we shouldn't hold this PR up for that reason.

packages/filebrowser/src/listing.ts Outdated Show resolved Hide resolved
packages/filebrowser/src/listing.ts Outdated Show resolved Hide resolved
@krassowski
Copy link
Member

Hmm... this made me think that we could already use the progress bar if we moved the logic to the listing model. Actually, I think we should move the logic to model anyways so that it can be easily reused. This would also remove the need for allUploaded because we could listen to uploadChanged signal.

@krassowski
Copy link
Member

While I think that progress bar for the entire folder would be useful, I do not have bandwidth before 4.3 freeze. If we decide to move the logic to the model, the allUploaded signal can be easily made into a filter proxy of uploadChanged and deprecated (and it is a protected rather than a public member anyways). The question is only whether the public API in the model should be:

  • upload(something: File | FileSystemEntry, path?: str): Promise<Contents.IModel>, or
  • uploadEntry(entry: FileSystemEntry, path?: str): Promise<Contents.IModel>, or
  • uploadDirectory(directory: FileSystemDirectoryEntry, path?: str): Promise<Contents.IModel>

@krassowski krassowski changed the title Add functionality to upload folder Add functionality to upload folder by dragging to file browser Jul 25, 2024
@krassowski krassowski merged commit edd9769 into jupyterlab:main Jul 25, 2024
84 checks passed
@krassowski krassowski mentioned this pull request Aug 11, 2024
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JupyterLab drag-and-drop copy doesn't work for folders
5 participants