2020-10-30 02:01:38 +01:00
|
|
|
import React from "react";
|
|
|
|
import { timeFormat } from "d3-time-format";
|
2020-11-03 02:23:32 +01:00
|
|
|
import { Table, Tag} from "antd";
|
2020-10-30 02:01:38 +01:00
|
|
|
import Linkify from "react-linkify";
|
2020-11-01 07:17:44 +01:00
|
|
|
import { SortOrder } from "antd/lib/table/interface";
|
|
|
|
|
|
|
|
function renderColumnLevel(text, entry) {
|
|
|
|
let color = 'black';
|
|
|
|
|
|
|
|
if (entry.level === "warning") {
|
|
|
|
color = "orange";
|
|
|
|
} else if (entry.level === 'error') {
|
|
|
|
color = "red";
|
|
|
|
}
|
|
|
|
|
2020-11-03 02:23:32 +01:00
|
|
|
return <Tag color={color}>{text}</Tag>;
|
2020-11-01 07:17:44 +01:00
|
|
|
}
|
|
|
|
|
2020-11-01 08:01:37 +01:00
|
|
|
function renderMessage(text) {
|
2020-11-01 07:17:44 +01:00
|
|
|
return (
|
|
|
|
<Linkify>{text}</Linkify>
|
|
|
|
)
|
|
|
|
}
|
2020-10-30 02:01:38 +01:00
|
|
|
|
2020-11-01 08:01:37 +01:00
|
|
|
interface Props {
|
|
|
|
logs: object[],
|
|
|
|
pageSize: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function LogTable({ logs, pageSize }: Props) {
|
2020-10-30 02:01:38 +01:00
|
|
|
const columns = [
|
|
|
|
{
|
|
|
|
title: "Level",
|
|
|
|
dataIndex: "level",
|
|
|
|
key: "level",
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
text: "Info",
|
|
|
|
value: "info",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Warning",
|
|
|
|
value: "warning",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Error",
|
|
|
|
value: "Error",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
onFilter: (level, row) => row.level.indexOf(level) === 0,
|
|
|
|
render: renderColumnLevel,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Timestamp",
|
|
|
|
dataIndex: "time",
|
|
|
|
key: "time",
|
|
|
|
render: (timestamp) =>
|
|
|
|
timeFormat("%H:%M:%S %m/%d/%Y")(new Date(timestamp)),
|
|
|
|
sorter: (a, b) => new Date(a.time).getTime() - new Date(b.time).getTime(),
|
2020-11-01 07:17:44 +01:00
|
|
|
sortDirections: ["descend", "ascend"] as SortOrder[],
|
|
|
|
defaultSortOrder: "descend" as SortOrder,
|
2020-10-30 02:01:38 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Message",
|
|
|
|
dataIndex: "message",
|
|
|
|
key: "message",
|
|
|
|
render: renderMessage,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Table
|
2020-11-01 03:29:06 +01:00
|
|
|
size="middle"
|
2020-10-30 02:01:38 +01:00
|
|
|
dataSource={logs}
|
|
|
|
columns={columns}
|
|
|
|
rowKey={(row) => row.time}
|
|
|
|
pagination={{ pageSize: pageSize || 20 }}
|
|
|
|
/>
|
|
|
|
;
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|