Skip to content

Commit

Permalink
Improve kernels pane in running sidebar (jupyterlab#13851)
Browse files Browse the repository at this point in the history
* Allow "notebook:create-new" to accept optional kernelId parameter to open a notebook with a given kernel

* Allow an optional CSS class name and context menu hint in a data attribute for running items to support using a context menu

* Add context menu support for running kernels

* Add list of child sessions connected to a kernel

* Clarify comments

* Update Playwright Snapshots

* Use CommandIDs

* Make kernels in running sidebar collapsible

* Approximate stopPropagation since toolbar buttons do not expose native events

* Add support for kernel icons

* Update Playwright Snapshots

* Make open() function for running items optional

* Update packages/running/src/index.tsx

Co-authored-by: Frédéric Collonval <[email protected]>

* Address review comments

* Clearer variable name: `stopPropagation` instead of `shutdownRequested`

* Update documentation snapshot expected text

* Update Playwright Snapshots

* Use customizable context menu

* Fix DOM structure

* Better UI test selectors

* Update snapshots

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
  • Loading branch information
4 people authored Jan 31, 2023
1 parent 733e2a2 commit e3d4621
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,30 @@
"caption": "Run All",
"shortcuts": []
},
{
"id": "running:kernel-new-console",
"label": "New Console for Kernel",
"caption": "",
"shortcuts": []
},
{
"id": "running:kernel-new-notebook",
"label": "New Notebook for Kernel",
"caption": "",
"shortcuts": []
},
{
"id": "running:kernel-open-session",
"label": "Unknown Session",
"caption": "",
"shortcuts": []
},
{
"id": "running:kernel-shut-down",
"label": "Shut Down Kernel",
"caption": "",
"shortcuts": []
},
{
"id": "running:show-panel",
"label": "Sessions and Tabs",
Expand Down
14 changes: 10 additions & 4 deletions galata/test/documentation/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ test.describe('General', () => {

await page.click('[title="Running Terminals and Kernels"]');

await page.locator('text="Python 3 (ipykernel) {1}"').waitFor();
await page
.locator(
'.jp-RunningSessions-item.jp-mod-kernel >> text="Python 3 (ipykernel)"'
)
.waitFor();
expect(
await page.screenshot({ clip: { y: 27, x: 0, width: 283, height: 400 } })
).toMatchSnapshot('interface_tabs.png');
Expand Down Expand Up @@ -462,9 +466,11 @@ test.describe('General', () => {

await page.click('[title="Running Terminals and Kernels"]');

await expect(page.locator('text="Python 3 (ipykernel) {1}"')).toHaveCount(
2
);
await expect(
page.locator(
'.jp-RunningSessions-item.jp-mod-kernel >> text="Python 3 (ipykernel)"'
)
).toHaveCount(2);

expect(
await page.screenshot({ clip: { y: 27, x: 0, width: 283, height: 400 } })
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.
13 changes: 9 additions & 4 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1642,16 +1642,20 @@ function activateNotebookHandler(
}

// Utility function to create a new notebook.
const createNew = async (cwd: string, kernelName?: string) => {
const createNew = async (
cwd: string,
kernelId: string,
kernelName: string
) => {
const model = await commands.execute('docmanager:new-untitled', {
path: cwd,
type: 'notebook'
});
if (model != undefined) {
if (model !== undefined) {
const widget = (await commands.execute('docmanager:open', {
path: model.path,
factory: FACTORY,
kernel: { name: kernelName }
kernel: { id: kernelId, name: kernelName }
})) as unknown as IDocumentWidget;
widget.isUntitled = true;
return widget;
Expand All @@ -1677,8 +1681,9 @@ function activateNotebookHandler(
icon: args => (args['isPalette'] ? undefined : notebookIcon),
execute: args => {
const cwd = (args['cwd'] as string) || (defaultBrowser?.model.path ?? '');
const kernelId = (args['kernelId'] as string) || '';
const kernelName = (args['kernelName'] as string) || '';
return createNew(cwd, kernelName);
return createNew(cwd, kernelId, kernelName);
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/running-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@jupyterlab/application": "^4.0.0-alpha.18",
"@jupyterlab/coreutils": "^6.0.0-alpha.18",
"@jupyterlab/docregistry": "^4.0.0-alpha.18",
"@jupyterlab/rendermime-interfaces": "^3.8.0-alpha.18",
"@jupyterlab/running": "^4.0.0-alpha.18",
Expand Down
37 changes: 37 additions & 0 deletions packages/running-extension/schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@
}
]
}
],
"context": [
{
"command": "running:kernel-new-console",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 0
},
{
"command": "running:kernel-new-notebook",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 1
},
{
"type": "separator",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 2
},
{
"type": "submenu",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 3,
"submenu": {
"id": "jp-contextmenu-connected-sessions",
"label": "Connected Sessions…",
"items": []
}
},
{
"type": "separator",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 4
},
{
"command": "running:kernel-shut-down",
"selector": ".jp-RunningSessions-item.jp-mod-kernel",
"rank": 5
}
]
},
"jupyter.lab.shortcuts": [
Expand Down
6 changes: 5 additions & 1 deletion packages/running-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import { addOpenTabsSessionManager } from './opentabs';
/**
* The command IDs used by the running plugin.
*/
namespace CommandIDs {
export namespace CommandIDs {
export const kernelNewConsole = 'running:kernel-new-console';
export const kernelNewNotebook = 'running:kernel-new-notebook';
export const kernelOpenSession = 'running:kernel-open-session';
export const kernelShutDown = 'running:kernel-shut-down';
export const showPanel = 'running:show-panel';
}

Expand Down
Loading

0 comments on commit e3d4621

Please sign in to comment.