Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/components/activity-display.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { CSS, React } from "../app-framework";6import { is_different_array, len, trunc as trunc_string } from "@cocalc/util/misc";7import { Icon } from "./icon";8import { CloseX } from "./close-x";910const ACTIVITY_STYLE = {11float: "right",12backgroundColor: "white",13position: "absolute",14right: "25px",15top: "65px",16border: "1px solid #ccc",17padding: "10px",18zIndex: 10,19borderRadius: "5px",20boxShadow: "3px 3px 3px #ccc",21} as CSS;2223const ACTIVITY_ITEM_STYLE = {24whiteSpace: "nowrap",25overflow: "hidden",26textOverflow: "ellipsis",27} as CSS;2829interface Props {30activity: string[]; // only changing this causes re-render31trunc?: number; // truncate activity messages at this many characters (default: 80)32on_clear?: () => void; // if given, called when a clear button is clicked33style?: CSS; // additional styles to be merged onto ACTIVITY_STYLE34}3536export const ActivityDisplay: React.FC<Props> = React.memo(37({ activity, trunc, on_clear, style }) => {38function render_items(): JSX.Element[] {39const n = trunc ?? 80;40const do_trunc = (s) => trunc_string(s, n);41return activity.map((desc, i) => (42<div key={i} style={ACTIVITY_ITEM_STYLE}>43<Icon44style={{ padding: "2px 1px 1px 2px" }}45name="cocalc-ring"46spin47/>{" "}48{do_trunc(desc)}49</div>50));51}5253if (len(activity) > 0) {54return (55<div key="activity" style={{ ...ACTIVITY_STYLE, ...style }}>56{on_clear && <CloseX on_close={on_clear} />}57{render_items()}58</div>59);60} else {61return <></>;62}63},64(prev, next) => !is_different_array(prev.activity, next.activity)65);666768