From e6e31986bdecc3c7ea0f982daf778c9e29fbc8e7 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Tue, 23 Apr 2024 21:17:28 +0200 Subject: [PATCH] JupyterLab 3 bug fix (#98) --- beakerx_widgets/js/package.json | 4 ++-- .../js/src/lab/plugin/gistPublish/index.ts | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/beakerx_widgets/js/package.json b/beakerx_widgets/js/package.json index 8be4ee0..bfa5fbc 100644 --- a/beakerx_widgets/js/package.json +++ b/beakerx_widgets/js/package.json @@ -1,6 +1,6 @@ { "name": "@beakerx/beakerx-widgets", - "version": "2.4.2", + "version": "2.4.3", "description": "BeakerX: Beaker EasyForms, Magics, Plots and Spark Extension for Jupyter Lab 2.x", "homepage": "http://beakerx.com/", "keywords": [ @@ -39,7 +39,7 @@ "prettier:fix": "prettier --check src/**/*.{ts,js} --write" }, "devDependencies": { - "@jupyterlab/builder": "^4", + "@jupyterlab/builder": "^3 || ^4", "@types/big.js": "^4.0.5", "@types/chai": "^4.2.11", "@types/d3": "^5.7.2", diff --git a/beakerx_widgets/js/src/lab/plugin/gistPublish/index.ts b/beakerx_widgets/js/src/lab/plugin/gistPublish/index.ts index a3ec42b..7491c3e 100644 --- a/beakerx_widgets/js/src/lab/plugin/gistPublish/index.ts +++ b/beakerx_widgets/js/src/lab/plugin/gistPublish/index.ts @@ -21,6 +21,7 @@ import { Cell, CodeCell } from '@jupyterlab/cells'; import { CommandRegistry } from '@lumino/commands'; import { GistPublisher, GistPublisherUtils } from '../../../plots/publisher'; import { AccessTokenProvider } from '../AccessTokenProvider'; +import { Widget } from '@lumino/widgets'; export function registerGistPublishFeature(panel: NotebookPanel, commands: CommandRegistry, showPublication: boolean) { if (showPublication) { @@ -48,10 +49,22 @@ function addActionButton(panel: NotebookPanel, commands: CommandRegistry): void } function removeActionButton(panel: NotebookPanel): void { - for (const widget of panel.toolbar.layout) { - if (widget instanceof ToolbarButton && widget.id == 'bx-publishButton') { - panel.toolbar.layout.removeWidget(widget); - break; + try { + for (const widget of panel.toolbar.layout) { + if (widget instanceof ToolbarButton && widget.id == 'bx-publishButton') { + panel.toolbar.layout.removeWidget(widget); + break; + } + } + } catch(e) { + // @ts-ignore JupyterLab 3 support + const iter = panel.toolbar.layout.iter(); + let widget: Widget; + while ((widget = iter.next())) { + if (widget instanceof ToolbarButton && widget.id == 'bx-publishButton') { + panel.toolbar.layout.removeWidget(widget); + break; + } } } }