mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-10 07:36:30 +08:00

* feat: add list and table views for logs * chore: some of the changes are updated * chore: some of the refactoring is done * chore: px to updated to rem * chore: constant is moved to local storage * refactor: some of the refactoring is updated * chore: some of the changes are updated * fix: resize log table issue * chore: logs is updated * chore: resize header is updated * chore: font observer is added in package json and hook is added for same * chore: no logs text is updated * chore: no logs text is updated * chore: updated some feedback in raw logs line * chore: types is added --------- Co-authored-by: Palash Gupta <palashgdev@gmail.com> Co-authored-by: Pranay Prateek <pranay@signoz.io> Co-authored-by: Vishal Sharma <makeavish786@gmail.com> Co-authored-by: Chintan Sudani <csudani7@gmail.com>
107 lines
2.5 KiB
TypeScript
107 lines
2.5 KiB
TypeScript
import { ExpandAltOutlined } from '@ant-design/icons';
|
|
import { Table, Typography } from 'antd';
|
|
import { ColumnsType, ColumnType } from 'antd/es/table';
|
|
import dayjs from 'dayjs';
|
|
// utils
|
|
import { FlatLogData } from 'lib/logs/flatLogData';
|
|
import React, { useMemo } from 'react';
|
|
import { IField } from 'types/api/logs/fields';
|
|
// interfaces
|
|
import { ILog } from 'types/api/logs/log';
|
|
|
|
// styles
|
|
import { ExpandIconWrapper } from '../RawLogView/styles';
|
|
// config
|
|
import { defaultCellStyle, tableScroll } from './config';
|
|
|
|
type ColumnTypeRender<T = unknown> = ReturnType<
|
|
NonNullable<ColumnType<T>['render']>
|
|
>;
|
|
|
|
type LogsTableViewProps = {
|
|
logs: ILog[];
|
|
fields: IField[];
|
|
linesPerRow: number;
|
|
onClickExpand: (log: ILog) => void;
|
|
};
|
|
|
|
function LogsTableView(props: LogsTableViewProps): JSX.Element {
|
|
const { logs, fields, linesPerRow, onClickExpand } = props;
|
|
|
|
const flattenLogData = useMemo(() => logs.map((log) => FlatLogData(log)), [
|
|
logs,
|
|
]);
|
|
|
|
const columns: ColumnsType<Record<string, unknown>> = useMemo(() => {
|
|
const fieldColumns: ColumnsType<Record<string, unknown>> = fields.map(
|
|
({ name }) => ({
|
|
title: name,
|
|
dataIndex: name,
|
|
key: name,
|
|
render: (field): ColumnTypeRender<Record<string, unknown>> => ({
|
|
props: {
|
|
style: defaultCellStyle,
|
|
},
|
|
children: (
|
|
<Typography.Paragraph ellipsis={{ rows: linesPerRow }}>
|
|
{field}
|
|
</Typography.Paragraph>
|
|
),
|
|
}),
|
|
}),
|
|
);
|
|
|
|
return [
|
|
{
|
|
title: '',
|
|
dataIndex: 'id',
|
|
key: 'expand',
|
|
// https://github.com/ant-design/ant-design/discussions/36886
|
|
render: (_, item): ColumnTypeRender<Record<string, unknown>> => ({
|
|
props: {
|
|
style: defaultCellStyle,
|
|
},
|
|
children: (
|
|
<ExpandIconWrapper
|
|
onClick={(): void => {
|
|
onClickExpand((item as unknown) as ILog);
|
|
}}
|
|
>
|
|
<ExpandAltOutlined />
|
|
</ExpandIconWrapper>
|
|
),
|
|
}),
|
|
},
|
|
{
|
|
title: 'Timestamp',
|
|
dataIndex: 'timestamp',
|
|
key: 'timestamp',
|
|
// https://github.com/ant-design/ant-design/discussions/36886
|
|
render: (field): ColumnTypeRender<Record<string, unknown>> => {
|
|
const date = dayjs(field / 1e6).format();
|
|
return {
|
|
props: {
|
|
style: defaultCellStyle,
|
|
},
|
|
children: <span>{date}</span>,
|
|
};
|
|
},
|
|
},
|
|
...fieldColumns,
|
|
];
|
|
}, [fields, linesPerRow, onClickExpand]);
|
|
|
|
return (
|
|
<Table
|
|
columns={columns}
|
|
dataSource={flattenLogData}
|
|
pagination={false}
|
|
rowKey="id"
|
|
bordered
|
|
scroll={tableScroll}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default LogsTableView;
|