Skip to content

Commit 2e3ccf0

Browse files
andrii-idlqqq
andauthored
[1.x] Make server extension verification call during extension startup 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]>
1 parent 07ca417 commit 2e3ccf0

File tree

7 files changed

+2439
-4060
lines changed

7 files changed

+2439
-4060
lines changed

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@
6363
"@jupyterlab/docmanager-extension": "^3.4.2",
6464
"@jupyterlab/filebrowser": "^3.4.1",
6565
"@jupyterlab/launcher": "^3.4.4",
66+
"@jupyterlab/rendermime-interfaces": "^3",
6667
"@jupyterlab/services": "^6.4.2",
6768
"@jupyterlab/translation": "^3.4.1",
6869
"@jupyterlab/ui-components": "^3.4.2",
69-
"@lumino/polling": "^1.9.0",
70-
"@lumino/signaling": "^1.10.0",
71-
"@lumino/coreutils": "^1.12.0",
72-
"@lumino/widgets": "^1.32.0",
70+
"@lumino/coreutils": "^1",
71+
"@lumino/polling": "^1",
72+
"@lumino/signaling": "^1",
73+
"@lumino/widgets": "^1",
7374
"@mui/icons-material": "^5.10.9",
7475
"@mui/material": "^5.10.6",
7576
"@mui/system": "^5.10.6",
76-
"@types/react-dom": "^18.0.5",
7777
"cronstrue": "^2.12.0",
7878
"react": "^17.0.1",
7979
"react-dom": "^17.0.1",
@@ -94,6 +94,8 @@
9494
"mkdirp": "^1.0.3",
9595
"npm-run-all": "^4.1.5",
9696
"prettier": "^2.1.1",
97+
"@types/react": "^17.0.1",
98+
"@types/react-dom": "^17.0.1",
9799
"rimraf": "^3.0.2",
98100
"stylelint": "^14.3.0",
99101
"stylelint-config-prettier": "^9.0.3",
@@ -104,8 +106,8 @@
104106
"typescript": "~4.1.3"
105107
},
106108
"resolutions": {
107-
"@types/react": "^17.0.1",
108-
"@types/react-dom": "^18.0.5"
109+
"@lumino/coreutils": "^1",
110+
"@jupyterlab/rendermime-interfaces": "3.0.0 - 3.6.7"
109111
},
110112
"sideEffects": [
111113
"style/*.css",

src/components/error-boundary.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ErrorBoundary extends React.Component<
2727
this.setState({ hasError: true, error });
2828
}
2929

30-
render(): React.ReactNode {
30+
render(): JSX.Element {
3131
let errorDetail;
3232
if (typeof this.state.error === 'string') {
3333
errorDetail = this.state.error;
@@ -53,6 +53,6 @@ export class ErrorBoundary extends React.Component<
5353
</div>
5454
);
5555
}
56-
return this.props.children;
56+
return <> {this.props.children} </>;
5757
}
5858
}

src/index.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ type EventLog = {
4646
timestamp: Date;
4747
};
4848

49+
/**
50+
* Call API to verify that the server extension is actually installed.
51+
*/
52+
async function verifyServerExtension(props: {
53+
api: SchedulerService;
54+
translator: ITranslator;
55+
}) {
56+
const trans = props.translator.load('jupyterlab');
57+
try {
58+
await props.api.getJobs({ max_items: 0 });
59+
} catch (e: unknown) {
60+
// in case of 404, show missing server extension dialog and return
61+
if (
62+
e instanceof ServerConnection.ResponseError &&
63+
e.response.status === 404
64+
) {
65+
showDialog({
66+
title: trans.__('Jupyter Scheduler server extension not found'),
67+
body: SERVER_EXTENSION_404_JSX,
68+
buttons: [Dialog.okButton()]
69+
}).catch(console.warn);
70+
return;
71+
}
72+
}
73+
}
74+
4975
/**
5076
* Initialization data for the jupyterlab-scheduler extension.
5177
*/
@@ -138,7 +164,7 @@ function getDirectoryFromPath(path: string | null): string | null {
138164
return directories.join('/') + (directories.length > 0 ? '/' : '');
139165
}
140166

141-
async function activatePlugin(
167+
function activatePlugin(
142168
app: JupyterFrontEnd,
143169
browserFactory: IFileBrowserFactory,
144170
notebookTracker: INotebookTracker,
@@ -147,27 +173,10 @@ async function activatePlugin(
147173
advancedOptions: Scheduler.IAdvancedOptions,
148174
telemetryHandler: Scheduler.TelemetryHandler,
149175
launcher: ILauncher | null
150-
): Promise<void> {
176+
): void {
151177
const trans = translator.load('jupyterlab');
152178
const api = new SchedulerService({});
153-
154-
// Call API to verify that the server extension is actually installed
155-
try {
156-
await api.getJobs({ max_items: 0 });
157-
} catch (e: unknown) {
158-
// in case of 404, show missing server extension dialog and return
159-
if (
160-
e instanceof ServerConnection.ResponseError &&
161-
e.response.status === 404
162-
) {
163-
showDialog({
164-
title: trans.__('Jupyter Scheduler server extension not found'),
165-
body: SERVER_EXTENSION_404_JSX,
166-
buttons: [Dialog.okButton()]
167-
}).catch(console.warn);
168-
return;
169-
}
170-
}
179+
verifyServerExtension({ api, translator });
171180

172181
const { commands } = app;
173182
const fileBrowserTracker = browserFactory.tracker;

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"noUnusedLocals": true,
1414
"preserveWatchOutput": true,
1515
"resolveJsonModule": true,
16+
"skipLibCheck": true,
1617
"outDir": "lib",
1718
"rootDir": "src",
1819
"strict": true,
-9 Bytes
Loading
-9 Bytes
Loading

0 commit comments

Comments
 (0)