import { blue, orange } from '@ant-design/colors'; import { Input } from 'antd'; import { ColumnsType } from 'antd/es/table'; import Editor from 'components/Editor'; import AddToQueryHOC from 'components/Logs/AddToQueryHOC'; import CopyClipboardHOC from 'components/Logs/CopyClipboardHOC'; import { ResizeTable } from 'components/ResizeTable'; import flatten from 'flat'; import { fieldSearchFilter } from 'lib/logs/fieldSearch'; import { isEmpty } from 'lodash-es'; import React, { useMemo, useState } from 'react'; import { ILog } from 'types/api/logs/log'; import ActionItem from './ActionItem'; import { recursiveParseJSON } from './utils'; // Fields which should be restricted from adding it to query const RESTRICTED_FIELDS = ['timestamp']; interface TableViewProps { logData: ILog; } function TableView({ logData }: TableViewProps): JSX.Element | null { const [fieldSearchInput, setFieldSearchInput] = useState(''); const flattenLogData: Record | null = useMemo( () => (logData ? flatten(logData) : null), [logData], ); if (logData === null) { return null; } const dataSource = flattenLogData !== null && Object.keys(flattenLogData) .filter((field) => fieldSearchFilter(field, fieldSearchInput)) .map((key) => ({ key, field: key, value: JSON.stringify(flattenLogData[key]), })); if (!dataSource) { return null; } const columns: ColumnsType = [ { title: 'Action', width: 15, render: (fieldData: Record): JSX.Element | null => { const fieldKey = fieldData.field.split('.').slice(-1); if (!RESTRICTED_FIELDS.includes(fieldKey[0])) { return ; } return null; }, }, { title: 'Field', dataIndex: 'field', key: 'field', width: 30, ellipsis: true, render: (field: string): JSX.Element => { const fieldKey = field.split('.').slice(-1); const renderedField = {field}; if (!RESTRICTED_FIELDS.includes(fieldKey[0])) { return ( {renderedField} ); } return renderedField; }, }, { title: 'Value', dataIndex: 'value', key: 'value', width: 80, ellipsis: false, render: (field, record): JSX.Element => { if (record.field === 'body') { const parsedBody = recursiveParseJSON(field); if (!isEmpty(parsedBody)) { return ( ); } } return ( {field} ); }, }, ]; return ( <> setFieldSearchInput(e.target.value)} /> ); } interface DataType { key: string; field: string; value: string; } export default TableView;