Skip to content

Commit 2839130

Browse files
authored
Restore the use of contentHeader, make CI green, improve scripts (#263)
* 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
1 parent 2b9283f commit 2839130

File tree

7 files changed

+34
-13
lines changed

7 files changed

+34
-13
lines changed

contentheader/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ This JupyterLab example extension is intended to demo one specific feature of `M
1111
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).
1212

1313
```ts
14-
// src/index.ts#L33-L50
14+
// src/index.ts#L33-L58
1515

1616
commands.addCommand(command, {
1717
label: 'Populate content header (time example)',
1818
caption: 'Populate content header (time example)',
1919
execute: () => {
2020
// Check to ensure this is a MainAreaWidget
21-
const widget = app.shell.currentWidget;
21+
const main = app.shell.currentWidget;
2222

23-
if (widget instanceof MainAreaWidget) {
23+
if (main instanceof MainAreaWidget) {
24+
// Create a widget
25+
const widget = new Widget();
2426
widget.addClass('example-extension-contentheader-widget');
2527
widget.node.textContent = generateContent();
2628

29+
// set the height so that it is visible
30+
widget.node.style.minHeight = '20px';
31+
32+
// and insert it into the header
33+
main.contentHeader.addWidget(widget);
34+
2735
// Every so often, update the widget's contents
2836
setInterval(() => {
2937
widget.node.textContent = generateContent();

contentheader/preview.gif

-88 KB
Loading

contentheader/src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
JupyterFrontEnd,
33
JupyterFrontEndPlugin
44
} from '@jupyterlab/application';
5-
5+
import { Widget } from '@lumino/widgets';
66
import { ICommandPalette, MainAreaWidget } from '@jupyterlab/apputils';
77

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

40-
if (widget instanceof MainAreaWidget) {
40+
if (main instanceof MainAreaWidget) {
41+
// Create a widget
42+
const widget = new Widget();
4143
widget.addClass('example-extension-contentheader-widget');
4244
widget.node.textContent = generateContent();
4345

46+
// set the height so that it is visible
47+
widget.node.style.minHeight = '20px';
48+
49+
// and insert it into the header
50+
main.contentHeader.addWidget(widget);
51+
4452
// Every so often, update the widget's contents
4553
setInterval(() => {
4654
widget.node.textContent = generateContent();

contentheader/ui-tests/tests/contentheader.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ test('should populate the contentheader', async ({ page }) => {
1515

1616
// Ensure we see text from the extension example
1717
expect(await page.waitForSelector('text=Time in GMT is:')).toBeTruthy();
18+
19+
// Ensure that launcher was not overwritten
20+
expect(await page.waitForSelector('.jp-Launcher-content')).toBeTruthy();
1821
});

context-menu/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ The first step is to define the command that will be executed when clicking on t
3535
3636
<!-- prettier-ignore-start -->
3737
```ts
38-
// src/index.ts#L15-L31
38+
// src/index.ts#L15-L32
3939

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

4849
if (file) {
4950
showDialog({

context-menu/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const extension: JupyterFrontEndPlugin<void> = {
1717
caption: "Example context menu button for file browser's items.",
1818
icon: buildIcon,
1919
execute: () => {
20-
const file = factory.tracker.currentWidget?.selectedItems().next()
21-
.value;
20+
const file = factory.tracker.currentWidget
21+
?.selectedItems()
22+
.next().value;
2223

2324
if (file) {
2425
showDialog({

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"embedme": "embedme \"[!n]*/README.md\" \"notifications/README.md\"",
88
"install-py": "lerna exec --concurrency 4 -- touch yarn.lock && lerna exec --concurrency 4 -- python -m pip install \".\"",
99
"install-ext": "lerna run install:extension",
10-
"lint": "lerna run lint",
11-
"lint:check": "jlpm run embedme --verify && lerna run lint:check",
10+
"lint": "lerna run lint && jlpm run embedme",
11+
"lint:check": "lerna run lint:check && jlpm run embedme --verify",
1212
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
1313
"prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\""
1414
},

0 commit comments

Comments
 (0)