Skip to content

Commit

Permalink
[Refactor]: added tag for data type and type of logs (#3554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Dabade authored Sep 14, 2023
1 parent 14a59a2 commit 85d7752
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
25 changes: 25 additions & 0 deletions frontend/src/container/LogDetailedView/FieldRenderer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<span>
{dataType && newField && logType ? (
<>
<span style={{ color: blue[4] }}>{newField} </span>
<Tag>Type: {logType}</Tag>
<Tag>Data type: {dataType}</Tag>
</>
) : (
<span style={{ color: blue[4] }}>{field}</span>
)}
</span>
);
}

export default FieldRenderer;
11 changes: 11 additions & 0 deletions frontend/src/container/LogDetailedView/LogDetailedView.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MetricsType } from 'container/MetricsApplication/constant';

export interface FieldRendererProps {
field: string;
}

export interface IFieldAttributes {
dataType?: string;
newField?: string;
logType?: MetricsType;
}
11 changes: 6 additions & 5 deletions frontend/src/container/LogDetailedView/TableView.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -91,7 +92,7 @@ function TableView({
const columns: ColumnsType<DataType> = [
{
title: 'Action',
width: 30,
width: 11,
render: (fieldData: Record<string, string>): JSX.Element | null => {
const fieldKey = fieldData.field.split('.').slice(-1);
if (!RESTRICTED_FIELDS.includes(fieldKey[0])) {
Expand All @@ -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 = <span style={{ color: blue[4] }}>{field}</span>;
const renderedField = <FieldRenderer field={field} />;

if (record.field === 'trace_id') {
const traceId = flattenLogData[record.field];
Expand Down Expand Up @@ -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') {
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/container/LogDetailedView/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { MetricsType } from 'container/MetricsApplication/constant';

import { IFieldAttributes } from './LogDetailedView.types';

export const recursiveParseJSON = (obj: string): Record<string, unknown> => {
try {
const value = JSON.parse(obj);
Expand Down Expand Up @@ -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 };
};

0 comments on commit 85d7752

Please sign in to comment.