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

Support jupyter-collaboration by handling RTC prefix in the file paths #541

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading