diff --git a/packages/notebook-extension/schema/edit-notebook-metadata.json b/packages/notebook-extension/schema/edit-notebook-metadata.json new file mode 100644 index 0000000000..f93274e1cc --- /dev/null +++ b/packages/notebook-extension/schema/edit-notebook-metadata.json @@ -0,0 +1,28 @@ +{ + "title": "Jupyter Notebook Menu Entries", + "description": "Jupyter Notebook Menu Entries", + "jupyter.lab.menus": { + "main": [ + { + "id": "jp-mainmenu-edit", + "items": [ + { + "type": "separator", + "rank": 8.5 + }, + { + "command": "notebook:edit-metadata", + "rank": 8.5 + }, + { + "type": "separator", + "rank": 8.5 + } + ] + } + ] + }, + "properties": {}, + "additionalProperties": false, + "type": "object" +} diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index cad2762453..86fb9bc917 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -10,6 +10,7 @@ import { ISessionContext, DOMUtils, IToolbarWidgetRegistry, + ICommandPalette, } from '@jupyterlab/apputils'; import { Cell, CodeCell } from '@jupyterlab/cells'; @@ -63,6 +64,16 @@ const KERNEL_STATUS_FADE_OUT_CLASS = 'jp-NotebookKernelStatus-fade'; */ const SCROLLED_OUTPUTS_CLASS = 'jp-mod-outputsScrolled'; +/** + * The command IDs used by the notebook plugins. + */ +namespace CommandIDs { + /** + * A command to open right sidebar for Editing Notebook Metadata + */ + export const openEditNotebookMetadata = 'notebook:edit-metadata'; +} + /** * A plugin for the checkpoint indicator */ @@ -491,12 +502,71 @@ const trusted: JupyterFrontEndPlugin = { }, }; +/** + * Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu + */ +const editNotebookMetadata: JupyterFrontEndPlugin = { + id: '@jupyter-notebook/notebook-extension:edit-notebook-metadata', + description: + 'Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu', + autoStart: true, + optional: [ICommandPalette, ITranslator, INotebookTools], + activate: ( + app: JupyterFrontEnd, + palette: ICommandPalette | null, + translator: ITranslator | null, + notebookTools: INotebookTools | null + ) => { + const { commands } = app; + translator = translator ?? nullTranslator; + const trans = translator.load('notebook'); + + commands.addCommand(CommandIDs.openEditNotebookMetadata, { + label: trans.__('Edit Notebook Metadata'), + execute: async () => { + const command = 'application:toggle-panel'; + const args = { + side: 'right', + title: 'Show Notebook Tools', + id: 'notebook-tools', + }; + + // Check if Show Notebook Tools (Right Sidebar) is open (expanded) + if (!commands.isToggled(command, args)) { + await commands.execute(command, args).then((_) => { + // For expanding the 'Advanced Tools' section (default: collapsed) + if (notebookTools) { + const tools = (notebookTools?.layout as any).widgets; + tools.forEach((tool: any) => { + if ( + tool.widget.title.label === trans.__('Advanced Tools') && + tool.collapsed + ) { + tool.toggle(); + } + }); + } + }); + } + }, + }); + + if (palette) { + palette.addItem({ + command: CommandIDs.openEditNotebookMetadata, + category: 'Notebook Operations', + }); + } + }, +}; + /** * Export the plugins as default. */ const plugins: JupyterFrontEndPlugin[] = [ checkpoints, closeTab, + editNotebookMetadata, kernelLogo, kernelStatus, notebookToolsWidget, diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-chromium-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-chromium-linux.png index c7edfc8421..ea28dd1503 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-chromium-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-chromium-linux.png differ diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-firefox-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-firefox-linux.png index 6b1d024863..ad82a4f51f 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-firefox-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-edit-firefox-linux.png differ