Skip to content

Commit

Permalink
Restore the use of contentHeader, make CI green, improve scripts (#263
Browse files Browse the repository at this point in the history
)

* Restore the use of `contentHeader`

* Correct range

* Update the preview GIF

* Test: ensure the main area does not get overridden

* Align

* Lint (unrelated) context-menu index

* Run embedme after lint

* Run lint:check before embedme because the former might

force us to reformat a file which would change ranges,
so checking embedme first is pointless
  • Loading branch information
krassowski authored Feb 7, 2024
1 parent 2b9283f commit 2839130
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
14 changes: 11 additions & 3 deletions contentheader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ This JupyterLab example extension is intended to demo one specific feature of `M
In code: the command `jlab-examples:contentheader` creates a widget and check if it is an instance of `MainAreaWidget`. A specific text content is then added to this widget (here the current GMT time).

```ts
// src/index.ts#L33-L50
// src/index.ts#L33-L58

commands.addCommand(command, {
label: 'Populate content header (time example)',
caption: 'Populate content header (time example)',
execute: () => {
// Check to ensure this is a MainAreaWidget
const widget = app.shell.currentWidget;
const main = app.shell.currentWidget;

if (widget instanceof MainAreaWidget) {
if (main instanceof MainAreaWidget) {
// Create a widget
const widget = new Widget();
widget.addClass('example-extension-contentheader-widget');
widget.node.textContent = generateContent();

// set the height so that it is visible
widget.node.style.minHeight = '20px';

// and insert it into the header
main.contentHeader.addWidget(widget);

// Every so often, update the widget's contents
setInterval(() => {
widget.node.textContent = generateContent();
Expand Down
Binary file modified contentheader/preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions contentheader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import { Widget } from '@lumino/widgets';
import { ICommandPalette, MainAreaWidget } from '@jupyterlab/apputils';

/**
Expand Down Expand Up @@ -35,12 +35,20 @@ const plugin: JupyterFrontEndPlugin<void> = {
caption: 'Populate content header (time example)',
execute: () => {
// Check to ensure this is a MainAreaWidget
const widget = app.shell.currentWidget;
const main = app.shell.currentWidget;

if (widget instanceof MainAreaWidget) {
if (main instanceof MainAreaWidget) {
// Create a widget
const widget = new Widget();
widget.addClass('example-extension-contentheader-widget');
widget.node.textContent = generateContent();

// set the height so that it is visible
widget.node.style.minHeight = '20px';

// and insert it into the header
main.contentHeader.addWidget(widget);

// Every so often, update the widget's contents
setInterval(() => {
widget.node.textContent = generateContent();
Expand Down
3 changes: 3 additions & 0 deletions contentheader/ui-tests/tests/contentheader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ test('should populate the contentheader', async ({ page }) => {

// Ensure we see text from the extension example
expect(await page.waitForSelector('text=Time in GMT is:')).toBeTruthy();

// Ensure that launcher was not overwritten
expect(await page.waitForSelector('.jp-Launcher-content')).toBeTruthy();
});
7 changes: 4 additions & 3 deletions context-menu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ The first step is to define the command that will be executed when clicking on t
<!-- prettier-ignore-start -->
```ts
// src/index.ts#L15-L31
// src/index.ts#L15-L32

app.commands.addCommand('jlab-examples/context-menu:open', {
label: 'Example',
caption: "Example context menu button for file browser's items.",
icon: buildIcon,
execute: () => {
const file = factory.tracker.currentWidget?.selectedItems().next()
.value;
const file = factory.tracker.currentWidget
?.selectedItems()
.next().value;

if (file) {
showDialog({
Expand Down
5 changes: 3 additions & 2 deletions context-menu/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const extension: JupyterFrontEndPlugin<void> = {
caption: "Example context menu button for file browser's items.",
icon: buildIcon,
execute: () => {
const file = factory.tracker.currentWidget?.selectedItems().next()
.value;
const file = factory.tracker.currentWidget
?.selectedItems()
.next().value;

if (file) {
showDialog({
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"embedme": "embedme \"[!n]*/README.md\" \"notifications/README.md\"",
"install-py": "lerna exec --concurrency 4 -- touch yarn.lock && lerna exec --concurrency 4 -- python -m pip install \".\"",
"install-ext": "lerna run install:extension",
"lint": "lerna run lint",
"lint:check": "jlpm run embedme --verify && lerna run lint:check",
"lint": "lerna run lint && jlpm run embedme",
"lint:check": "lerna run lint:check && jlpm run embedme --verify",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\""
},
Expand Down

0 comments on commit 2839130

Please sign in to comment.