4
4
* MIT License
5
5
*/
6
6
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
-
13
7
import React , { useCallback , useContext , useEffect , useState } from 'react' ;
14
8
import { createRoot } from 'react-dom/client' ;
15
9
import { ServiceManager } from '@jupyterlab/services' ;
@@ -35,48 +29,23 @@ function NotebookVSCode(): JSX.Element {
35
29
const [ serviceManager , setServiceManager ] = useState <
36
30
ServiceManager | undefined
37
31
> ( ) ;
38
- const [ runtimeReady , setRuntimeReady ] = useState ( false ) ;
39
32
const kernelId = useKernelId ( {
40
33
kernels : serviceManager ?. kernels ,
41
- startDefaultKernel : runtimeReady ,
34
+ startDefaultKernel : true ,
42
35
} ) ;
43
36
const model = useNotebookModel ( { nbformat } ) ;
44
37
useEffect ( ( ) => {
45
- if ( model && serviceManager ) {
38
+ if ( model ) {
46
39
setIsLoading ( false ) ;
47
40
}
48
- } , [ model , serviceManager ] ) ;
41
+ } , [ model ] ) ;
49
42
const handler = useCallback (
50
43
async ( message : ExtensionMessage ) => {
51
44
const { type, body, id } = message ;
52
45
switch ( type ) {
53
46
case 'init' : {
54
47
// FIXME
55
48
// 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
-
80
49
if ( body . untitled ) {
81
50
setNbformat ( { } as any ) ;
82
51
return ;
@@ -115,32 +84,26 @@ function NotebookVSCode(): JSX.Element {
115
84
disposable . dispose ( ) ;
116
85
} ;
117
86
} , [ 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
+ ) : (
140
95
< Box
141
96
style = { { height, width : '100%' , position : 'relative' } }
142
97
id = "dla-Jupyter-Notebook"
143
98
>
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 >
144
107
< Box
145
108
className = "dla-Box-Notebook"
146
109
sx = { {
0 commit comments