Skip to content

Commit

Permalink
Fix open path error with timeline feature (#401)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Meriem-BenIsmail authored Nov 20, 2024
1 parent 3126a81 commit d328e17
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 28 deletions.
72 changes: 44 additions & 28 deletions packages/docprovider-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,35 +158,37 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
documentPath: string,
documentId: string
) => {
if (drive) {
// Remove 'RTC:' from document path
documentPath = documentPath.slice(drive.name.length + 1);
// Dispose of the previous timelineWidget if it exists
if (timelineWidget) {
timelineWidget.dispose();
timelineWidget = null;
}
if (documentId && documentPath.split(':')[0] === 'RTC') {
if (drive) {
// Remove 'RTC:' from document path
documentPath = documentPath.slice(drive.name.length + 1);
// Dispose of the previous timelineWidget if it exists
if (timelineWidget) {
timelineWidget.dispose();
timelineWidget = null;
}

const [format, type] = documentId.split(':');
const provider = drive.providers.get(
`${format}:${type}:${documentPath}`
) as unknown as IForkProvider;
const fullPath = URLExt.join(
app.serviceManager.serverSettings.baseUrl,
DOCUMENT_TIMELINE_URL,
documentPath
);
const [format, type] = documentId.split(':');
const provider = drive.providers.get(
`${format}:${type}:${documentPath}`
) as unknown as IForkProvider;
const fullPath = URLExt.join(
app.serviceManager.serverSettings.baseUrl,
DOCUMENT_TIMELINE_URL,
documentPath
);

timelineWidget = new TimelineWidget(
fullPath,
provider,
provider.contentType,
provider.format
);
timelineWidget = new TimelineWidget(
fullPath,
provider,
provider.contentType,
provider.format
);

const elt = document.getElementById('jp-slider-status-bar');
if (elt && !timelineWidget.isAttached) {
Widget.attach(timelineWidget, elt);
const elt = document.getElementById('jp-slider-status-bar');
if (elt && !timelineWidget.isAttached) {
Widget.attach(timelineWidget, elt);
}
}
}
};
Expand Down Expand Up @@ -222,8 +224,22 @@ export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
align: 'left',
rank: 4,
isActive: () => {
const currentWidget = app.shell.currentWidget;
return !!currentWidget && 'context' in currentWidget;
const currentWidget = app.shell
.currentWidget as DocumentWidget | null;

if (
currentWidget &&
currentWidget.context &&
typeof currentWidget.context.path === 'string'
) {
const documentPath = currentWidget.context.path;
const documentId =
currentWidget.context.model.sharedModel.getState(
'document_id'
) as string;
return !!documentId && documentPath.split(':')[0] === 'RTC';
}
return false;
}
});
}
Expand Down
39 changes: 39 additions & 0 deletions ui-tests/tests/timeline-slider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

import { expect, test } from '@jupyterlab/galata';
import { Page } from '@playwright/test';

async function capturePageErrors(page: Page) {
const pageErrors: string[] = [];
page.on('pageerror', (error) => pageErrors.push(error.message));
return pageErrors;
}

async function openNotebook(page: Page, notebookPath: string) {
await page.click('text=File');
await page.click('.lm-Menu-itemLabel:text("Open from Path…")');
await page.fill(
'input[placeholder="/path/relative/to/jlab/root"]',
notebookPath
);
await page.click('.jp-Dialog-buttonLabel:text("Open")');
await page.waitForSelector('.jp-Notebook', { state: 'visible' });
}

test.describe('Open from Path', () => {

test('should fail if there are console errors', async ({ page, tmpPath }) => {
const pageErrors = await capturePageErrors(page);

await page.notebook.createNew();
await page.notebook.save();
await page.notebook.close();

await openNotebook(page, `${tmpPath}/Untitled.ipynb`);

expect(pageErrors).toHaveLength(0);
});
});

0 comments on commit d328e17

Please sign in to comment.