Skip to content

Commit 2d717f5

Browse files
Dilip-Jainpre-commit-ci[bot]jtpiogithub-actions[bot]
authored
Added Edit Notebook Metadata Option (#6402) (#7099)
* Added Edit Notebook Metadata Option (#6402) Edit Notebook Metadata plugin added under Edit Menu for functionality similar to classic-notebook. Clicking on the option under the menu opens up the Notebook Tools widget in the right sidebar and expands the Additional Tools (which contains the Notebook Metadata editor) collapsible section (default: collapsed). * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added Edit Notebook Metadata Option (#6402) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Prettier Code for passing Test Lint check * Prettier Code for passing Test Lint check * adding the edit-notebook-metadata entry via schema adding the menu entry via the settings defined in the schema folder dropping the dependency on IMainMenu in the plugin * adding the edit-notebook-metadata entry via schema adding the menu entry via the settings defined in the schema folder dropping the dependency on IMainMenu in the plugin * adding the edit-notebook-metadata entry via schema * adding the edit-notebook-metadata entry via schema * adding the edit-notebook-metadata entry via schema * fix menu item * Add to the command palette * Update Playwright Snapshots * Update Playwright Snapshots * fix snapshots --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jeremy Tuloup <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1d0a402 commit 2d717f5

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"title": "Jupyter Notebook Menu Entries",
3+
"description": "Jupyter Notebook Menu Entries",
4+
"jupyter.lab.menus": {
5+
"main": [
6+
{
7+
"id": "jp-mainmenu-edit",
8+
"items": [
9+
{
10+
"type": "separator",
11+
"rank": 8.5
12+
},
13+
{
14+
"command": "notebook:edit-metadata",
15+
"rank": 8.5
16+
},
17+
{
18+
"type": "separator",
19+
"rank": 8.5
20+
}
21+
]
22+
}
23+
]
24+
},
25+
"properties": {},
26+
"additionalProperties": false,
27+
"type": "object"
28+
}

packages/notebook-extension/src/index.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ISessionContext,
1111
DOMUtils,
1212
IToolbarWidgetRegistry,
13+
ICommandPalette,
1314
} from '@jupyterlab/apputils';
1415

1516
import { Cell, CodeCell } from '@jupyterlab/cells';
@@ -63,6 +64,16 @@ const KERNEL_STATUS_FADE_OUT_CLASS = 'jp-NotebookKernelStatus-fade';
6364
*/
6465
const SCROLLED_OUTPUTS_CLASS = 'jp-mod-outputsScrolled';
6566

67+
/**
68+
* The command IDs used by the notebook plugins.
69+
*/
70+
namespace CommandIDs {
71+
/**
72+
* A command to open right sidebar for Editing Notebook Metadata
73+
*/
74+
export const openEditNotebookMetadata = 'notebook:edit-metadata';
75+
}
76+
6677
/**
6778
* A plugin for the checkpoint indicator
6879
*/
@@ -491,12 +502,71 @@ const trusted: JupyterFrontEndPlugin<void> = {
491502
},
492503
};
493504

505+
/**
506+
* Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu
507+
*/
508+
const editNotebookMetadata: JupyterFrontEndPlugin<void> = {
509+
id: '@jupyter-notebook/notebook-extension:edit-notebook-metadata',
510+
description:
511+
'Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu',
512+
autoStart: true,
513+
optional: [ICommandPalette, ITranslator, INotebookTools],
514+
activate: (
515+
app: JupyterFrontEnd,
516+
palette: ICommandPalette | null,
517+
translator: ITranslator | null,
518+
notebookTools: INotebookTools | null
519+
) => {
520+
const { commands } = app;
521+
translator = translator ?? nullTranslator;
522+
const trans = translator.load('notebook');
523+
524+
commands.addCommand(CommandIDs.openEditNotebookMetadata, {
525+
label: trans.__('Edit Notebook Metadata'),
526+
execute: async () => {
527+
const command = 'application:toggle-panel';
528+
const args = {
529+
side: 'right',
530+
title: 'Show Notebook Tools',
531+
id: 'notebook-tools',
532+
};
533+
534+
// Check if Show Notebook Tools (Right Sidebar) is open (expanded)
535+
if (!commands.isToggled(command, args)) {
536+
await commands.execute(command, args).then((_) => {
537+
// For expanding the 'Advanced Tools' section (default: collapsed)
538+
if (notebookTools) {
539+
const tools = (notebookTools?.layout as any).widgets;
540+
tools.forEach((tool: any) => {
541+
if (
542+
tool.widget.title.label === trans.__('Advanced Tools') &&
543+
tool.collapsed
544+
) {
545+
tool.toggle();
546+
}
547+
});
548+
}
549+
});
550+
}
551+
},
552+
});
553+
554+
if (palette) {
555+
palette.addItem({
556+
command: CommandIDs.openEditNotebookMetadata,
557+
category: 'Notebook Operations',
558+
});
559+
}
560+
},
561+
};
562+
494563
/**
495564
* Export the plugins as default.
496565
*/
497566
const plugins: JupyterFrontEndPlugin<any>[] = [
498567
checkpoints,
499568
closeTab,
569+
editNotebookMetadata,
500570
kernelLogo,
501571
kernelStatus,
502572
notebookToolsWidget,
304 Bytes
Loading
1.94 KB
Loading

0 commit comments

Comments
 (0)