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

Left right panel in Notebook view #6487

Merged
merged 57 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
73a64bb
Incorporates files from retrolab PR 275 and fix rebase changes
JasonWeill Mar 23, 2022
b29a925
Add the table of content dependency
brichet Jul 21, 2022
a794e12
Fix the ToC on Notebook (and remove remaining comments from rebase)
brichet Aug 2, 2022
4e9d0ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2022
60dc750
Update screenshot of View menu which have a new entry
brichet Aug 3, 2022
86283fe
Add a test on Table of Contents
brichet Aug 3, 2022
72756df
Fix menu entries in tree and editor views
brichet Aug 3, 2022
ab7b0ad
Update the menu entries when widgets are added or removed from side p…
brichet Aug 4, 2022
e2ed555
Fix tha activateById on side panels widgets
brichet Aug 4, 2022
b02eb05
Fix some test snapshots and css
brichet Aug 4, 2022
45deda1
Add NotebookTools widget in right panel
brichet Aug 4, 2022
d47f8c4
Loads side panel widgets only on notebook page
brichet Aug 5, 2022
6fec146
update snapshots and selector in ui-tests
brichet Aug 5, 2022
e2592c3
Some refactoring and cleaning
brichet Aug 8, 2022
3d665c9
Add command palette entries to open side bar panels
brichet Aug 8, 2022
5d01394
Side panels take the full page height
jtpio Aug 17, 2022
418e294
Remove unused import
jtpio Aug 17, 2022
2145e66
Remove tests for sidePanelsVisible
jtpio Aug 17, 2022
116f5a5
Move some logic and dependencies from Shell to plugin
brichet Aug 18, 2022
9681be3
Move the palette logic from Shell to plugin
brichet Aug 23, 2022
11d3588
Include the notebook tools widget from the notebook-extension
brichet Aug 23, 2022
2055ccf
Add icon to close side panel
brichet Aug 26, 2022
1773c8f
Hide the current widget when collapsing, otherwise this is only the u…
brichet Aug 26, 2022
0696850
Fix the sidebar closing if another widget is selected in the same sid…
brichet Aug 26, 2022
bc67cdc
Add 'isToggled' check mark on right panel
brichet Aug 26, 2022
aceb187
Fix tests on left and right area in tree view
brichet Sep 1, 2022
0580147
Use signal to update menu and palette entries when widgets are remove…
brichet Sep 1, 2022
d210064
Add some docstring
brichet Sep 2, 2022
7f33dbe
Fix tests on panels and add snapshots
brichet Sep 7, 2022
239e5b9
Updates after rebasing v7.0.0a6
invalid-email-address Oct 4, 2022
7f32693
Apply the min-width to the side panels themselves instead of to the c…
invalid-email-address Oct 4, 2022
4463ed8
Specify the 'Shut Down All' button to click in smoke tour test (the o…
invalid-email-address Oct 4, 2022
22089cd
update snapshot
invalid-email-address Oct 4, 2022
73aafed
Minor cleanups
jtpio Oct 4, 2022
fc663a5
Enable side bars on other pages
jtpio Oct 4, 2022
9af6a20
Simplify menu entry label
jtpio Oct 4, 2022
7375ee1
Remove unused handling of layout modified
jtpio Oct 5, 2022
07720ad
More cleanups
jtpio Oct 5, 2022
ea36920
Dissociate menu and palette updates
jtpio Oct 5, 2022
b396e51
Revert to making INotebookTools optional
jtpio Oct 5, 2022
d5e9cec
Add the debugger extension
jtpio Oct 5, 2022
ffadcbc
Update some reference snapshots
jtpio Oct 5, 2022
d9635e3
Try fixing the test opening JupyterLab
jtpio Oct 5, 2022
1ed8e02
Update viewport width for mobile tests
jtpio Oct 5, 2022
e62a06f
Remove TODO
jtpio Oct 5, 2022
7d5691e
Try fixing UI test race conditions
jtpio Oct 5, 2022
55cd158
Update more reference snapshots
jtpio Oct 5, 2022
3f8c558
Update toc snapshot for Firefox
jtpio Oct 5, 2022
02a164d
Remove shutdownAll in the menu tests
jtpio Oct 5, 2022
f6b65e3
Tweak menu tests
jtpio Oct 6, 2022
d583453
Try dispatching a resize message manually
jtpio Oct 6, 2022
12119f9
Fix what looks like a rebase issue
jtpio Oct 6, 2022
b893cf0
Wait for kernel ready before menu screenshots
jtpio Oct 6, 2022
708928b
Try resize workaround in tests for now
jtpio Oct 6, 2022
b4f520c
Drop unused async
jtpio Oct 6, 2022
820ee98
Update kernel menu snapshot for firefox
jtpio Oct 6, 2022
94eadd8
Remove `isEmpty` from the shell API (only used for tests)
jtpio Oct 6, 2022
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
22 changes: 21 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function main() {
require('@jupyterlab/apputils-extension').default.filter(({ id }) =>
[
'@jupyterlab/apputils-extension:palette',
'@jupyter/apputils-extension:sanitizer',
'@jupyterlab/apputils-extension:settings',
'@jupyterlab/apputils-extension:state',
'@jupyterlab/apputils-extension:themes',
Expand Down Expand Up @@ -175,11 +176,30 @@ async function main() {
}
case 'notebooks': {
baseMods = baseMods.concat([
require('@jupyterlab/celltags-extension'),
require('@jupyterlab/cell-toolbar-extension'),
require('@jupyterlab/debugger-extension').default.filter(({ id }) =>
[
'@jupyterlab/debugger-extension:config',
'@jupyterlab/debugger-extension:main',
'@jupyterlab/debugger-extension:notebooks',
'@jupyterlab/debugger-extension:service',
'@jupyterlab/debugger-extension:sidebar',
'@jupyterlab/debugger-extension:sources'
].includes(id)
),
require('@jupyterlab/notebook-extension').default.filter(({ id }) =>
[
'@jupyterlab/notebook-extension:completer',
'@jupyterlab/notebook-extension:search'
'@jupyterlab/notebook-extension:search',
'@jupyterlab/notebook-extension:toc',
'@jupyterlab/notebook-extension:tools'
].includes(id)
),
require('@jupyterlab/toc-extension').default.filter(({ id }) =>
[
'@jupyterlab/toc-extension:registry',
'@jupyterlab/toc-extension:tracker'
].includes(id)
),
require('@jupyterlab/tooltip-extension').default.filter(({ id }) =>
Expand Down
7 changes: 7 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@jupyterlab/cell-toolbar": "~4.0.0-alpha.14",
"@jupyterlab/cell-toolbar-extension": "~4.0.0-alpha.14",
"@jupyterlab/celltags": "~4.0.0-alpha.14",
"@jupyterlab/celltags-extension": "~4.0.0-alpha.14",
"@jupyterlab/codeeditor": "~4.0.0-alpha.14",
"@jupyterlab/codemirror-extension": "~4.0.0-alpha.14",
"@jupyterlab/collaboration": "~4.0.0-alpha.14",
Expand Down Expand Up @@ -76,6 +77,7 @@
"@jupyterlab/terminal-extension": "~4.0.0-alpha.14",
"@jupyterlab/theme-dark-extension": "~4.0.0-alpha.14",
"@jupyterlab/theme-light-extension": "~4.0.0-alpha.14",
"@jupyterlab/toc-extension": "~6.0.0-alpha.14",
"@jupyterlab/tooltip": "~4.0.0-alpha.14",
"@jupyterlab/tooltip-extension": "~4.0.0-alpha.14",
"@jupyterlab/translation": "~4.0.0-alpha.14",
Expand Down Expand Up @@ -114,11 +116,13 @@
"@jupyterlab/apputils-extension": "^4.0.0-alpha.14",
"@jupyterlab/cell-toolbar-extension": "^4.0.0-alpha.14",
"@jupyterlab/celltags": "^4.0.0-alpha.14",
"@jupyterlab/celltags-extension": "^4.0.0-alpha.14",
"@jupyterlab/codemirror-extension": "^4.0.0-alpha.14",
"@jupyterlab/collaboration-extension": "^4.0.0-alpha.14",
"@jupyterlab/completer-extension": "^4.0.0-alpha.14",
"@jupyterlab/console-extension": "^4.0.0-alpha.14",
"@jupyterlab/coreutils": "^6.0.0-alpha.14",
"@jupyterlab/debugger-extension": "^4.0.0-alpha.14",
"@jupyterlab/docmanager-extension": "^4.0.0-alpha.14",
"@jupyterlab/docprovider-extension": "^4.0.0-alpha.14",
"@jupyterlab/documentsearch-extension": "^4.0.0-alpha.14",
Expand All @@ -140,6 +144,7 @@
"@jupyterlab/terminal-extension": "^4.0.0-alpha.14",
"@jupyterlab/theme-dark-extension": "^4.0.0-alpha.14",
"@jupyterlab/theme-light-extension": "^4.0.0-alpha.14",
"@jupyterlab/toc-extension": "^6.0.0-alpha.14",
"@jupyterlab/tooltip-extension": "^4.0.0-alpha.14",
"@jupyterlab/translation-extension": "^4.0.0-alpha.14",
"@jupyterlab/vega5-extension": "^4.0.0-alpha.14"
Expand Down Expand Up @@ -181,6 +186,7 @@
"@jupyterlab/codemirror-extension",
"@jupyterlab/completer-extension",
"@jupyterlab/console-extension",
"@jupyterlab/debugger-extension",
"@jupyterlab/docmanager-extension",
"@jupyterlab/documentsearch-extension",
"@jupyterlab/filebrowser-extension",
Expand Down Expand Up @@ -211,6 +217,7 @@
"@jupyterlab/completer",
"@jupyterlab/console",
"@jupyterlab/coreutils",
"@jupyterlab/debugger",
"@jupyterlab/docmanager",
"@jupyterlab/docprovider",
"@jupyterlab/documentsearch",
Expand Down
237 changes: 231 additions & 6 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,24 @@ import { ITranslator } from '@jupyterlab/translation';
import {
NotebookApp,
NotebookShell,
INotebookShell
INotebookShell,
SideBarPanel,
SideBarHandler
} from '@jupyter-notebook/application';

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

import { PromiseDelegate } from '@lumino/coreutils';

import { DisposableDelegate, DisposableSet } from '@lumino/disposable';
import {
DisposableDelegate,
DisposableSet,
IDisposable
} from '@lumino/disposable';

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

import { Widget } from '@lumino/widgets';
import { SideBarPalette } from './sidebarpalette';

/**
* A regular expression to match path to notebooks and documents
Expand All @@ -65,6 +73,11 @@ namespace CommandIDs {
*/
export const toggleTop = 'application:toggle-top';

/**
* Toggle sidebar visibility
*/
export const togglePanel = 'application:toggle-panel';

/**
* Toggle the Zen mode
*/
Expand Down Expand Up @@ -173,7 +186,7 @@ const opener: JupyterFrontEndPlugin<void> = {
const file = decodeURIComponent(path);
const urlParams = new URLSearchParams(parsed.search);
const factory = urlParams.get('factory') ?? 'default';
app.restored.then(async () => {
app.started.then(async () => {
docManager.open(file, factory, undefined, {
ref: '_noref'
});
Expand All @@ -187,8 +200,6 @@ const opener: JupyterFrontEndPlugin<void> = {

/**
* A plugin to customize menus
*
* TODO: use this plugin to customize the menu items and their order
*/
const menus: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:menus',
Expand Down Expand Up @@ -557,6 +568,219 @@ const topVisibility: JupyterFrontEndPlugin<void> = {
autoStart: true
};

/**
* Plugin to toggle the left or right sidebar's visibility.
*/
const sidebarVisibility: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:sidebar',
requires: [INotebookShell, ITranslator],
optional: [IMainMenu, ICommandPalette],
autoStart: true,
activate: (
app: JupyterFrontEnd<JupyterFrontEnd.IShell>,
notebookShell: INotebookShell,
translator: ITranslator,
menu: IMainMenu | null,
palette: ICommandPalette | null
) => {
const trans = translator.load('notebook');

/* Arguments for togglePanel command:
* side, left or right area
* title, widget title to show in the menu
* id, widget ID to activate in the sidebar
*/
app.commands.addCommand(CommandIDs.togglePanel, {
label: args => args['title'] as string,
caption: args => {
// We do not substitute the parameter into the string because the parameter is not
// localized (e.g., it is always 'left') even though the string is localized.
if (args['side'] === 'left') {
return trans.__(
'Show %1 in the left sidebar',
args['title'] as string
);
} else if (args['side'] === 'right') {
return trans.__(
'Show %1 in the right sidebar',
args['title'] as string
);
}
return trans.__('Show %1 in the sidebar', args['title'] as string);
},
execute: args => {
switch (args['side'] as string) {
case 'left':
if (notebookShell.leftCollapsed) {
notebookShell.expandLeft(args.id as string);
} else if (
notebookShell.leftHandler.currentWidget?.id !== args.id
) {
notebookShell.expandLeft(args.id as string);
} else {
notebookShell.collapseLeft();
if (notebookShell.currentWidget) {
notebookShell.activateById(notebookShell.currentWidget.id);
}
}
break;
case 'right':
if (notebookShell.rightCollapsed) {
notebookShell.expandRight(args.id as string);
} else if (
notebookShell.rightHandler.currentWidget?.id !== args.id
) {
notebookShell.expandRight(args.id as string);
} else {
notebookShell.collapseRight();
if (notebookShell.currentWidget) {
notebookShell.activateById(notebookShell.currentWidget.id);
}
}
break;
}
},
isToggled: args => {
switch (args['side'] as string) {
case 'left': {
if (notebookShell.leftCollapsed) {
return false;
}
const currentWidget = notebookShell.leftHandler.currentWidget;
if (!currentWidget) {
return false;
}

return currentWidget.id === (args['id'] as string);
}
case 'right': {
if (notebookShell.rightCollapsed) {
return false;
}
const currentWidget = notebookShell.rightHandler.currentWidget;
if (!currentWidget) {
return false;
}

return currentWidget.id === (args['id'] as string);
}
}
return false;
}
});

const sideBarMenu: { [area in SideBarPanel.Area]: IDisposable | null } = {
left: null,
right: null
};

/**
* The function which adds entries to the View menu for each widget of a sidebar.
*
* @param area - 'left' or 'right', the area of the side bar.
* @param entryLabel - the name of the main entry in the View menu for that sidebar.
* @returns - The disposable menu added to the View menu or null.
*/
const updateMenu = (area: SideBarPanel.Area, entryLabel: string) => {
if (menu === null) {
return null;
}

// Remove the previous menu entry for this sidebar.
sideBarMenu[area]?.dispose();

// Creates a new menu entry and populates it with sidebar widgets.
const newMenu = new Menu({ commands: app.commands });
newMenu.title.label = entryLabel;
const widgets = notebookShell.widgets(area);
let menuToAdd = false;

for (let widget of widgets) {
newMenu.addItem({
command: CommandIDs.togglePanel,
args: {
side: area,
title: `Show ${widget.title.caption}`,
id: widget.id
}
});
menuToAdd = true;
}

// If there are widgets, add the menu to the main menu entry.
if (menuToAdd) {
sideBarMenu[area] = menu.viewMenu.addItem({
type: 'submenu',
submenu: newMenu
});
}
};

app.restored.then(() => {
// Create menu entries for the left and right panel.
if (menu) {
const getSideBarLabel = (area: SideBarPanel.Area): string => {
if (area === 'left') {
return trans.__(`Left Sidebar`);
} else {
return trans.__(`Right Sidebar`);
}
};
const leftArea = notebookShell.leftHandler.area;
const leftLabel = getSideBarLabel(leftArea);
updateMenu(leftArea, leftLabel);

const rightArea = notebookShell.rightHandler.area;
const rightLabel = getSideBarLabel(rightArea);
updateMenu(rightArea, rightLabel);

const handleSideBarChange = (
sidebar: SideBarHandler,
widget: Widget
) => {
const label = getSideBarLabel(sidebar.area);
updateMenu(sidebar.area, label);
};

notebookShell.leftHandler.widgetAdded.connect(handleSideBarChange);
notebookShell.leftHandler.widgetRemoved.connect(handleSideBarChange);
notebookShell.rightHandler.widgetAdded.connect(handleSideBarChange);
notebookShell.rightHandler.widgetRemoved.connect(handleSideBarChange);
}

// Add palette entries for side panels.
if (palette) {
const sideBarPalette = new SideBarPalette({
commandPalette: palette as ICommandPalette,
command: CommandIDs.togglePanel
});

notebookShell.leftHandler.widgets.forEach(widget => {
sideBarPalette.addItem(widget, notebookShell.leftHandler.area);
});

notebookShell.rightHandler.widgets.forEach(widget => {
sideBarPalette.addItem(widget, notebookShell.rightHandler.area);
});

// Update menu and palette when widgets are added or removed from sidebars.
notebookShell.leftHandler.widgetAdded.connect((sidebar, widget) => {
sideBarPalette.addItem(widget, sidebar.area);
});
notebookShell.leftHandler.widgetRemoved.connect((sidebar, widget) => {
sideBarPalette.removeItem(widget, sidebar.area);
});
notebookShell.rightHandler.widgetAdded.connect((sidebar, widget) => {
sideBarPalette.addItem(widget, sidebar.area);
});
notebookShell.rightHandler.widgetRemoved.connect((sidebar, widget) => {
sideBarPalette.removeItem(widget, sidebar.area);
});
}
});
}
};

/**
* The default tree route resolver plugin.
*/
Expand Down Expand Up @@ -711,6 +935,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
router,
sessionDialogs,
shell,
sidebarVisibility,
status,
tabTitle,
title,
Expand Down
Loading