Skip to content

Commit

Permalink
Check for and remove "RTC" drive prefix when returning selected file …
Browse files Browse the repository at this point in the history
…path added by the jupyter-collaboration (#541)

* Check for and remove "RTC:" prefix added by the jupyter-collaboration from the file path

* Require and pass app.serviceManager.contents to getSelectedFilePath, not whole app

* abstract path checking and manipulation into getLocalPath

* formatting
  • Loading branch information
andrii-i authored Aug 29, 2024
1 parent 1a775c2 commit bfb84b6
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,33 @@ function getSelectedFileBaseName(widget: FileBrowser | null): string | null {
return parts.join('.');
}

// Get the file name, with all parent directories, of the currently selected file.
function getSelectedFilePath(widget: FileBrowser | null): string | null {
/**
* Get the file name of the currently selected file with all parent directories, check
* for and remove "RTC" drive prefix potentially added by jupyter-collaboration.
*/
function getSelectedFilePath(
widget: FileBrowser | null,
contents: Contents.IManager
): string | null {
const selectedItem = getSelectedItem(widget);
if (selectedItem === null) {
return null;
}
return selectedItem.path;
return getLocalPath(selectedItem.path, contents);
}

/**
* Checks if path contains "RTC" drive prefix potentially added by jupyter-collaboration
* and returns a local path removing "RTC" prefix if needed
*/
export function getLocalPath(
path: string,
contents: Contents.IManager
): string {
if (contents.driveName(path) === 'RTC') {
return contents.localPath(path);
}
return path;
}

// Get the containing directory of the file at a particular path.
Expand Down Expand Up @@ -260,7 +280,8 @@ function activatePlugin(
execute: async () => {
eventLogger('file-browser.create-job');
const widget = fileBrowserTracker.currentWidget;
const filePath = getSelectedFilePath(widget) ?? '';
const filePath =
getSelectedFilePath(widget, app.serviceManager.contents) ?? '';

// Update the job form inside the notebook jobs widget
const newCreateModel = emptyCreateJobModel();
Expand Down

0 comments on commit bfb84b6

Please sign in to comment.