import React, { useState } from 'react'; import cn from 'classnames'; import { Icon } from 'UI'; import JumpButton from 'Shared/DevTools/JumpButton'; import { Tag } from 'antd'; import TabTag from '../TabTag'; interface Props { log: any; iconProps: any; jump?: any; renderWithNL?: any; style?: any; onClick?: () => void; getTabNum?: (tab: string) => number; showSingleTab: boolean; } function ConsoleRow(props: Props) { const { log, iconProps, jump, renderWithNL, style } = props; const [expanded, setExpanded] = useState(false); const lines = log.value?.split('\n').filter((l: any) => !!l) || []; const canExpand = lines.length > 1; const clickable = canExpand || !!log.errorId; const toggleExpand = () => { setExpanded(!expanded); }; const urlRegex = /(https?:\/\/[^\s)]+)/g; const renderLine = (l: string) => { const parts = l.split(urlRegex); const formattedLine = parts.map((part, index) => { if (urlRegex.test(part)) { return ( {part} ); } return part; }); return formattedLine; }; const titleLine = lines[0]; const restLines = lines.slice(1); const logSource = props.showSingleTab ? -1 : props.getTabNum?.(log.tabId); const logTabId = log.tabId; return (
(log.errorId ? props.onClick?.() : toggleExpand()) : undefined } > {logSource !== -1 && }
{canExpand && ( )} {renderWithNL(titleLine)}
{log.errorId && (
{log.message}
)}
{canExpand && expanded && restLines.map((l: string, i: number) => (
{renderLine(l)}
))}
jump(log.time)} />
); } export default ConsoleRow;