Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extension not showing up in the Settings Editor #120

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Add an option to show the cell outputs per second [#116](https://github.com/deshaw/jupyterlab-execute-time/pull/116)

### Fixed

- Fix extension not showing up in the Settings Editor [#120](https://github.com/deshaw/jupyterlab-execute-time/pull/120)

## [3.1.2](https://github.com/deshaw/jupyterlab-execute-time/compare/v3.1.0...v3.1.2) (2024-02-14)

### Fixed
Expand Down
34 changes: 4 additions & 30 deletions src/ExecuteTimeWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,16 @@ export default class ExecuteTimeWidget extends Widget {
constructor(
panel: NotebookPanel,
tracker: INotebookTracker,
settingRegistry: ISettingRegistry
settings: ISettingRegistry.ISettings
) {
super();
this._panel = panel;
this._tracker = tracker;
this._settingRegistry = settingRegistry;

this.updateConnectedCell = this.updateConnectedCell.bind(this);
settingRegistry.load(`${PLUGIN_NAME}:settings`).then(
(settings: ISettingRegistry.ISettings) => {
this._updateSettings(settings);
settings.changed.connect(this._updateSettings.bind(this));

// If the plugin is enabled, force recording of timing
// We only do this once (not on every settings update) in case the user tries to turn it off
if (settings.get('enabled').composite) {
this._settingRegistry
.load('@jupyterlab/notebook-extension:tracker')
.then(
(nbSettings: ISettingRegistry.ISettings) =>
nbSettings.set('recordTiming', true),
(err: Error) => {
console.error(
`jupyterlab-execute-time: Could not force metadata recording: ${err}`
);
}
);
}
},
(err: Error) => {
console.error(
`jupyterlab-execute-time: Could not load settings, so did not active ${PLUGIN_NAME}: ${err}`
);
}
);

this._updateSettings(settings);
settings.changed.connect(this._updateSettings.bind(this));
}

/**
Expand Down Expand Up @@ -517,7 +492,6 @@ export default class ExecuteTimeWidget extends Widget {
} = {};
private _tracker: INotebookTracker;
private _panel: NotebookPanel;
private _settingRegistry: ISettingRegistry;
private _settings: IExecuteTimeSettings = {
enabled: false,
highlight: true,
Expand Down
36 changes: 30 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { DocumentRegistry } from '@jupyterlab/docregistry';
import ExecuteTimeWidget, { PLUGIN_NAME } from './ExecuteTimeWidget';

class ExecuteTimeWidgetExtension implements DocumentRegistry.WidgetExtension {
constructor(tracker: INotebookTracker, settingRegistry: ISettingRegistry) {
this._settingRegistry = settingRegistry;
constructor(tracker: INotebookTracker, settings: ISettingRegistry.ISettings) {
this._settings = settings;
this._tracker = tracker;
}

Expand All @@ -22,10 +22,10 @@ class ExecuteTimeWidgetExtension implements DocumentRegistry.WidgetExtension {
panel: NotebookPanel,
context: DocumentRegistry.IContext<INotebookModel>
) {
return new ExecuteTimeWidget(panel, this._tracker, this._settingRegistry);
return new ExecuteTimeWidget(panel, this._tracker, this._settings);
}

private _settingRegistry: ISettingRegistry;
private _settings: ISettingRegistry.ISettings;
private _tracker: INotebookTracker;
}

Expand All @@ -36,14 +36,38 @@ const extension: JupyterFrontEndPlugin<void> = {
id: PLUGIN_NAME,
autoStart: true,
requires: [INotebookTracker, ISettingRegistry],
activate: (
activate: async (
app: JupyterFrontEnd,
tracker: INotebookTracker,
settingRegistry: ISettingRegistry
) => {
let settings: ISettingRegistry.ISettings;
try {
settings = await settingRegistry.load(`${PLUGIN_NAME}:settings`);
} catch (err: unknown) {
console.error(
`jupyterlab-execute-time: Could not load settings, so did not active ${PLUGIN_NAME}: ${err}`
);
return;
}

// If the plugin is enabled, force recording of timing
// We only do this once (not on every settings update) in case the user tries to turn it off
if (settings.get('enabled').composite) {
settingRegistry.load('@jupyterlab/notebook-extension:tracker').then(
(nbSettings: ISettingRegistry.ISettings) =>
nbSettings.set('recordTiming', true),
(err: Error) => {
console.error(
`jupyterlab-execute-time: Could not force metadata recording: ${err}`
);
}
);
}

app.docRegistry.addWidgetExtension(
'Notebook',
new ExecuteTimeWidgetExtension(tracker, settingRegistry)
new ExecuteTimeWidgetExtension(tracker, settings)
);

// eslint-disable-next-line no-console
Expand Down
15 changes: 15 additions & 0 deletions ui-tests/tests/settings_editor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from '@jupyterlab/galata';

test.describe('Settings Editor', () => {
test('Execute Time show up in the Settings Editor', async ({ page }) => {
await page.evaluate(async () => {
await window.jupyterapp.commands.execute('settingeditor:open');
});
const plugin = page.locator(
'.jp-PluginList .jp-PluginList-entry >> text="Execute Time"'
);

await plugin.waitFor();
expect(plugin).toHaveCount(1);
});
});
Loading