CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/statistics/active-users.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Table } from "antd";
7
8
import { HistoricCounts } from "@cocalc/util/db-schema/stats";
9
import { Paragraph, Title } from "components/misc";
10
import { ZEROS } from "./misc";
11
12
interface Props {
13
active: HistoricCounts;
14
created: HistoricCounts;
15
hubServers: { host: string; clients: number }[];
16
style?: React.CSSProperties;
17
}
18
19
const columns = [
20
{ title: "Accounts", dataIndex: "type", key: "type" },
21
{ title: "Hour", dataIndex: "1h", key: "1h" },
22
{ title: "Day", dataIndex: "1d", key: "1d" },
23
{ title: "Week", dataIndex: "7d", key: "7d" },
24
{ title: "Month", dataIndex: "30d", key: "30d" },
25
];
26
27
function connectedUsers(hubServers): number {
28
if (hubServers == null || hubServers.length === 0) {
29
return 0;
30
} else {
31
return hubServers.map((x) => x.clients).reduce((s, t) => s + t);
32
}
33
}
34
35
export default function ActiveUsers({
36
created,
37
active,
38
hubServers,
39
style,
40
}: Props) {
41
const rows = [
42
{ type: "In use", ...ZEROS, ...active },
43
{ type: "Created", ...ZEROS, ...created },
44
];
45
return (
46
<div style={style}>
47
<Title level={2}>Connected Users: {connectedUsers(hubServers)}</Title>
48
<Paragraph>
49
There are {connectedUsers(hubServers)} users connected right now; of
50
these {active["5min"]} actively edited a file in the last 5 minutes.
51
Track the number of users that were recently active or created new
52
accounts below.
53
</Paragraph>
54
55
<Table
56
dataSource={rows}
57
columns={columns}
58
bordered
59
pagination={false}
60
rowKey={"type"}
61
/>
62
</div>
63
);
64
}
65
66