Skip to content

Commit

Permalink
Restore workspace and open _tree_ path (jupyterlab#11168) (jupyterlab…
Browse files Browse the repository at this point in the history
…#11176)

* workspace is restored instead of loading requested document via `/tree/notebook.ipynb`
Fixes jupyterlab#10876

* Add test for workspaces

Co-authored-by: Frédéric Collonval <fcollonval@gmail.com>
  • Loading branch information
Steven Silvester and fcollonval committed Sep 28, 2021
1 parent dfd3ad6 commit c4d1f7b
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions packages/application-extension/src/index.tsx
Expand Up @@ -368,14 +368,20 @@ const mainCommands: JupyterFrontEndPlugin<void> = {
*/
const main: JupyterFrontEndPlugin<ITreePathUpdater> = {
id: '@jupyterlab/application-extension:main',
requires: [IRouter, IWindowResolver, ITranslator],
requires: [
IRouter,
IWindowResolver,
ITranslator,
JupyterFrontEnd.ITreeResolver
],
optional: [IConnectionLost],
provides: ITreePathUpdater,
activate: (
app: JupyterFrontEnd,
router: IRouter,
resolver: IWindowResolver,
translator: ITranslator,
treeResolver: JupyterFrontEnd.ITreeResolver,
connectionLost: IConnectionLost | null
) => {
const trans = translator.load('jupyterlab');
Expand All @@ -391,13 +397,17 @@ const main: JupyterFrontEndPlugin<ITreePathUpdater> = {
let _defaultBrowserTreePath = '';

function updateTreePath(treePath: string) {
_defaultBrowserTreePath = treePath;
if (!_docTreePath) {
const path = PageConfig.getUrl({ treePath });
router.navigate(path, { skipRouting: true });
// Persist the new tree path to PageConfig as it is used elsewhere at runtime.
PageConfig.setOption('treePath', treePath);
}
// Wait for tree resolver to finish before updating the path because it use the PageConfig['treePath']
treeResolver.paths.then(() => {
_defaultBrowserTreePath = treePath;
if (!_docTreePath) {
const url = PageConfig.getUrl({ treePath });
const path = URLExt.parse(url).pathname;
router.navigate(path, { skipRouting: true });
// Persist the new tree path to PageConfig as it is used elsewhere at runtime.
PageConfig.setOption('treePath', treePath);
}
});
}

// Requiring the window resolver guarantees that the application extension
Expand Down Expand Up @@ -433,16 +443,20 @@ const main: JupyterFrontEndPlugin<ITreePathUpdater> = {
PageConfig.setOption('mode', args as string);
});

// Watch the path of the current widget in the main area and update the page
// URL to reflect the change.
app.shell.currentPathChanged.connect((_, args) => {
const maybeTreePath = args.newValue as string;
const treePath = maybeTreePath || _defaultBrowserTreePath;
const path = PageConfig.getUrl({ treePath: treePath });
router.navigate(path, { skipRouting: true });
// Persist the new tree path to PageConfig as it is used elsewhere at runtime.
PageConfig.setOption('treePath', treePath);
_docTreePath = maybeTreePath;
// Wait for tree resolver to finish before updating the path because it use the PageConfig['treePath']
treeResolver.paths.then(() => {
// Watch the path of the current widget in the main area and update the page
// URL to reflect the change.
app.shell.currentPathChanged.connect((_, args) => {
const maybeTreePath = args.newValue as string;
const treePath = maybeTreePath || _defaultBrowserTreePath;
const url = PageConfig.getUrl({ treePath: treePath });
const path = URLExt.parse(url).pathname;
router.navigate(path, { skipRouting: true });
// Persist the new tree path to PageConfig as it is used elsewhere at runtime.
PageConfig.setOption('treePath', treePath);
_docTreePath = maybeTreePath;
});
});

// If the connection to the server is lost, handle it with the
Expand Down

0 comments on commit c4d1f7b

Please sign in to comment.