diff --git a/frontend/src/container/LogDetailedView/FieldRenderer.tsx b/frontend/src/container/LogDetailedView/FieldRenderer.tsx new file mode 100644 index 0000000000..3df11cb8b5 --- /dev/null +++ b/frontend/src/container/LogDetailedView/FieldRenderer.tsx @@ -0,0 +1,25 @@ +import { blue } from '@ant-design/colors'; +import { Tag } from 'antd'; + +import { FieldRendererProps } from './LogDetailedView.types'; +import { getFieldAttributes } from './utils'; + +function FieldRenderer({ field }: FieldRendererProps): JSX.Element { + const { dataType, newField, logType } = getFieldAttributes(field); + + return ( + + {dataType && newField && logType ? ( + <> + {newField} + Type: {logType} + Data type: {dataType} + + ) : ( + {field} + )} + + ); +} + +export default FieldRenderer; diff --git a/frontend/src/container/LogDetailedView/LogDetailedView.types.ts b/frontend/src/container/LogDetailedView/LogDetailedView.types.ts new file mode 100644 index 0000000000..0360ae11c3 --- /dev/null +++ b/frontend/src/container/LogDetailedView/LogDetailedView.types.ts @@ -0,0 +1,11 @@ +import { MetricsType } from 'container/MetricsApplication/constant'; + +export interface FieldRendererProps { + field: string; +} + +export interface IFieldAttributes { + dataType?: string; + newField?: string; + logType?: MetricsType; +} diff --git a/frontend/src/container/LogDetailedView/TableView.tsx b/frontend/src/container/LogDetailedView/TableView.tsx index a7b0391ff7..736e1a5da2 100644 --- a/frontend/src/container/LogDetailedView/TableView.tsx +++ b/frontend/src/container/LogDetailedView/TableView.tsx @@ -1,4 +1,4 @@ -import { blue, orange } from '@ant-design/colors'; +import { orange } from '@ant-design/colors'; import { LinkOutlined } from '@ant-design/icons'; import { Input, Space, Tooltip } from 'antd'; import { ColumnsType } from 'antd/es/table'; @@ -21,6 +21,7 @@ import { SET_DETAILED_LOG_DATA } from 'types/actions/logs'; import { ILog } from 'types/api/logs/log'; import ActionItem, { ActionItemProps } from './ActionItem'; +import FieldRenderer from './FieldRenderer'; import { flattenObject, recursiveParseJSON } from './utils'; // Fields which should be restricted from adding it to query @@ -91,7 +92,7 @@ function TableView({ const columns: ColumnsType = [ { title: 'Action', - width: 30, + width: 11, render: (fieldData: Record): JSX.Element | null => { const fieldKey = fieldData.field.split('.').slice(-1); if (!RESTRICTED_FIELDS.includes(fieldKey[0])) { @@ -110,12 +111,12 @@ function TableView({ title: 'Field', dataIndex: 'field', key: 'field', - width: 30, + width: 50, align: 'left', ellipsis: true, render: (field: string, record): JSX.Element => { const fieldKey = field.split('.').slice(-1); - const renderedField = {field}; + const renderedField = ; if (record.field === 'trace_id') { const traceId = flattenLogData[record.field]; @@ -161,7 +162,7 @@ function TableView({ title: 'Value', dataIndex: 'value', key: 'value', - width: 80, + width: 70, ellipsis: false, render: (field, record): JSX.Element => { if (record.field === 'body') { diff --git a/frontend/src/container/LogDetailedView/utils.ts b/frontend/src/container/LogDetailedView/utils.ts index 4a73c61933..b87a6a4ed0 100644 --- a/frontend/src/container/LogDetailedView/utils.ts +++ b/frontend/src/container/LogDetailedView/utils.ts @@ -1,3 +1,7 @@ +import { MetricsType } from 'container/MetricsApplication/constant'; + +import { IFieldAttributes } from './LogDetailedView.types'; + export const recursiveParseJSON = (obj: string): Record => { try { const value = JSON.parse(obj); @@ -32,3 +36,23 @@ export function flattenObject(obj: AnyObject, prefix = ''): AnyObject { return acc; }, {}); } + +export const getFieldAttributes = (field: string): IFieldAttributes => { + let dataType; + let newField; + let logType; + + if (field.startsWith('attributes_')) { + logType = MetricsType.Tag; + const stringWithoutPrefix = field.slice('attributes_'.length); + const parts = stringWithoutPrefix.split('.'); + [dataType, newField] = parts; + } else if (field.startsWith('resources_')) { + logType = MetricsType.Resource; + const stringWithoutPrefix = field.slice('resources_'.length); + const parts = stringWithoutPrefix.split('.'); + [dataType, newField] = parts; + } + + return { dataType, newField, logType }; +};