2024-02-12 00:23:19 +05:30
|
|
|
import './TableView.styles.scss';
|
|
|
|
|
|
2023-05-18 12:36:02 +05:30
|
|
|
import { LinkOutlined } from '@ant-design/icons';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { Color } from '@signozhq/design-tokens';
|
|
|
|
|
import { Button, Space, Spin, Tooltip, Tree, Typography } from 'antd';
|
2023-03-17 15:21:02 +05:30
|
|
|
import { ColumnsType } from 'antd/es/table';
|
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';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { OPERATORS } from 'constants/queryBuilder';
|
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';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { removeJSONStringifyQuotes } from 'lib/removeJSONStringifyQuotes';
|
2023-03-17 15:21:02 +05:30
|
|
|
import { isEmpty } from 'lodash-es';
|
2024-02-12 00:23:19 +05:30
|
|
|
import { ArrowDownToDot, ArrowUpFromDot } from 'lucide-react';
|
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
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
import { ActionItemProps } from './ActionItem';
|
2023-09-14 17:12:49 +05:30
|
|
|
import FieldRenderer from './FieldRenderer';
|
2023-10-12 12:21:04 +05:30
|
|
|
import {
|
2023-12-21 13:21:20 +05:30
|
|
|
filterKeyForField,
|
2023-10-12 12:21:04 +05:30
|
|
|
flattenObject,
|
|
|
|
|
jsonToDataNodes,
|
|
|
|
|
recursiveParseJSON,
|
|
|
|
|
removeEscapeCharacters,
|
|
|
|
|
} 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;
|
2024-02-12 00:23:19 +05:30
|
|
|
fieldSearchInput: string;
|
2024-02-20 16:21:07 +05:30
|
|
|
isListViewPanel?: boolean;
|
2022-08-19 17:16:04 +05:30
|
|
|
}
|
2023-07-11 16:53:15 +03:00
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
type Props = TableViewProps &
|
2024-02-12 00:23:19 +05:30
|
|
|
Partial<Pick<ActionItemProps, 'onClickActionItem'>> &
|
|
|
|
|
Pick<AddToQueryHOCProps, 'onAddToQuery'>;
|
2023-07-11 16:53:15 +03:00
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
function TableView({
|
|
|
|
|
logData,
|
2024-02-12 00:23:19 +05:30
|
|
|
fieldSearchInput,
|
2023-07-13 15:55:43 +03:00
|
|
|
onAddToQuery,
|
|
|
|
|
onClickActionItem,
|
2024-02-20 16:21:07 +05:30
|
|
|
isListViewPanel = false,
|
2023-07-13 15:55:43 +03:00
|
|
|
}: Props): JSX.Element | null {
|
2023-05-18 12:36:02 +05:30
|
|
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
2024-02-12 00:23:19 +05:30
|
|
|
const [isfilterInLoading, setIsFilterInLoading] = useState<boolean>(false);
|
|
|
|
|
const [isfilterOutLoading, setIsFilterOutLoading] = useState<boolean>(false);
|
2023-05-18 12:36:02 +05:30
|
|
|
|
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],
|
|
|
|
|
);
|
2024-02-12 00:23:19 +05:30
|
|
|
|
|
|
|
|
const handleClick = (
|
|
|
|
|
operator: string,
|
|
|
|
|
fieldKey: string,
|
|
|
|
|
fieldValue: string,
|
|
|
|
|
): void => {
|
|
|
|
|
const validatedFieldValue = removeJSONStringifyQuotes(fieldValue);
|
|
|
|
|
if (onClickActionItem) {
|
|
|
|
|
onClickActionItem(fieldKey, validatedFieldValue, operator);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onClickHandler = (
|
|
|
|
|
operator: string,
|
|
|
|
|
fieldKey: string,
|
|
|
|
|
fieldValue: string,
|
|
|
|
|
) => (): void => {
|
|
|
|
|
handleClick(operator, fieldKey, fieldValue);
|
|
|
|
|
if (operator === OPERATORS.IN) {
|
|
|
|
|
setIsFilterInLoading(true);
|
|
|
|
|
}
|
|
|
|
|
if (operator === OPERATORS.NIN) {
|
|
|
|
|
setIsFilterOutLoading(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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,
|
2023-10-13 11:35:50 +05:30
|
|
|
value: JSON.stringify(flattenLogData[key]),
|
2023-01-24 18:53:04 +05:30
|
|
|
}));
|
2022-08-19 17:16:04 +05:30
|
|
|
|
2024-02-17 14:59:49 +05:30
|
|
|
const onTraceHandler = (
|
|
|
|
|
record: DataType,
|
|
|
|
|
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
|
|
|
) => (): void => {
|
2023-05-18 12:36:02 +05:30
|
|
|
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;
|
|
|
|
|
|
2024-02-17 14:59:49 +05:30
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
|
// open the trace in new tab
|
|
|
|
|
window.open(route, '_blank');
|
|
|
|
|
} else {
|
|
|
|
|
history.push(route);
|
|
|
|
|
}
|
2023-05-18 12:36:02 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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: '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,
|
2024-02-12 00:23:19 +05:30
|
|
|
className: 'attribute-name',
|
2023-05-18 12:36:02 +05:30
|
|
|
render: (field: string, record): JSX.Element => {
|
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 (
|
2024-02-12 00:23:19 +05:30
|
|
|
<Space size="middle" className="log-attribute">
|
|
|
|
|
<Typography.Text>{renderedField}</Typography.Text>
|
2023-05-18 12:36:02 +05:30
|
|
|
|
|
|
|
|
{traceId && (
|
|
|
|
|
<Tooltip title="Inspect in Trace">
|
2024-02-17 14:59:49 +05:30
|
|
|
<Button
|
|
|
|
|
className="periscope-btn"
|
|
|
|
|
onClick={(
|
|
|
|
|
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
|
|
|
): void => {
|
|
|
|
|
onTraceHandler(record, event);
|
|
|
|
|
}}
|
2023-05-18 12:36:02 +05:30
|
|
|
>
|
|
|
|
|
<LinkOutlined
|
|
|
|
|
style={{
|
|
|
|
|
width: '15px',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2024-02-17 14:59:49 +05:30
|
|
|
</Button>
|
2023-05-18 12:36:02 +05:30
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</Space>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 13:21:20 +05:30
|
|
|
const fieldFilterKey = filterKeyForField(field);
|
|
|
|
|
if (!RESTRICTED_FIELDS.includes(fieldFilterKey)) {
|
2022-08-16 18:53:34 +05:30
|
|
|
return (
|
2023-07-11 16:53:15 +03:00
|
|
|
<AddToQueryHOC
|
2023-12-21 13:21:20 +05:30
|
|
|
fieldKey={fieldFilterKey}
|
2023-07-11 16:53:15 +03:00
|
|
|
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',
|
|
|
|
|
key: 'value',
|
2023-09-14 17:12:49 +05:30
|
|
|
width: 70,
|
2022-08-11 11:45:28 +05:30
|
|
|
ellipsis: false,
|
2024-02-12 00:23:19 +05:30
|
|
|
className: 'value-field-container attribute-value',
|
|
|
|
|
render: (fieldData: Record<string, string>, record): JSX.Element => {
|
|
|
|
|
const textToCopy = fieldData.value.slice(1, -1);
|
2023-09-28 09:15:12 +05:30
|
|
|
|
2023-03-17 15:21:02 +05:30
|
|
|
if (record.field === 'body') {
|
2024-02-12 00:23:19 +05:30
|
|
|
const parsedBody = recursiveParseJSON(fieldData.value);
|
2023-03-17 15:21:02 +05:30
|
|
|
if (!isEmpty(parsedBody)) {
|
2023-09-15 10:38:07 +05:30
|
|
|
return (
|
|
|
|
|
<Tree defaultExpandAll showLine treeData={jsonToDataNodes(parsedBody)} />
|
|
|
|
|
);
|
2023-03-17 15:21:02 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
const fieldFilterKey = filterKeyForField(fieldData.field);
|
|
|
|
|
|
2023-03-17 15:21:02 +05:30
|
|
|
return (
|
2024-02-12 00:23:19 +05:30
|
|
|
<div className="value-field">
|
|
|
|
|
<CopyClipboardHOC textToCopy={textToCopy}>
|
|
|
|
|
<span style={{ color: Color.BG_SIENNA_400 }}>
|
|
|
|
|
{removeEscapeCharacters(fieldData.value)}
|
|
|
|
|
</span>
|
|
|
|
|
</CopyClipboardHOC>
|
2024-02-20 16:21:07 +05:30
|
|
|
|
|
|
|
|
{!isListViewPanel && (
|
|
|
|
|
<span className="action-btn">
|
|
|
|
|
<Tooltip title="Filter for value">
|
|
|
|
|
<Button
|
|
|
|
|
className="filter-btn periscope-btn"
|
|
|
|
|
icon={
|
|
|
|
|
isfilterInLoading ? (
|
|
|
|
|
<Spin size="small" />
|
|
|
|
|
) : (
|
|
|
|
|
<ArrowDownToDot size={14} style={{ transform: 'rotate(90deg)' }} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClick={onClickHandler(
|
|
|
|
|
OPERATORS.IN,
|
|
|
|
|
fieldFilterKey,
|
|
|
|
|
fieldData.value,
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title="Filter out value">
|
|
|
|
|
<Button
|
|
|
|
|
className="filter-btn periscope-btn"
|
|
|
|
|
icon={
|
|
|
|
|
isfilterOutLoading ? (
|
|
|
|
|
<Spin size="small" />
|
|
|
|
|
) : (
|
|
|
|
|
<ArrowUpFromDot size={14} style={{ transform: 'rotate(90deg)' }} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClick={onClickHandler(
|
|
|
|
|
OPERATORS.NIN,
|
|
|
|
|
fieldFilterKey,
|
|
|
|
|
fieldData.value,
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-02-12 00:23:19 +05:30
|
|
|
</div>
|
2023-03-17 15:21:02 +05:30
|
|
|
);
|
|
|
|
|
},
|
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 (
|
2024-02-12 00:23:19 +05:30
|
|
|
<ResizeTable
|
|
|
|
|
columns={columns}
|
|
|
|
|
tableLayout="fixed"
|
|
|
|
|
dataSource={dataSource}
|
|
|
|
|
pagination={false}
|
|
|
|
|
showHeader={false}
|
|
|
|
|
className="attribute-table-container"
|
|
|
|
|
/>
|
2022-08-11 11:45:28 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
TableView.defaultProps = {
|
|
|
|
|
isListViewPanel: false,
|
|
|
|
|
};
|
|
|
|
|
|
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;
|