Skip to content

Commit bfb84b6

Browse files
authored
Check for and remove "RTC" drive prefix when returning selected file 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
1 parent 1a775c2 commit bfb84b6

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/index.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,33 @@ function getSelectedFileBaseName(widget: FileBrowser | null): string | null {
142142
return parts.join('.');
143143
}
144144

145-
// Get the file name, with all parent directories, of the currently selected file.
146-
function getSelectedFilePath(widget: FileBrowser | null): string | null {
145+
/**
146+
* Get the file name of the currently selected file with all parent directories, check
147+
* for and remove "RTC" drive prefix potentially added by jupyter-collaboration.
148+
*/
149+
function getSelectedFilePath(
150+
widget: FileBrowser | null,
151+
contents: Contents.IManager
152+
): string | null {
147153
const selectedItem = getSelectedItem(widget);
148154
if (selectedItem === null) {
149155
return null;
150156
}
151-
return selectedItem.path;
157+
return getLocalPath(selectedItem.path, contents);
158+
}
159+
160+
/**
161+
* Checks if path contains "RTC" drive prefix potentially added by jupyter-collaboration
162+
* and returns a local path removing "RTC" prefix if needed
163+
*/
164+
export function getLocalPath(
165+
path: string,
166+
contents: Contents.IManager
167+
): string {
168+
if (contents.driveName(path) === 'RTC') {
169+
return contents.localPath(path);
170+
}
171+
return path;
152172
}
153173

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

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

0 commit comments

Comments
 (0)