Skip to content

Commit

Permalink
Added Edit Notebook Metadata Option (#6402) (#7099)
Browse files Browse the repository at this point in the history
* 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 <jeremy.tuloup@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 7, 2024
1 parent 1d0a402 commit 2d717f5
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 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"
}
70 changes: 70 additions & 0 deletions packages/notebook-extension/src/index.ts
Expand Up @@ -10,6 +10,7 @@ import {
ISessionContext,
DOMUtils,
IToolbarWidgetRegistry,
ICommandPalette,
} from '@jupyterlab/apputils';

import { Cell, CodeCell } from '@jupyterlab/cells';
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -491,12 +502,71 @@ const trusted: JupyterFrontEndPlugin<void> = {
},
};

/**
* Add a command to open right sidebar for Editing Notebook Metadata when clicking on "Edit Notebook Metadata" under Edit menu
*/
const editNotebookMetadata: JupyterFrontEndPlugin<void> = {
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<any>[] = [
checkpoints,
closeTab,
editNotebookMetadata,
kernelLogo,
kernelStatus,
notebookToolsWidget,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d717f5

Please sign in to comment.