1
1
import { ReactWidget } from '@jupyterlab/apputils' ;
2
- import { INotebookTracker , Notebook , NotebookPanel } from '@jupyterlab/notebook' ;
2
+ import { INotebookTracker } from '@jupyterlab/notebook' ;
3
3
import { User } from '@jupyterlab/services' ;
4
4
5
5
import * as React from 'react' ;
6
- import Plot from 'react-plotly.js' ;
7
6
8
- import { Roles , Role } from './roles' ;
7
+ import { ActivityBarGraph } from './activitybargraph' ;
8
+ import { Roles } from './roles' ;
9
9
10
10
11
11
export class ActivityDisplay extends ReactWidget {
@@ -25,98 +25,7 @@ export class ActivityDisplay extends ReactWidget {
25
25
}
26
26
27
27
render ( ) {
28
- return < ActivityDisplayComponent tracker = { this . _tracker } currentUser = { this . _currentUser } userRoles = { this . _roles } />
28
+ return < ActivityBarGraph tracker = { this . _tracker } currentUser = { this . _currentUser } userRoles = { this . _roles } />
29
29
}
30
30
31
31
}
32
-
33
-
34
- interface ActivityDisplayComponentProps {
35
-
36
- tracker : INotebookTracker ;
37
- currentUser : User . IManager ;
38
- userRoles : Roles
39
-
40
- }
41
-
42
- const ActivityDisplayComponent : React . FC < ActivityDisplayComponentProps > = ( { tracker, currentUser, userRoles} ) => {
43
-
44
- const user = currentUser ;
45
- const roles = userRoles ;
46
-
47
- const [ state , setState ] = React . useState < number [ ] > ( [ ] ) ;
48
-
49
- React . useEffect ( ( ) => {
50
-
51
- const updateCounts = ( notebook : Notebook ) => {
52
-
53
- const counts = notebook . widgets . map ( cell => {
54
- let activeUsers = cell . model . getMetadata ( 'active_users' ) ;
55
- if ( ! activeUsers || ! Array . isArray ( activeUsers ) ) return 0 ;
56
- return activeUsers . length ;
57
- } ) ;
58
-
59
- setState ( counts ) ;
60
-
61
- }
62
-
63
- const startTracking = ( _ : any , panel : NotebookPanel ) => {
64
-
65
- const notebook = panel . content ;
66
-
67
- notebook . model ?. cells . changed . connect ( ( ) => {
68
-
69
- updateCounts ( notebook ) ;
70
-
71
- notebook . widgets . forEach ( cell => {
72
- cell . model . metadataChanged . connect ( ( ) => {
73
- updateCounts ( notebook ) ;
74
- } )
75
- } )
76
-
77
- } )
78
-
79
- }
80
-
81
- tracker . widgetAdded . connect ( startTracking ) ;
82
-
83
- return ( ) => {
84
- tracker . widgetAdded . disconnect ( startTracking ) ;
85
- }
86
-
87
- } , [ tracker ] ) ;
88
-
89
- const data = [ {
90
- y : state . map ( ( _ , index ) => index + 1 ) ,
91
- x : state ,
92
- type : 'bar' ,
93
- orientation : 'h' ,
94
- marker : { color : 'green' } ,
95
- hovertemplate : '%{x} user(s) on cell %{y}<extra></extra>'
96
- } ] as Plotly . Data [ ] ;
97
-
98
- const layout = {
99
- width : 300 ,
100
- height : 500 ,
101
- xaxis : {
102
- title : 'Active users'
103
- } ,
104
- yaxis : {
105
- title : 'Cell' ,
106
- autorange : 'reversed' as const
107
- } ,
108
- margin : {
109
- l : 60 ,
110
- r : 30 ,
111
- t : 30 ,
112
- b : 60
113
- }
114
- } ;
115
-
116
- return < div >
117
- { roles . get ( user . identity ! . username ) === Role . Owner && (
118
- < Plot className = 'jp-graph' data = { data } layout = { layout } />
119
- ) }
120
- </ div >
121
-
122
- }
0 commit comments