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

Fix rename for tree view (Jupyter 3.6.x) #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skbitsp
Copy link

@skbitsp skbitsp commented Mar 18, 2024

This code change addresses an issue where the rename functionality was not working correctly in the JupyterLab tree view extension. The problem stemmed from the fact that the model.path attribute in the extension contained the complete path, while in operating systems, only the parent path is typically considered as the path. To resolve this issue, the rename method of DirListing—the class extended by the tree view extension was overridden.

In the tree view extension, the model.path attribute contains the complete path, whereas it typically should represent only the parent path. This discrepancy caused the rename functionality to fail in the tree view. To fix this, the code was modified to customize the DirListing class, taking a patch from JupyterLab version we are importing (3.6.*). By overriding the rename method, we ensure that the correct path is used for renaming files and folders.

Please note that this fix will only work for Jupyter 3.6.x (since the DirListing rename code is taken from that branch). For other versions also, something similar needs to be done, i.e. patch the code of rename method.

Tested on local

rename-tree-viewgif

Copy link

Binder 👈 Launch a Binder on branch skbitsp/jupyterlab-unfold/master

@skbitsp skbitsp mentioned this pull request Mar 18, 2024
Copy link
Contributor

@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.

@skbitsp thank you for working on this. A bit more work is needed to merge this:

  • JupyterLab 3 is nearing end of maintenance in two months time (JupyterLab 3 — May 15, 2024 end of maintenance jupyterlab/jupyterlab#15921, https://blog.jupyter.org/jupyterlab-3-end-of-maintenance-879778927db2) and since this extension currently supports JupyterLab 4 I don't think we can merge code which only works on 3.x.
  • while adding a CustomDirListing sounds all right, it should not use the private methods of DirListing; ideally the DirListing in core JupyterLab would be amended so that it either works out of the box without a need for subclassing (preferred), or so that only public/protected attributes/methods are accessed in the rename() override.
  • this PR includes a bunch of code which is not needed, and includes @ts-nocheck and @ts-ignore which goes against the quality requirements

/**
* Format bytes to human readable string.
*/
export function formatFileSize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it added?

/**
* Get the index of the node at a client position, or `-1`.
*/
export function hitTestNodes(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not used anywhere.

/**
* Sort a list of items by sort state as a new array.
*/
export function sort(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not used anywhere.

Copy link
Author

Choose a reason for hiding this comment

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

I have copied the entire Private namespace as used in JL 3 - hence the additional functions.


const oldModelPath = this._model.path;
let modelPath = oldModelPath;
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is @ts-ignore needed here?

@skbitsp
Copy link
Author

skbitsp commented Mar 19, 2024

@skbitsp thank you for working on this. A bit more work is needed to merge this:

  • JupyterLab 3 is nearing end of maintenance in two months time (JupyterLab 3 — May 15, 2024 end of maintenance jupyterlab/jupyterlab#15921, https://blog.jupyter.org/jupyterlab-3-end-of-maintenance-879778927db2) and since this extension currently supports JupyterLab 4 I don't think we can merge code which only works on 3.x.
  • while adding a CustomDirListing sounds all right, it should not use the private methods of DirListing; ideally the DirListing in core JupyterLab would be amended so that it either works out of the box without a need for subclassing (preferred), or so that only public/protected attributes/methods are accessed in the rename() override.
  • this PR includes a bunch of code which is not needed, and includes @ts-nocheck and @ts-ignore which goes against the quality requirements

This PR is only meant as a reference for users using this extension (hence created a draft PR). Since the code will change for all different versions of JL, the code will be different for JL 4. Users can customize on this based on the version they are using.

Though this is not the ideal way and the solution should come from the code JL side, this works fine as a quick workaround to unblock oursleves.

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

3 participants