2023-09-14 17:12:49 +05:30
|
|
|
import { orange } from '@ant-design/colors';
|
2023-05-18 12:36:02 +05:30
|
|
|
import { LinkOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Input, Space, Tooltip } from 'antd';
|
2023-03-17 15:21:02 +05:30
|
|
|
import { ColumnsType } from 'antd/es/table';
|
|
|
|
|
import Editor from 'components/Editor';
|
2023-07-11 16:53:15 +03:00
|
|
|
import AddToQueryHOC, {
|
|
|
|
|
AddToQueryHOCProps,
|
|
|
|
|
} from 'components/Logs/AddToQueryHOC';
|
2022-08-11 11:45:28 +05:30
|
|
|
import CopyClipboardHOC from 'components/Logs/CopyClipboardHOC';
|
2023-02-03 18:06:26 +05:30
|
|
|
import { ResizeTable } from 'components/ResizeTable';
|
2023-05-18 12:36:02 +05:30
|
|
|
import ROUTES from 'constants/routes';
|
|
|
|
|
import history from 'lib/history';
|
2022-08-11 11:45:28 +05:30
|
|
|
import { fieldSearchFilter } from 'lib/logs/fieldSearch';
|
2023-03-17 15:21:02 +05:30
|
|
|
import { isEmpty } from 'lodash-es';
|
2023-05-19 13:14:32 +05:30
|
|
|
import { useMemo, useState } from 'react';
|
2023-05-18 12:36:02 +05:30
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
import { generatePath } from 'react-router-dom';
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
import AppActions from 'types/actions';
|
|
|
|
|
import { SET_DETAILED_LOG_DATA } from 'types/actions/logs';
|
2022-08-19 17:16:04 +05:30
|
|
|
import { ILog } from 'types/api/logs/log';
|
2022-08-11 11:45:28 +05:30
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
import ActionItem, { ActionItemProps } from './ActionItem';
|
2023-09-14 17:12:49 +05:30
|
|
|
import FieldRenderer from './FieldRenderer';
|
2023-05-19 17:42:20 +05:30
|
|
|
import { flattenObject, recursiveParseJSON } from './utils';
|
2022-08-11 11:45:28 +05:30
|
|
|
|
2022-08-16 18:53:34 +05:30
|
|
|
// Fields which should be restricted from adding it to query
|
|
|
|
|
const RESTRICTED_FIELDS = ['timestamp'];
|
|
|
|
|
|
2022-08-19 17:16:04 +05:30
|
|
|
interface TableViewProps {
|
|
|
|
|
logData: ILog;
|
|
|
|
|
}
|
2023-07-11 16:53:15 +03:00
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
type Props = TableViewProps &
|
|
|
|
|
Pick<AddToQueryHOCProps, 'onAddToQuery'> &
|
|
|
|
|
Pick<ActionItemProps, 'onClickActionItem'>;
|
2023-07-11 16:53:15 +03:00
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
function TableView({
|
|
|
|
|
logData,
|
|
|
|
|
onAddToQuery,
|
|
|
|
|
onClickActionItem,
|
|
|
|
|
}: Props): JSX.Element | null {
|
2022-08-11 11:45:28 +05:30
|
|
|
const [fieldSearchInput, setFieldSearchInput] = useState<string>('');
|
|
|
|
|
|
2023-05-18 12:36:02 +05:30
|
|
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
|
|
|
|
|
2023-06-19 15:57:58 +03:00
|
|
|
const flattenLogData: Record<string, string> | null = useMemo(
|
2023-05-19 17:42:20 +05:30
|
|
|
() => (logData ? flattenObject(logData) : null),
|
2022-08-19 17:16:04 +05:30
|
|
|
[logData],
|
|
|
|
|
);
|
2022-08-11 11:45:28 +05:30
|
|
|
if (logData === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 17:16:04 +05:30
|
|
|
const dataSource =
|
|
|
|
|
flattenLogData !== null &&
|
|
|
|
|
Object.keys(flattenLogData)
|
|
|
|
|
.filter((field) => fieldSearchFilter(field, fieldSearchInput))
|
2023-01-24 18:53:04 +05:30
|
|
|
.map((key) => ({
|
|
|
|
|
key,
|
|
|
|
|
field: key,
|
|
|
|
|
value: JSON.stringify(flattenLogData[key]),
|
|
|
|
|
}));
|
2022-08-19 17:16:04 +05:30
|
|
|
|
2023-05-18 12:36:02 +05:30
|
|
|
const onTraceHandler = (record: DataType) => (): void => {
|
|
|
|
|
if (flattenLogData === null) return;
|
|
|
|
|
|
|
|
|
|
const traceId = flattenLogData[record.field];
|
|
|
|
|
|
|
|
|
|
const spanId = flattenLogData?.span_id;
|
|
|
|
|
|
|
|
|
|
if (traceId) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SET_DETAILED_LOG_DATA,
|
|
|
|
|
payload: null,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const basePath = generatePath(ROUTES.TRACE_DETAIL, {
|
|
|
|
|
id: traceId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const route = spanId ? `${basePath}?spanId=${spanId}` : basePath;
|
|
|
|
|
|
|
|
|
|
history.push(route);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-19 17:16:04 +05:30
|
|
|
if (!dataSource) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-08-11 11:45:28 +05:30
|
|
|
|
2023-03-17 15:21:02 +05:30
|
|
|
const columns: ColumnsType<DataType> = [
|
2022-08-11 11:45:28 +05:30
|
|
|
{
|
|
|
|
|
title: 'Action',
|
2023-09-14 17:12:49 +05:30
|
|
|
width: 11,
|
2022-08-19 17:16:04 +05:30
|
|
|
render: (fieldData: Record<string, string>): JSX.Element | null => {
|
2022-08-16 18:53:34 +05:30
|
|
|
const fieldKey = fieldData.field.split('.').slice(-1);
|
|
|
|
|
if (!RESTRICTED_FIELDS.includes(fieldKey[0])) {
|
2023-07-13 15:55:43 +03:00
|
|
|
return (
|
|
|
|
|
<ActionItem
|
|
|
|
|
fieldKey={fieldKey[0]}
|
|
|
|
|
fieldValue={fieldData.value}
|
|
|
|
|
onClickActionItem={onClickActionItem}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-08-16 18:53:34 +05:30
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
2022-08-11 11:45:28 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Field',
|
|
|
|
|
dataIndex: 'field',
|
|
|
|
|
key: 'field',
|
2023-09-14 17:12:49 +05:30
|
|
|
width: 50,
|
2023-05-18 12:36:02 +05:30
|
|
|
align: 'left',
|
2023-03-17 15:21:02 +05:30
|
|
|
ellipsis: true,
|
2023-05-18 12:36:02 +05:30
|
|
|
render: (field: string, record): JSX.Element => {
|
2022-08-16 18:53:34 +05:30
|
|
|
const fieldKey = field.split('.').slice(-1);
|
2023-09-14 17:12:49 +05:30
|
|
|
const renderedField = <FieldRenderer field={field} />;
|
2022-08-16 18:53:34 +05:30
|
|
|
|
2023-05-18 12:36:02 +05:30
|
|
|
if (record.field === 'trace_id') {
|
|
|
|
|
const traceId = flattenLogData[record.field];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Space size="middle">
|
|
|
|
|
{renderedField}
|
|
|
|
|
|
|
|
|
|
{traceId && (
|
|
|
|
|
<Tooltip title="Inspect in Trace">
|
|
|
|
|
<div
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
role="presentation"
|
|
|
|
|
onClick={onTraceHandler(record)}
|
|
|
|
|
>
|
|
|
|
|
<LinkOutlined
|
|
|
|
|
style={{
|
|
|
|
|
width: '15px',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</Space>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-16 18:53:34 +05:30
|
|
|
if (!RESTRICTED_FIELDS.includes(fieldKey[0])) {
|
|
|
|
|
return (
|
2023-07-11 16:53:15 +03:00
|
|
|
<AddToQueryHOC
|
|
|
|
|
fieldKey={fieldKey[0]}
|
|
|
|
|
fieldValue={flattenLogData[field]}
|
|
|
|
|
onAddToQuery={onAddToQuery}
|
|
|
|
|
>
|
2022-08-16 18:53:34 +05:30
|
|
|
{renderedField}
|
|
|
|
|
</AddToQueryHOC>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return renderedField;
|
|
|
|
|
},
|
2022-08-11 11:45:28 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Value',
|
|
|
|
|
dataIndex: 'value',
|
|
|
|
|
key: 'value',
|
2023-09-14 17:12:49 +05:30
|
|
|
width: 70,
|
2022-08-11 11:45:28 +05:30
|
|
|
ellipsis: false,
|
2023-03-17 15:21:02 +05:30
|
|
|
render: (field, record): JSX.Element => {
|
|
|
|
|
if (record.field === 'body') {
|
|
|
|
|
const parsedBody = recursiveParseJSON(field);
|
|
|
|
|
if (!isEmpty(parsedBody)) {
|
|
|
|
|
return (
|
|
|
|
|
<Editor
|
2023-05-15 18:04:58 +05:30
|
|
|
value={JSON.stringify(parsedBody, null, 2).replace(/\\n/g, '\n')}
|
2023-03-17 15:21:02 +05:30
|
|
|
readOnly
|
|
|
|
|
height="70vh"
|
|
|
|
|
options={{
|
|
|
|
|
minimap: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CopyClipboardHOC textToCopy={field}>
|
|
|
|
|
<span style={{ color: orange[6] }}>{field}</span>
|
|
|
|
|
</CopyClipboardHOC>
|
|
|
|
|
);
|
|
|
|
|
},
|
2022-08-11 11:45:28 +05:30
|
|
|
},
|
|
|
|
|
];
|
2023-02-02 16:53:15 +05:30
|
|
|
|
2022-08-11 11:45:28 +05:30
|
|
|
return (
|
2023-03-17 15:21:02 +05:30
|
|
|
<>
|
2022-08-11 11:45:28 +05:30
|
|
|
<Input
|
|
|
|
|
placeholder="Search field names"
|
|
|
|
|
size="large"
|
|
|
|
|
value={fieldSearchInput}
|
2022-08-19 17:16:04 +05:30
|
|
|
onChange={(e): void => setFieldSearchInput(e.target.value)}
|
2022-08-11 11:45:28 +05:30
|
|
|
/>
|
2023-02-03 18:06:26 +05:30
|
|
|
<ResizeTable
|
2023-03-17 15:21:02 +05:30
|
|
|
columns={columns}
|
2023-02-03 18:06:26 +05:30
|
|
|
tableLayout="fixed"
|
|
|
|
|
dataSource={dataSource}
|
|
|
|
|
pagination={false}
|
|
|
|
|
/>
|
2023-03-17 15:21:02 +05:30
|
|
|
</>
|
2022-08-11 11:45:28 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 15:21:02 +05:30
|
|
|
interface DataType {
|
|
|
|
|
key: string;
|
|
|
|
|
field: string;
|
|
|
|
|
value: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-11 11:45:28 +05:30
|
|
|
export default TableView;
|