import { LogEntry } from "./columns"; import { message } from "antd"; interface RequestResponsePanelProps { row: { original: LogEntry; }; hasMessages: string | boolean; hasResponse: string | boolean; hasError: boolean; errorInfo: any; getRawRequest: () => any; formattedResponse: () => any; } export function RequestResponsePanel({ row, hasMessages, hasResponse, hasError, errorInfo, getRawRequest, formattedResponse, }: RequestResponsePanelProps) { const copyToClipboard = async (text: string) => { try { // Try modern clipboard API first if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); return true; } else { // Fallback for non-secure contexts (like 0.0.0.0) const textArea = document.createElement('textarea'); textArea.value = text; textArea.style.position = 'fixed'; textArea.style.opacity = '0'; document.body.appendChild(textArea); textArea.focus(); textArea.select(); const successful = document.execCommand('copy'); document.body.removeChild(textArea); if (!successful) { throw new Error('execCommand failed'); } return true; } } catch (error) { console.error('Copy failed:', error); return false; } }; const handleCopyRequest = async () => { const success = await copyToClipboard(JSON.stringify(getRawRequest(), null, 2)); if (success) { message.success('Request copied to clipboard'); } else { message.error('Failed to copy request'); } }; const handleCopyResponse = async () => { const success = await copyToClipboard(JSON.stringify(formattedResponse(), null, 2)); if (success) { message.success('Response copied to clipboard'); } else { message.error('Failed to copy response'); } }; return (
{/* Request Side */}

Request

{JSON.stringify(getRawRequest(), null, 2)}
{/* Response Side */}

Response {hasError && ( • HTTP code {errorInfo?.error_code || 400} )}

{hasResponse ? (
{JSON.stringify(formattedResponse(), null, 2)}
) : (
Response data not available
)}
); }