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/compute/compute-server-log.tsx
Views: 687
1
/*
2
Show the log entries for a specific compute server.
3
4
More precisely this is a little button that you click on, and
5
it shows the log in a modal.
6
*/
7
8
import { Modal, Button, Spin, Table, Tooltip } from "antd";
9
import { useEffect, useState } from "react";
10
import LogEntry from "./log-entry";
11
import type { ComputeServerEvent } from "@cocalc/util/compute/log";
12
import { TimeAgo } from "@cocalc/frontend/components";
13
import { getLog } from "./api";
14
import { Icon } from "@cocalc/frontend/components";
15
import getTitle from "./get-title";
16
17
export default function ComputeServerLog({
18
id,
19
style,
20
}: {
21
id: number;
22
style?;
23
color?: string;
24
}) {
25
const [open, setOpen] = useState<boolean>(false);
26
27
return (
28
<Tooltip title={"Show configuration and control log"}>
29
<Button
30
size={"small"}
31
type="text"
32
style={{ color: "#666", ...style }}
33
onClick={() => {
34
setOpen(true);
35
}}
36
>
37
<Icon name="history" /> Log
38
</Button>
39
{open && <LogModal id={id} close={() => setOpen(false)} />}
40
</Tooltip>
41
);
42
}
43
44
export function LogModal({ id, close }) {
45
const [log, setLog] = useState<
46
null | { time: Date; project_id: string; event: ComputeServerEvent }[]
47
>(null);
48
const [title, setTitle] = useState<string>("");
49
50
useEffect(() => {
51
(async () => {
52
setLog(await getLog({ id }));
53
setTitle((await getTitle(id)).title);
54
})();
55
}, []);
56
57
return (
58
<Modal
59
width={800}
60
title={
61
<>
62
<Icon name="server" /> Compute Server Log - "{title}"
63
</>
64
}
65
open
66
onCancel={close}
67
onOk={close}
68
>
69
{log == null && <Spin />}
70
{log != null && (
71
<Table dataSource={log} rowKey={(record) => record.time.toString()}>
72
<Table.Column
73
title="Log Entry"
74
render={(record) => (
75
<LogEntry
76
event={record.event}
77
hideTitle
78
project_id={record.project_id}
79
/>
80
)}
81
/>
82
<Table.Column
83
title="Time"
84
render={(record) => <TimeAgo date={record.time} />}
85
/>
86
</Table>
87
)}
88
</Modal>
89
);
90
}
91
92