diff --git a/packages/_metapackage/tsconfig.json b/packages/_metapackage/tsconfig.json index fa8c866b05..c8938dcdaa 100644 --- a/packages/_metapackage/tsconfig.json +++ b/packages/_metapackage/tsconfig.json @@ -15,6 +15,7 @@ { "path": "../lab-extension" }, { "path": "../notebook-extension" }, { "path": "../terminal-extension" }, + { "path": "../tree" }, { "path": "../tree-extension" }, { "path": "../ui-components" } ] diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 65e4021bd7..470d1fa1a6 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -262,18 +262,22 @@ const pages: JupyterFrontEndPlugin = { window.open(`${baseUrl}lab`); } }); + const page = PageConfig.getOption('notebookPage'); app.commands.addCommand(CommandIDs.openTree, { - label: trans.__('Open Files'), + label: trans.__('File Browser'), execute: () => { - window.open(`${baseUrl}tree`); + if (page === 'tree') { + app.commands.execute('filebrowser:activate'); + } else { + window.open(`${baseUrl}tree`); + } } }); if (palette) { - [CommandIDs.openLab, CommandIDs.openTree].forEach(command => { - palette.addItem({ command, category: 'View' }); - }); + palette.addItem({ command: CommandIDs.openLab, category: 'View' }); + palette.addItem({ command: CommandIDs.openTree, category: 'View' }); } } }; diff --git a/packages/tree-extension/src/index.ts b/packages/tree-extension/src/index.ts index 3c3aafd5ff..6d1217cccd 100644 --- a/packages/tree-extension/src/index.ts +++ b/packages/tree-extension/src/index.ts @@ -44,6 +44,14 @@ const FILE_BROWSER_FACTORY = 'FileBrowser'; */ const FILE_BROWSER_PLUGIN_ID = '@jupyterlab/filebrowser-extension:browser'; +/** + * The namespace for command IDs. + */ +namespace CommandIDs { + // The command to activate the filebrowser widget in tree view. + export const activate = 'filebrowser:activate'; +} + /** * Plugin to add extra commands to the file browser to create * new notebooks, files, consoles and terminals @@ -94,6 +102,28 @@ const createNew: JupyterFrontEndPlugin = { } }; +/** + * A plugin to add file browser commands for the tree view. + */ +const openFileBrowser: JupyterFrontEndPlugin = { + id: '@jupyter-notebook/tree-extension:open-file-browser', + requires: [INotebookTree, IFileBrowserFactory], + autoStart: true, + activate: ( + app: JupyterFrontEnd, + notebookTree: INotebookTree, + factory: IFileBrowserFactory + ) => { + const { commands } = app; + commands.addCommand(CommandIDs.activate, { + execute: () => { + const { defaultBrowser: browser } = factory; + notebookTree.currentWidget = browser; + } + }); + } +}; + /** * A plugin to add the file browser widget to an INotebookShell */ @@ -183,5 +213,9 @@ const notebookTreeWidget: JupyterFrontEndPlugin = { /** * Export the plugins as default. */ -const plugins: JupyterFrontEndPlugin[] = [createNew, notebookTreeWidget]; +const plugins: JupyterFrontEndPlugin[] = [ + createNew, + openFileBrowser, + notebookTreeWidget +]; export default plugins; diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png index 4d6d3b2e2d..6d4c5e5a3a 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png differ diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png index 38fe11a4fd..04b5de58b7 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png differ diff --git a/ui-tests/test/tree.spec.ts b/ui-tests/test/tree.spec.ts index beef661f4e..f96c98eb3c 100644 --- a/ui-tests/test/tree.spec.ts +++ b/ui-tests/test/tree.spec.ts @@ -36,3 +36,12 @@ test('should update url when navigating in filebrowser', async ({ const url = new URL(page.url()); expect(url.pathname).toEqual(`/tree/${tmpPath}/${SUBFOLDER}`); }); + +test('Should activate file browser tab', async ({ page, tmpPath }) => { + await page.goto(`tree/${tmpPath}`); + await page.click('text="Running"'); + await expect(page.locator('#main-panel #jp-running-sessions')).toBeVisible(); + + await page.menu.clickMenuItem('View>File Browser'); + await expect(page.locator('#main-panel #filebrowser')).toBeVisible(); +});