@@ -4,11 +4,12 @@ import { ReactWidget, ISessionContext } from '@jupyterlab/apputils';
44import { IChangedArgs } from '@jupyterlab/coreutils' ;
55import { Kernel } from '@jupyterlab/services' ;
66import { TranslationBundle } from '@jupyterlab/translation' ;
7- import { INotebookTracker , NotebookPanel } from '@jupyterlab/notebook' ;
87import { requestAPI } from './handler' ;
98import { KernelUsagePanel } from './panel' ;
109import useInterval from './useInterval' ;
1110import { formatForDisplay } from './format' ;
11+ import { IWidgetWithSession } from './types' ;
12+ import { KernelWidgetTracker } from './tracker' ;
1213
1314type Usage = {
1415 timestamp : Date | null ;
@@ -43,12 +44,11 @@ type KernelChangeCallback = (
4344) => void ;
4445let kernelChangeCallback : {
4546 callback : KernelChangeCallback ;
46- panel : NotebookPanel ;
47+ panel : IWidgetWithSession ;
4748} | null = null ;
4849
4950const KernelUsage = ( props : {
50- widgetAdded : ISignal < INotebookTracker , NotebookPanel | null > ;
51- currentNotebookChanged : ISignal < INotebookTracker , NotebookPanel | null > ;
51+ currentChanged : ISignal < KernelWidgetTracker , IWidgetWithSession | null > ;
5252 panel : KernelUsagePanel ;
5353 trans : TranslationBundle ;
5454} ) => {
@@ -79,7 +79,7 @@ const KernelUsage = (props: {
7979 } ;
8080
8181 useEffect ( ( ) => {
82- const createKernelChangeCallback = ( panel : NotebookPanel ) => {
82+ const createKernelChangeCallback = ( panel : IWidgetWithSession ) => {
8383 return (
8484 _sender : ISessionContext ,
8585 args : IChangedArgs <
@@ -102,12 +102,13 @@ const KernelUsage = (props: {
102102 } ;
103103
104104 const notebookChangeCallback = (
105- sender : INotebookTracker ,
106- panel : NotebookPanel | null
105+ _ : KernelWidgetTracker ,
106+ panel : IWidgetWithSession | null
107107 ) => {
108108 if ( panel === null ) {
109109 // Ideally we would switch to a new "select a notebook to get kernel
110110 // usage" screen instead of showing outdated info.
111+ setKernelId ( undefined ) ;
111112 return ;
112113 }
113114 if ( kernelChangeCallback ) {
@@ -131,9 +132,9 @@ const KernelUsage = (props: {
131132 }
132133 }
133134 } ;
134- props . currentNotebookChanged . connect ( notebookChangeCallback ) ;
135+ props . currentChanged . connect ( notebookChangeCallback ) ;
135136 return ( ) => {
136- props . currentNotebookChanged . disconnect ( notebookChangeCallback ) ;
137+ props . currentChanged . disconnect ( notebookChangeCallback ) ;
137138 // In the ideal world we would disconnect kernelChangeCallback from
138139 // last panel here, but this can lead to a race condition. Instead,
139140 // we make sure there is ever only one callback active by holding
@@ -239,31 +240,27 @@ const KernelUsage = (props: {
239240} ;
240241
241242export 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
246246 > ;
247247 private _panel : KernelUsagePanel ;
248248 private _trans : TranslationBundle ;
249249 constructor ( props : {
250- widgetAdded : ISignal < INotebookTracker , NotebookPanel | null > ;
251- currentNotebookChanged : ISignal < INotebookTracker , NotebookPanel | null > ;
250+ currentChanged : ISignal < KernelWidgetTracker , IWidgetWithSession | null > ;
252251 panel : KernelUsagePanel ;
253252 trans : TranslationBundle ;
254253 } ) {
255254 super ( ) ;
256- this . _widgetAdded = props . widgetAdded ;
257- this . _currentNotebookChanged = props . currentNotebookChanged ;
255+ this . _currentChanged = props . currentChanged ;
258256 this . _panel = props . panel ;
259257 this . _trans = props . trans ;
260258 }
261259
262260 protected render ( ) : React . ReactElement < any > {
263261 return (
264262 < KernelUsage
265- widgetAdded = { this . _widgetAdded }
266- currentNotebookChanged = { this . _currentNotebookChanged }
263+ currentChanged = { this . _currentChanged }
267264 panel = { this . _panel }
268265 trans = { this . _trans }
269266 />
0 commit comments