@@ -6,6 +6,9 @@ import useRefreshNotebookUntilStart from './useRefreshNotebookUntilStart';
6
6
import StopNotebookConfirmModal from './StopNotebookConfirmModal' ;
7
7
import useStopNotebookModalAvailability from './useStopNotebookModalAvailability' ;
8
8
import NotebookStatusText from './NotebookStatusText' ;
9
+ import { fireTrackingEvent } from '../../../utilities/segmentIOUtils' ;
10
+ import useNotebookGPUNumber from '../screens/detail/notebooks/useNotebookGPUNumber' ;
11
+ import useNotebookDeploymentSize from '../screens/detail/notebooks/useNotebookDeploymentSize' ;
9
12
10
13
type NotebookStatusToggleProps = {
11
14
notebookState : NotebookState ;
@@ -14,6 +17,8 @@ type NotebookStatusToggleProps = {
14
17
15
18
const NotebookStatusToggle : React . FC < NotebookStatusToggleProps > = ( { notebookState, doListen } ) => {
16
19
const { notebook, isStarting, isRunning, refresh } = notebookState ;
20
+ const gpuNumber = useNotebookGPUNumber ( notebook ) ;
21
+ const { size } = useNotebookDeploymentSize ( notebook ) ;
17
22
const [ isOpenConfirm , setOpenConfirm ] = React . useState ( false ) ;
18
23
const [ inProgress , setInProgress ] = React . useState ( false ) ;
19
24
const listenToNotebookStart = useRefreshNotebookUntilStart ( notebookState , doListen ) ;
@@ -34,13 +39,33 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({ notebookSta
34
39
label = isRunning ? 'Running' : 'Stopped' ;
35
40
}
36
41
42
+ const fireNotebookTrackingEvent = React . useCallback (
43
+ ( action : 'started' | 'stopped' ) => {
44
+ fireTrackingEvent ( `Workbench ${ action } ` , {
45
+ GPU : gpuNumber ,
46
+ lastSelectedSize :
47
+ size ?. name ||
48
+ notebook . metadata . annotations ?. [ 'notebooks.opendatahub.io/last-size-selection' ] ,
49
+ lastSelectedImage :
50
+ notebook . metadata . annotations ?. [ 'notebooks.opendatahub.io/last-image-selection' ] ,
51
+ projectName : notebook . metadata . namespace ,
52
+ notebookName : notebook . metadata . name ,
53
+ ...( action === 'stopped' && {
54
+ lastActivity : notebook . metadata . annotations ?. [ 'notebooks.kubeflow.org/last-activity' ] ,
55
+ } ) ,
56
+ } ) ;
57
+ } ,
58
+ [ gpuNumber , notebook , size ] ,
59
+ ) ;
60
+
37
61
const handleStop = React . useCallback ( ( ) => {
62
+ fireNotebookTrackingEvent ( 'stopped' ) ;
38
63
setInProgress ( true ) ;
39
64
stopNotebook ( notebookName , notebookNamespace ) . then ( ( ) => {
40
65
refresh ( ) . then ( ( ) => setInProgress ( false ) ) ;
41
66
listenToNotebookStart ( false ) ;
42
67
} ) ;
43
- } , [ notebookName , notebookNamespace , refresh , listenToNotebookStart ] ) ;
68
+ } , [ notebookName , notebookNamespace , refresh , listenToNotebookStart , fireNotebookTrackingEvent ] ) ;
44
69
45
70
return (
46
71
< >
@@ -61,6 +86,7 @@ const NotebookStatusToggle: React.FC<NotebookStatusToggleProps> = ({ notebookSta
61
86
} else {
62
87
setInProgress ( true ) ;
63
88
startNotebook ( notebookName , notebookNamespace ) . then ( ( ) => {
89
+ fireNotebookTrackingEvent ( 'started' ) ;
64
90
refresh ( ) . then ( ( ) => setInProgress ( false ) ) ;
65
91
listenToNotebookStart ( true ) ;
66
92
} ) ;
0 commit comments