Skip to content

Commit

Permalink
Add ready attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Mar 12, 2024
1 parent 8e9b2e9 commit 7eb662e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
48 changes: 9 additions & 39 deletions src/jupyterlab/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Token } from '@lumino/coreutils';
import { ISignal, Signal } from '@lumino/signaling';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
Expand All @@ -12,47 +10,15 @@ import {
} from '@jupyterlab/apputils';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { ILauncher } from '@jupyterlab/launcher';
import { PromiseDelegate } from '@lumino/coreutils';
import icon from '@datalayer/icons-react/data1/DatalayerGreenPaddingIconJupyterLab';
import { requestAPI } from './handler';
import { DatalayerWidget } from './widget';
import { datalayerStore } from '../state';
import { IDatalayerConfig } from './tokens';
import { IDatalayerConfig, IDatalayer, DatalayerConfiguration } from './tokens';

export * from './tokens';

export class DatalayerConfiguration {
private _configuration?: IDatalayerConfig;
private _configurationChanged: Signal<
DatalayerConfiguration,
IDatalayerConfig | undefined
>;
constructor() {
this._configurationChanged = new Signal<
DatalayerConfiguration,
IDatalayerConfig | undefined
>(this);
}
set configuration(configuration: IDatalayerConfig | undefined) {
this._configuration = configuration;
this._configurationChanged.emit(configuration);
}
get configuration() {
return this._configuration;
}
get configurationChanged(): ISignal<
DatalayerConfiguration,
IDatalayerConfig | undefined
> {
return this._configurationChanged;
}
}

export type IDatalayer = {
configuration: DatalayerConfiguration;
};

export const IDatalayer = new Token<IDatalayer>('@datalayer/core:plugin');

/**
* The command IDs used by the plugin.k
*/
Expand Down Expand Up @@ -88,9 +54,11 @@ const plugin: JupyterFrontEndPlugin<IDatalayer> = {
launcher?: ILauncher,
restorer?: ILayoutRestorer
): IDatalayer => {
const datalayer: IDatalayer = {
configuration: new DatalayerConfiguration()
};
const ready = new PromiseDelegate<void>();
const datalayer: IDatalayer = Object.freeze({
configuration: new DatalayerConfiguration(),
ready: ready.promise
});
storeConfiguration(datalayer.configuration.configuration);
datalayer.configuration.configurationChanged.connect((_, config) => {
storeConfiguration(config);
Expand All @@ -105,6 +73,7 @@ const plugin: JupyterFrontEndPlugin<IDatalayer> = {
whiteLabel: data.settings.white_label
};
datalayer.configuration.configuration = configuration;
ready.resolve();

// Don't add user interface elements in white label
if (configuration.whiteLabel) {
Expand Down Expand Up @@ -164,6 +133,7 @@ const plugin: JupyterFrontEndPlugin<IDatalayer> = {
}
})
.catch(reason => {
ready.reject(reason);
console.error(
`Error while accessing the jupyter server extension.\n${reason}`
);
Expand Down
37 changes: 37 additions & 0 deletions src/jupyterlab/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
import { Token } from '@lumino/coreutils';
import { ISignal, Signal } from '@lumino/signaling';

export type IDatalayerConfig = {
apiServerUrl: string;
launcherCategory: string;
whiteLabel: boolean;
};

export type IDatalayer = {
configuration: DatalayerConfiguration;
ready: Promise<void>;
};

export const IDatalayer = new Token<IDatalayer>('@datalayer/core:plugin');

export class DatalayerConfiguration {
private _configuration?: IDatalayerConfig;
private _configurationChanged: Signal<
DatalayerConfiguration,
IDatalayerConfig | undefined
>;
constructor() {
this._configurationChanged = new Signal<
DatalayerConfiguration,
IDatalayerConfig | undefined
>(this);
}
set configuration(configuration: IDatalayerConfig | undefined) {
this._configuration = configuration;
this._configurationChanged.emit(configuration);
}
get configuration() {
return this._configuration;
}
get configurationChanged(): ISignal<
DatalayerConfiguration,
IDatalayerConfig | undefined
> {
return this._configurationChanged;
}
}

0 comments on commit 7eb662e

Please sign in to comment.