Skip to content

Commit addd2bf

Browse files
committed
Started activity graph
1 parent a8c162d commit addd2bf

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

packages/collaboration-extension/src/collaboration.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { Menu, MenuBar } from '@lumino/widgets';
2626
import { IAwareness } from '@jupyter/ydoc';
2727

2828
import {
29+
ActivityDisplay,
2930
addDisplay,
3031
Chatbox,
3132
CollaboratorsPanel,
@@ -138,11 +139,12 @@ export const rtcPanelPlugin: JupyterFrontEndPlugin<void> = {
138139
id: '@jupyter/collaboration-extension:rtcPanel',
139140
description: 'Add side panel to display all currently connected users.',
140141
autoStart: true,
141-
requires: [IGlobalAwareness],
142+
requires: [IGlobalAwareness, INotebookTracker],
142143
optional: [ITranslator],
143144
activate: (
144145
app: JupyterFrontEnd,
145146
awareness: Awareness,
147+
tracker: INotebookTracker,
146148
translator: ITranslator | null
147149
): void => {
148150

@@ -179,6 +181,10 @@ export const rtcPanelPlugin: JupyterFrontEndPlugin<void> = {
179181
collaboratorsPanel.title.label = trans.__('Online Collaborators');
180182
userPanel.addWidget(collaboratorsPanel);
181183

184+
const activityDisplay = new ActivityDisplay(tracker);
185+
activityDisplay.title.label = trans.__('User activity');
186+
userPanel.addWidget(activityDisplay);
187+
182188

183189
const chatPanel = new SidePanel({
184190
alignment: 'justify'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import * as React from 'react';
2+
import { ReactWidget } from '@jupyterlab/apputils';
3+
import { INotebookTracker, Notebook, NotebookPanel } from '@jupyterlab/notebook';
4+
5+
export class ActivityDisplay extends ReactWidget {
6+
7+
private _tracker: INotebookTracker
8+
9+
constructor(tracker: INotebookTracker) {
10+
11+
super();
12+
13+
this._tracker = tracker;
14+
15+
}
16+
17+
render() {
18+
return <ActivityDisplayComponent tracker={this._tracker}/>
19+
}
20+
21+
}
22+
23+
24+
interface ActivityDisplayComponentProps {
25+
26+
tracker: INotebookTracker;
27+
28+
}
29+
30+
const ActivityDisplayComponent: React.FC<ActivityDisplayComponentProps> = ({tracker}) => {
31+
32+
const [state, setState] = React.useState<number[]>([]);
33+
34+
React.useEffect(() => {
35+
36+
const updateCounts = (notebook: Notebook) => {
37+
38+
const counts = notebook.widgets.map(cell => {
39+
return cell.model.getMetadata('active_users') || 0;
40+
});
41+
42+
setState(counts);
43+
44+
}
45+
46+
const startTracking = (_: any, panel: NotebookPanel) => {
47+
48+
const notebook = panel.content;
49+
50+
notebook.model?.cells.changed.connect(() => {
51+
52+
updateCounts(notebook);
53+
54+
notebook.widgets.forEach(cell => {
55+
cell.model.metadataChanged.connect(() => {
56+
updateCounts(notebook);
57+
})
58+
})
59+
60+
})
61+
62+
}
63+
64+
tracker.widgetAdded.connect(startTracking);
65+
66+
return () => {
67+
tracker.widgetAdded.disconnect(startTracking);
68+
}
69+
70+
}, [tracker]);
71+
72+
const graph = state.map((count, index) => (
73+
<div key={index} style={{height: '8px', width: count*5, backgroundColor: 'green', margin: '2px'}}/>
74+
))
75+
76+
return <div>{graph}</div>;
77+
78+
}

packages/collaboration/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export * from './messageEncoding';
1616
export * from './polls';
1717
export * from './roles';
1818
export * from './cellTracker';
19-
export * from './activeusersdisplay';
19+
export * from './activeusersdisplay';
20+
export * from './activitydisplay';

0 commit comments

Comments
 (0)