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/frontend/components/activity-display.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { CSS, React } from "../app-framework";
7
import { is_different_array, len, trunc as trunc_string } from "@cocalc/util/misc";
8
import { Icon } from "./icon";
9
import { CloseX } from "./close-x";
10
11
const ACTIVITY_STYLE = {
12
float: "right",
13
backgroundColor: "white",
14
position: "absolute",
15
right: "25px",
16
top: "65px",
17
border: "1px solid #ccc",
18
padding: "10px",
19
zIndex: 10,
20
borderRadius: "5px",
21
boxShadow: "3px 3px 3px #ccc",
22
} as CSS;
23
24
const ACTIVITY_ITEM_STYLE = {
25
whiteSpace: "nowrap",
26
overflow: "hidden",
27
textOverflow: "ellipsis",
28
} as CSS;
29
30
interface Props {
31
activity: string[]; // only changing this causes re-render
32
trunc?: number; // truncate activity messages at this many characters (default: 80)
33
on_clear?: () => void; // if given, called when a clear button is clicked
34
style?: CSS; // additional styles to be merged onto ACTIVITY_STYLE
35
}
36
37
export const ActivityDisplay: React.FC<Props> = React.memo(
38
({ activity, trunc, on_clear, style }) => {
39
function render_items(): JSX.Element[] {
40
const n = trunc ?? 80;
41
const do_trunc = (s) => trunc_string(s, n);
42
return activity.map((desc, i) => (
43
<div key={i} style={ACTIVITY_ITEM_STYLE}>
44
<Icon
45
style={{ padding: "2px 1px 1px 2px" }}
46
name="cocalc-ring"
47
spin
48
/>{" "}
49
{do_trunc(desc)}
50
</div>
51
));
52
}
53
54
if (len(activity) > 0) {
55
return (
56
<div key="activity" style={{ ...ACTIVITY_STYLE, ...style }}>
57
{on_clear && <CloseX on_close={on_clear} />}
58
{render_items()}
59
</div>
60
);
61
} else {
62
return <></>;
63
}
64
},
65
(prev, next) => !is_different_array(prev.activity, next.activity)
66
);
67
68