Skip to content

Commit d328e17

Browse files
Fix open path error with timeline feature (jupyterlab#401)
* fixed open path error with timeline * test added for timeline * modified test * added test that fails without PR but passes with it * added ui test that passes with PR but fails without it.
1 parent 3126a81 commit d328e17

File tree

2 files changed

+83
-28
lines changed

2 files changed

+83
-28
lines changed

packages/docprovider-extension/src/filebrowser.ts

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,35 +158,37 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
158158
documentPath: string,
159159
documentId: string
160160
) => {
161-
if (drive) {
162-
// Remove 'RTC:' from document path
163-
documentPath = documentPath.slice(drive.name.length + 1);
164-
// Dispose of the previous timelineWidget if it exists
165-
if (timelineWidget) {
166-
timelineWidget.dispose();
167-
timelineWidget = null;
168-
}
161+
if (documentId && documentPath.split(':')[0] === 'RTC') {
162+
if (drive) {
163+
// Remove 'RTC:' from document path
164+
documentPath = documentPath.slice(drive.name.length + 1);
165+
// Dispose of the previous timelineWidget if it exists
166+
if (timelineWidget) {
167+
timelineWidget.dispose();
168+
timelineWidget = null;
169+
}
169170

170-
const [format, type] = documentId.split(':');
171-
const provider = drive.providers.get(
172-
`${format}:${type}:${documentPath}`
173-
) as unknown as IForkProvider;
174-
const fullPath = URLExt.join(
175-
app.serviceManager.serverSettings.baseUrl,
176-
DOCUMENT_TIMELINE_URL,
177-
documentPath
178-
);
171+
const [format, type] = documentId.split(':');
172+
const provider = drive.providers.get(
173+
`${format}:${type}:${documentPath}`
174+
) as unknown as IForkProvider;
175+
const fullPath = URLExt.join(
176+
app.serviceManager.serverSettings.baseUrl,
177+
DOCUMENT_TIMELINE_URL,
178+
documentPath
179+
);
179180

180-
timelineWidget = new TimelineWidget(
181-
fullPath,
182-
provider,
183-
provider.contentType,
184-
provider.format
185-
);
181+
timelineWidget = new TimelineWidget(
182+
fullPath,
183+
provider,
184+
provider.contentType,
185+
provider.format
186+
);
186187

187-
const elt = document.getElementById('jp-slider-status-bar');
188-
if (elt && !timelineWidget.isAttached) {
189-
Widget.attach(timelineWidget, elt);
188+
const elt = document.getElementById('jp-slider-status-bar');
189+
if (elt && !timelineWidget.isAttached) {
190+
Widget.attach(timelineWidget, elt);
191+
}
190192
}
191193
}
192194
};
@@ -222,8 +224,22 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
222224
align: 'left',
223225
rank: 4,
224226
isActive: () => {
225-
const currentWidget = app.shell.currentWidget;
226-
return !!currentWidget && 'context' in currentWidget;
227+
const currentWidget = app.shell
228+
.currentWidget as DocumentWidget | null;
229+
230+
if (
231+
currentWidget &&
232+
currentWidget.context &&
233+
typeof currentWidget.context.path === 'string'
234+
) {
235+
const documentPath = currentWidget.context.path;
236+
const documentId =
237+
currentWidget.context.model.sharedModel.getState(
238+
'document_id'
239+
) as string;
240+
return !!documentId && documentPath.split(':')[0] === 'RTC';
241+
}
242+
return false;
227243
}
228244
});
229245
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Jupyter Development Team.
3+
* Distributed under the terms of the Modified BSD License.
4+
*/
5+
6+
import { expect, test } from '@jupyterlab/galata';
7+
import { Page } from '@playwright/test';
8+
9+
async function capturePageErrors(page: Page) {
10+
const pageErrors: string[] = [];
11+
page.on('pageerror', (error) => pageErrors.push(error.message));
12+
return pageErrors;
13+
}
14+
15+
async function openNotebook(page: Page, notebookPath: string) {
16+
await page.click('text=File');
17+
await page.click('.lm-Menu-itemLabel:text("Open from Path…")');
18+
await page.fill(
19+
'input[placeholder="/path/relative/to/jlab/root"]',
20+
notebookPath
21+
);
22+
await page.click('.jp-Dialog-buttonLabel:text("Open")');
23+
await page.waitForSelector('.jp-Notebook', { state: 'visible' });
24+
}
25+
26+
test.describe('Open from Path', () => {
27+
28+
test('should fail if there are console errors', async ({ page, tmpPath }) => {
29+
const pageErrors = await capturePageErrors(page);
30+
31+
await page.notebook.createNew();
32+
await page.notebook.save();
33+
await page.notebook.close();
34+
35+
await openNotebook(page, `${tmpPath}/Untitled.ipynb`);
36+
37+
expect(pageErrors).toHaveLength(0);
38+
});
39+
});

0 commit comments

Comments
 (0)