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/compute/log-entry.tsx
Views: 687
import type { ComputeServerEvent } from "@cocalc/util/compute/log";1import { useTypedRedux } from "@cocalc/frontend/app-framework";2import { capitalize, plural } from "@cocalc/util/misc";3import { STATE_INFO } from "@cocalc/util/db-schema/compute-servers";4import { Icon } from "@cocalc/frontend/components";5import ComputeServerTag from "@cocalc/frontend/compute/server-tag";67export default function LogEntry({8project_id,9event,10hideTitle,11}: {12project_id: string;13event: ComputeServerEvent;14hideTitle?: boolean;15}) {16const computeServers = useTypedRedux({ project_id }, "compute_servers");17const title = computeServers?.getIn([`${event.server_id}`, "title"]);18if (title == null) {19return null;20}21const cs = hideTitle ? <></> : <>Compute Server "{title}" - </>;22const tag = (23<ComputeServerTag24id={event.server_id}25style={{ float: "right", maxWidth: "125px" }}26/>27);2829switch (event.action) {30case "error":31return (32<>33{cs} <Error error={event.error} />34{tag}35</>36);37case "state":38if (!STATE_INFO[event.state]) {39return null;40}41const { color, icon } = STATE_INFO[event.state];42return (43<>44<span style={{ color }}>45<Icon name={icon} /> {capitalize(event.state)}46</span>{" "}47{cs}48{tag}49</>50);51case "configuration":52return (53<>54{cs} Configuration{" "}55{plural(Object.keys(event.changes).length, "change")} -{" "}56{changeString(event.changes)}57{tag}58</>59);60case "automatic-shutdown":61return (62<>63{cs} - Automatic {capitalize(event.automatic_shutdown?.action ?? "Stop")}{" "}64{tag}65</>66);67default:68return (69<>70{cs} {JSON.stringify(event)}71{tag}72</>73);74}75}7677function changeString(changes) {78let v: string[] = [];79for (const key in changes) {80const { from, to } = changes[key];81v.push(`${key}: ${JSON.stringify(from)} → ${JSON.stringify(to)}`);82}83if (v.length == 0) {84return "(no change)";85}86return v.join("; ");87}8889export function Error({ error, style }: { error; style? }) {90return (91<div92style={{93border: "0px 5px",94display: "inline-block",95color: "white",96background: "darkred",97padding: "1px 5px",98borderRadius: "3px",99...style,100}}101>102{error}103</div>104);105}106107108