import { blue, grey, orange } from '@ant-design/colors'; import { CopyFilled, ExpandAltOutlined } from '@ant-design/icons'; import { Button, Divider, Row, Typography } from 'antd'; import { map } from 'd3'; import dayjs from 'dayjs'; import { useNotifications } from 'hooks/useNotifications'; // utils import { FlatLogData } from 'lib/logs/flatLogData'; import React, { useCallback, useMemo } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useCopyToClipboard } from 'react-use'; // interfaces import { AppState } from 'store/reducers'; import { SET_DETAILED_LOG_DATA } from 'types/actions/logs'; import { ILog } from 'types/api/logs/log'; import { ILogsReducer } from 'types/reducer/logs'; // components import AddToQueryHOC from '../AddToQueryHOC'; import CopyClipboardHOC from '../CopyClipboardHOC'; // styles import { Container, LogContainer, Text, TextContainer } from './styles'; import { isValidLogField } from './util'; interface LogFieldProps { fieldKey: string; fieldValue: string; } function LogGeneralField({ fieldKey, fieldValue }: LogFieldProps): JSX.Element { return ( {fieldKey} {': '} {fieldValue} ); } function LogSelectedField({ fieldKey = '', fieldValue = '', }: LogFieldProps): JSX.Element { return (
{`"`} {fieldKey} {`"`} {': '} {typeof fieldValue === 'string' && `"`} {fieldValue} {typeof fieldValue === 'string' && `"`}
); } interface ListLogViewProps { logData: ILog; } function ListLogView({ logData }: ListLogViewProps): JSX.Element { const { fields: { selected }, } = useSelector((state) => state.logs); const dispatch = useDispatch(); const flattenLogData = useMemo(() => FlatLogData(logData), [logData]); const [, setCopy] = useCopyToClipboard(); const { notifications } = useNotifications(); const handleDetailedView = useCallback(() => { dispatch({ type: SET_DETAILED_LOG_DATA, payload: logData, }); }, [dispatch, logData]); const handleCopyJSON = (): void => { setCopy(JSON.stringify(logData, null, 2)); notifications.success({ message: 'Copied to clipboard', }); }; const updatedSelecedFields = useMemo( () => selected.filter((e) => e.name !== 'id'), [selected], ); return (
{'{'} <> {flattenLogData.stream && ( )} {'}'}
{map(updatedSelecedFields, (field) => isValidLogField(flattenLogData[field.name] as never) ? ( ) : null, )}
); } export default ListLogView;