@@ -4,11 +4,12 @@ import { ReactWidget, ISessionContext } from '@jupyterlab/apputils';
4
4
import { IChangedArgs } from '@jupyterlab/coreutils' ;
5
5
import { Kernel } from '@jupyterlab/services' ;
6
6
import { TranslationBundle } from '@jupyterlab/translation' ;
7
- import { INotebookTracker , NotebookPanel } from '@jupyterlab/notebook' ;
8
7
import { requestAPI } from './handler' ;
9
8
import { KernelUsagePanel } from './panel' ;
10
9
import useInterval from './useInterval' ;
11
10
import { formatForDisplay } from './format' ;
11
+ import { IWidgetWithSession } from './types' ;
12
+ import { KernelWidgetTracker } from './tracker' ;
12
13
13
14
type Usage = {
14
15
timestamp : Date | null ;
@@ -43,12 +44,11 @@ type KernelChangeCallback = (
43
44
) => void ;
44
45
let kernelChangeCallback : {
45
46
callback : KernelChangeCallback ;
46
- panel : NotebookPanel ;
47
+ panel : IWidgetWithSession ;
47
48
} | null = null ;
48
49
49
50
const KernelUsage = ( props : {
50
- widgetAdded : ISignal < INotebookTracker , NotebookPanel | null > ;
51
- currentNotebookChanged : ISignal < INotebookTracker , NotebookPanel | null > ;
51
+ currentChanged : ISignal < KernelWidgetTracker , IWidgetWithSession | null > ;
52
52
panel : KernelUsagePanel ;
53
53
trans : TranslationBundle ;
54
54
} ) => {
@@ -79,7 +79,7 @@ const KernelUsage = (props: {
79
79
} ;
80
80
81
81
useEffect ( ( ) => {
82
- const createKernelChangeCallback = ( panel : NotebookPanel ) => {
82
+ const createKernelChangeCallback = ( panel : IWidgetWithSession ) => {
83
83
return (
84
84
_sender : ISessionContext ,
85
85
args : IChangedArgs <
@@ -102,12 +102,13 @@ const KernelUsage = (props: {
102
102
} ;
103
103
104
104
const notebookChangeCallback = (
105
- sender : INotebookTracker ,
106
- panel : NotebookPanel | null
105
+ _ : KernelWidgetTracker ,
106
+ panel : IWidgetWithSession | null
107
107
) => {
108
108
if ( panel === null ) {
109
109
// Ideally we would switch to a new "select a notebook to get kernel
110
110
// usage" screen instead of showing outdated info.
111
+ setKernelId ( undefined ) ;
111
112
return ;
112
113
}
113
114
if ( kernelChangeCallback ) {
@@ -131,9 +132,9 @@ const KernelUsage = (props: {
131
132
}
132
133
}
133
134
} ;
134
- props . currentNotebookChanged . connect ( notebookChangeCallback ) ;
135
+ props . currentChanged . connect ( notebookChangeCallback ) ;
135
136
return ( ) => {
136
- props . currentNotebookChanged . disconnect ( notebookChangeCallback ) ;
137
+ props . currentChanged . disconnect ( notebookChangeCallback ) ;
137
138
// In the ideal world we would disconnect kernelChangeCallback from
138
139
// last panel here, but this can lead to a race condition. Instead,
139
140
// we make sure there is ever only one callback active by holding
@@ -239,31 +240,27 @@ const KernelUsage = (props: {
239
240
} ;
240
241
241
242
export class KernelUsageWidget extends ReactWidget {
242
- private _widgetAdded : ISignal < INotebookTracker , NotebookPanel | null > ;
243
- private _currentNotebookChanged : ISignal <
244
- INotebookTracker ,
245
- NotebookPanel | null
243
+ private _currentChanged : ISignal <
244
+ KernelWidgetTracker ,
245
+ IWidgetWithSession | null
246
246
> ;
247
247
private _panel : KernelUsagePanel ;
248
248
private _trans : TranslationBundle ;
249
249
constructor ( props : {
250
- widgetAdded : ISignal < INotebookTracker , NotebookPanel | null > ;
251
- currentNotebookChanged : ISignal < INotebookTracker , NotebookPanel | null > ;
250
+ currentChanged : ISignal < KernelWidgetTracker , IWidgetWithSession | null > ;
252
251
panel : KernelUsagePanel ;
253
252
trans : TranslationBundle ;
254
253
} ) {
255
254
super ( ) ;
256
- this . _widgetAdded = props . widgetAdded ;
257
- this . _currentNotebookChanged = props . currentNotebookChanged ;
255
+ this . _currentChanged = props . currentChanged ;
258
256
this . _panel = props . panel ;
259
257
this . _trans = props . trans ;
260
258
}
261
259
262
260
protected render ( ) : React . ReactElement < any > {
263
261
return (
264
262
< KernelUsage
265
- widgetAdded = { this . _widgetAdded }
266
- currentNotebookChanged = { this . _currentNotebookChanged }
263
+ currentChanged = { this . _currentChanged }
267
264
panel = { this . _panel }
268
265
trans = { this . _trans }
269
266
/>
0 commit comments