Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree view enhancement #6588

Merged
merged 16 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/_metapackage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "path": "../lab-extension" },
{ "path": "../notebook-extension" },
{ "path": "../terminal-extension" },
{ "path": "../tree" },
{ "path": "../tree-extension" },
{ "path": "../ui-components" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/application-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"@jupyter-notebook/application": "^7.0.0-alpha.10",
"@jupyter-notebook/tree": "^7.0.0-alpha.10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this dependency still needed after the last commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

"@jupyter-notebook/ui-components": "^7.0.0-alpha.10",
"@jupyterlab/application": "^4.0.0-alpha.17",
"@jupyterlab/apputils": "^4.0.0-alpha.17",
Expand Down
21 changes: 16 additions & 5 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
SidePanelPalette
} from '@jupyter-notebook/application';

import { CommandIDs as filebrowserCommandIDs } from '@jupyter-notebook/tree';

import { jupyterIcon } from '@jupyter-notebook/ui-components';

import { PromiseDelegate } from '@lumino/coreutils';
Expand Down Expand Up @@ -242,6 +244,11 @@ const menuSpacer: JupyterFrontEndPlugin<void> = {

/**
* Add commands to open the tree and running pages.
*
* ## NOTES:
* The optional token IFileBrowserCommands is useful to ensure the corresponding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this comment can probably be removed now.

* plugin has been activated. Otherwise this plugin can be activated before the commands
* 'toggle-main' has been added, which create a duplicated entry.
*/
const pages: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:pages',
Expand All @@ -262,18 +269,22 @@ const pages: JupyterFrontEndPlugin<void> = {
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(filebrowserCommandIDs.activate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid bringing a dependency on @jupyter-notebook/tree for @jupyter-notebook/application-extension, maybe we should just use the filebrowser:activate string here directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example this is what is done in the JupyterLab docmanager-extension, using a command defined in another plugin: https://github.com/jupyterlab/jupyterlab/blob/d614e293eb4b90055307828d5e81c9661e1147c9/packages/docmanager-extension/src/index.tsx#L1125

Copy link
Contributor Author

@brichet brichet Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, perhaps we should do the same in tree-extension:openFileBrowser and drop the CommandIDs namespace in tree.

EDIT: just saw the comment below.

} 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' });
}
}
};
Expand Down
34 changes: 32 additions & 2 deletions packages/tree-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import {

import { Menu, MenuBar } from '@lumino/widgets';

import { NotebookTreeWidget, INotebookTree } from '@jupyter-notebook/tree';
import {
CommandIDs,
NotebookTreeWidget,
INotebookTree
} from '@jupyter-notebook/tree';

/**
* The file browser factory.
Expand Down Expand Up @@ -94,6 +98,28 @@ const createNew: JupyterFrontEndPlugin<void> = {
}
};

/**
* A plugin to add file browser commands for the tree view.
*/
const openFileBrowser: JupyterFrontEndPlugin<void> = {
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
*/
Expand Down Expand Up @@ -183,5 +209,9 @@ const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [createNew, notebookTreeWidget];
const plugins: JupyterFrontEndPlugin<any>[] = [
createNew,
openFileBrowser,
notebookTreeWidget
];
export default plugins;
8 changes: 8 additions & 0 deletions packages/tree/src/notebook-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { TabPanel } from '@lumino/widgets';

import { INotebookTree } from './token';

/**
* The namespace for command IDs.
*/
export namespace CommandIDs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With https://github.com/jupyter/notebook/pull/6588/files#r1067176298 above, these CommandIDs could be moved to the tree-extension package.

// The command to activate the filebrowser widget in tree view.
export const activate = 'filebrowser:activate';
}

/**
* The widget added in main area of the tree view.
*/
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions ui-tests/test/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});