import { Box, Tabs, Typography, Tab, Paper, Button } from "@mui/material"; import Highlight from "react-highlight"; import * as React from "react"; import { Data } from "./RunsTable"; import { TabPanel, TabContext } from "@mui/lab"; import ArticleIcon from '@mui/icons-material/Article'; import ImageIcon from '@mui/icons-material/Image'; import { useEffect, useState } from "react"; import Table from '@mui/material/Table'; import TableBody from '@mui/material/TableBody'; import TableCell from '@mui/material/TableCell'; import TableContainer from '@mui/material/TableContainer'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import 'highlight.js/styles/github.css'; import { useTranslation } from "react-i18next"; interface RunContentProps { row: Data, currentLog: string, interpretationInProgress: boolean, logEndRef: React.RefObject, abortRunHandler: () => void, } export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRef, abortRunHandler }: RunContentProps) => { const { t } = useTranslation(); const [tab, setTab] = React.useState('log'); const [tableData, setTableData] = useState([]); const [columns, setColumns] = useState([]); useEffect(() => { setTab(tab); }, [interpretationInProgress]); useEffect(() => { if (row.serializableOutput && Object.keys(row.serializableOutput).length > 0) { const firstKey = Object.keys(row.serializableOutput)[0]; const data = row.serializableOutput[firstKey]; if (Array.isArray(data)) { // Filter out completely empty rows const filteredData = data.filter(row => Object.values(row).some(value => value !== undefined && value !== "") ); setTableData(filteredData); if (filteredData.length > 0) { setColumns(Object.keys(filteredData[0])); } } } }, [row.serializableOutput]); // Function to convert table data to CSV format const convertToCSV = (data: any[], columns: string[]): string => { const header = columns.join(','); const rows = data.map(row => columns.map(col => JSON.stringify(row[col], null, 2)).join(',') ); return [header, ...rows].join('\n'); }; const downloadCSV = () => { const csvContent = convertToCSV(tableData, columns); const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.setAttribute("download", "data.csv"); document.body.appendChild(link); link.click(); document.body.removeChild(link); }; return ( setTab(newTab)} aria-label="run-content-tabs" sx={{ // Remove the default blue indicator '& .MuiTabs-indicator': { backgroundColor: '#FF00C3', // Change to pink }, // Remove default transition effects '& .MuiTab-root': { '&.Mui-selected': { color: '#FF00C3', }, } }} > theme.palette.mode === 'dark' ? '#fff' : '#000', '&:hover': { color: '#FF00C3' }, '&.Mui-selected': { color: '#FF00C3', } }} /> theme.palette.mode === 'dark' ? '#fff' : '#000', '&:hover': { color: '#FF00C3' }, '&.Mui-selected': { color: '#FF00C3', } }} />
{interpretationInProgress ? currentLog : row.log}
{interpretationInProgress ? : null} {!row || !row.serializableOutput || !row.binaryOutput || (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0) ? {t('run_content.empty_output')} : null} {row.serializableOutput && Object.keys(row.serializableOutput).length !== 0 &&
{t('run_content.captured_data.title')} {t('run_content.captured_data.download_json')} {t('run_content.captured_data.download_csv')} {tableData.length > 0 ? ( {columns.map((column) => ( {column} ))} {tableData.map((row, index) => ( {columns.map((column) => ( {row[column] === undefined || row[column] === "" ? "-" : row[column]} ))} ))}
) : (
                    {JSON.stringify(row.serializableOutput, null, 2)}
                  
)}
} {row.binaryOutput && Object.keys(row.binaryOutput).length !== 0 &&
{t('run_content.captured_screenshot.title')} {Object.keys(row.binaryOutput).map((key) => { try { const imageUrl = row.binaryOutput[key]; return ( {t('run_content.captured_screenshot.download')} {key} ) } catch (e) { console.log(e) return {key}: {t('run_content.captured_screenshot.render_failed')} } })}
}
); };