1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
import { Action, PageTable } from "@/components";
import { useModals } from "@/modules/modals";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import {
faBug,
faCode,
faExclamationCircle,
faInfoCircle,
faLayerGroup,
faQuestion,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { FunctionComponent, useMemo } from "react";
import { Column } from "react-table";
import SystemLogModal from "./modal";
interface Props {
logs: readonly System.Log[];
}
function mapTypeToIcon(type: System.LogType): IconDefinition {
switch (type) {
case "DEBUG":
return faCode;
case "ERROR":
return faBug;
case "INFO":
return faInfoCircle;
case "WARNING":
return faExclamationCircle;
default:
return faQuestion;
}
}
const Table: FunctionComponent<Props> = ({ logs }) => {
const columns: Column<System.Log>[] = useMemo<Column<System.Log>[]>(
() => [
{
accessor: "type",
Cell: (row) => (
<FontAwesomeIcon icon={mapTypeToIcon(row.value)}></FontAwesomeIcon>
),
},
{
Header: "Message",
accessor: "message",
},
{
Header: "Date",
accessor: "timestamp",
},
{
accessor: "exception",
Cell: ({ value }) => {
const modals = useModals();
if (value) {
return (
<Action
label="Detail"
icon={faLayerGroup}
onClick={() =>
modals.openContextModal(SystemLogModal, { stack: value })
}
></Action>
);
} else {
return null;
}
},
},
],
[],
);
return (
<>
<PageTable columns={columns} data={logs}></PageTable>
</>
);
};
export default Table;
|