Skip to content

Commit

Permalink
[1.x] Make server extension verification call during extension startu…
Browse files Browse the repository at this point in the history
…p non-blocking (#480) (#481)

* Make server extension verification call during extension startup non-blocking (#480)

* remove async call, make call sync, refactor into a separate function

* don't use abbreviations in the verifyServerExtension function or type naming

* Update src/index.tsx

Co-authored-by: david qiu <[email protected]>

* remove unused type

* add @jupyterlab/rendermime-interfaces as a dependency

* Remove async from activatePlugin function declaration (makes it not async)

* set @jupyterlab/rendermime-interfaces version to ^3.8.0 to support all JLab >= 4

---------

Co-authored-by: david qiu <[email protected]>

* Fix translator usage, remove @jupyterlab/rendermime-interfaces dependency (#483)

* update snapshots

* use lowercase "es" is "es2017" as is convention in Project Jupyter

* fix 1.x dependencies

* fix package manifest to be compatible with JL3

* Make ErrorBoundary return JSX.Element to avoid type conflicts

---------

Co-authored-by: david qiu <[email protected]>
  • Loading branch information
andrii-i and dlqqq authored Feb 14, 2024
1 parent 07ca417 commit 2e3ccf0
Show file tree
Hide file tree
Showing 7 changed files with 2,439 additions and 4,060 deletions.
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@
"@jupyterlab/docmanager-extension": "^3.4.2",
"@jupyterlab/filebrowser": "^3.4.1",
"@jupyterlab/launcher": "^3.4.4",
"@jupyterlab/rendermime-interfaces": "^3",
"@jupyterlab/services": "^6.4.2",
"@jupyterlab/translation": "^3.4.1",
"@jupyterlab/ui-components": "^3.4.2",
"@lumino/polling": "^1.9.0",
"@lumino/signaling": "^1.10.0",
"@lumino/coreutils": "^1.12.0",
"@lumino/widgets": "^1.32.0",
"@lumino/coreutils": "^1",
"@lumino/polling": "^1",
"@lumino/signaling": "^1",
"@lumino/widgets": "^1",
"@mui/icons-material": "^5.10.9",
"@mui/material": "^5.10.6",
"@mui/system": "^5.10.6",
"@types/react-dom": "^18.0.5",
"cronstrue": "^2.12.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand All @@ -94,6 +94,8 @@
"mkdirp": "^1.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"@types/react": "^17.0.1",
"@types/react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"stylelint": "^14.3.0",
"stylelint-config-prettier": "^9.0.3",
Expand All @@ -104,8 +106,8 @@
"typescript": "~4.1.3"
},
"resolutions": {
"@types/react": "^17.0.1",
"@types/react-dom": "^18.0.5"
"@lumino/coreutils": "^1",
"@jupyterlab/rendermime-interfaces": "3.0.0 - 3.6.7"
},
"sideEffects": [
"style/*.css",
Expand Down
4 changes: 2 additions & 2 deletions src/components/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ErrorBoundary extends React.Component<
this.setState({ hasError: true, error });
}

render(): React.ReactNode {
render(): JSX.Element {
let errorDetail;
if (typeof this.state.error === 'string') {
errorDetail = this.state.error;
Expand All @@ -53,6 +53,6 @@ export class ErrorBoundary extends React.Component<
</div>
);
}
return this.props.children;
return <> {this.props.children} </>;
}
}
49 changes: 29 additions & 20 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ type EventLog = {
timestamp: Date;
};

/**
* Call API to verify that the server extension is actually installed.
*/
async function verifyServerExtension(props: {
api: SchedulerService;
translator: ITranslator;
}) {
const trans = props.translator.load('jupyterlab');
try {
await props.api.getJobs({ max_items: 0 });
} catch (e: unknown) {
// in case of 404, show missing server extension dialog and return
if (
e instanceof ServerConnection.ResponseError &&
e.response.status === 404
) {
showDialog({
title: trans.__('Jupyter Scheduler server extension not found'),
body: SERVER_EXTENSION_404_JSX,
buttons: [Dialog.okButton()]
}).catch(console.warn);
return;
}
}
}

/**
* Initialization data for the jupyterlab-scheduler extension.
*/
Expand Down Expand Up @@ -138,7 +164,7 @@ function getDirectoryFromPath(path: string | null): string | null {
return directories.join('/') + (directories.length > 0 ? '/' : '');
}

async function activatePlugin(
function activatePlugin(
app: JupyterFrontEnd,
browserFactory: IFileBrowserFactory,
notebookTracker: INotebookTracker,
Expand All @@ -147,27 +173,10 @@ async function activatePlugin(
advancedOptions: Scheduler.IAdvancedOptions,
telemetryHandler: Scheduler.TelemetryHandler,
launcher: ILauncher | null
): Promise<void> {
): void {
const trans = translator.load('jupyterlab');
const api = new SchedulerService({});

// Call API to verify that the server extension is actually installed
try {
await api.getJobs({ max_items: 0 });
} catch (e: unknown) {
// in case of 404, show missing server extension dialog and return
if (
e instanceof ServerConnection.ResponseError &&
e.response.status === 404
) {
showDialog({
title: trans.__('Jupyter Scheduler server extension not found'),
body: SERVER_EXTENSION_404_JSX,
buttons: [Dialog.okButton()]
}).catch(console.warn);
return;
}
}
verifyServerExtension({ api, translator });

const { commands } = app;
const fileBrowserTracker = browserFactory.tracker;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noUnusedLocals": true,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"outDir": "lib",
"rootDir": "src",
"strict": true,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2e3ccf0

Please sign in to comment.