Skip to content

Commit a56fb80

Browse files
committed
Test notebook
1 parent f017783 commit a56fb80

File tree

1 file changed

+19
-56
lines changed

1 file changed

+19
-56
lines changed

packages/vscode/webview/NotebookVSCode.tsx

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
* MIT License
55
*/
66

7-
/**
8-
* @module NotebookVSCode
9-
* @description React component for the Jupyter notebook editor.
10-
* Provides the main UI for viewing and editing Jupyter notebooks with full kernel support.
11-
*/
12-
137
import React, { useCallback, useContext, useEffect, useState } from 'react';
148
import { createRoot } from 'react-dom/client';
159
import { ServiceManager } from '@jupyterlab/services';
@@ -35,48 +29,23 @@ function NotebookVSCode(): JSX.Element {
3529
const [serviceManager, setServiceManager] = useState<
3630
ServiceManager | undefined
3731
>();
38-
const [runtimeReady, setRuntimeReady] = useState(false);
3932
const kernelId = useKernelId({
4033
kernels: serviceManager?.kernels,
41-
startDefaultKernel: runtimeReady,
34+
startDefaultKernel: true,
4235
});
4336
const model = useNotebookModel({ nbformat });
4437
useEffect(() => {
45-
if (model && serviceManager) {
38+
if (model) {
4639
setIsLoading(false);
4740
}
48-
}, [model, serviceManager]);
41+
}, [model]);
4942
const handler = useCallback(
5043
async (message: ExtensionMessage) => {
5144
const { type, body, id } = message;
5245
switch (type) {
5346
case 'init': {
5447
// FIXME
5548
// editor.setEditable(body.editable);
56-
57-
// Initialize runtime if provided
58-
if (body.runtime) {
59-
const { baseUrl, token } = body.runtime;
60-
if (baseUrl && token) {
61-
console.log(
62-
'[NotebookVSCode] Initializing with runtime:',
63-
baseUrl,
64-
);
65-
const manager = createServiceManager(baseUrl, token);
66-
setServiceManager(manager);
67-
setRuntimeReady(true);
68-
} else {
69-
console.warn(
70-
'[NotebookVSCode] Runtime info incomplete:',
71-
body.runtime,
72-
);
73-
}
74-
} else {
75-
console.log(
76-
'[NotebookVSCode] No runtime info provided in init message',
77-
);
78-
}
79-
8049
if (body.untitled) {
8150
setNbformat({} as any);
8251
return;
@@ -115,32 +84,26 @@ function NotebookVSCode(): JSX.Element {
11584
disposable.dispose();
11685
};
11786
}, [messageHandler, handler]);
118-
// Don't render the notebook until we have both model and service manager
119-
if (isLoading || !model) {
120-
return <Loader key="notebook-loader" />;
121-
}
122-
123-
if (!serviceManager) {
124-
return (
125-
<Box
126-
style={{ height, width: '100%', position: 'relative', padding: '20px' }}
127-
id="dla-Jupyter-Notebook"
128-
>
129-
<Box sx={{ textAlign: 'center' }}>
130-
<div>Waiting for runtime initialization...</div>
131-
<div style={{ fontSize: '12px', marginTop: '10px', color: '#666' }}>
132-
The notebook requires a runtime to execute code.
133-
</div>
134-
</Box>
135-
</Box>
136-
);
137-
}
138-
139-
return (
87+
const selectRuntime = useCallback(async () => {
88+
const reply = await messageHandler.postRequest({ type: 'select-runtime' });
89+
const { baseUrl, token } = reply.body ?? {};
90+
setServiceManager(createServiceManager(baseUrl, token));
91+
}, [messageHandler]);
92+
return isLoading ? (
93+
<Loader key="notebook-loader" />
94+
) : (
14095
<Box
14196
style={{ height, width: '100%', position: 'relative' }}
14297
id="dla-Jupyter-Notebook"
14398
>
99+
<Box sx={{ display: 'flex' }}>
100+
<Button
101+
title="Select a runtime for the current notebook."
102+
onClick={selectRuntime}
103+
>
104+
Select Runtime
105+
</Button>
106+
</Box>
144107
<Box
145108
className="dla-Box-Notebook"
146109
sx={{

0 commit comments

Comments
 (0)