import { Box, Tabs, Typography, Tab, Paper } from "@mui/material"; import Highlight from "react-highlight"; import Button from "@mui/material/Button"; import * as React from "react"; import { Data } from "./RunsTable"; import { TabPanel, TabContext } from "@mui/lab"; import SettingsIcon from '@mui/icons-material/Settings'; import ImageIcon from '@mui/icons-material/Image'; import ArticleIcon from '@mui/icons-material/Article'; import { useEffect, useState } from "react"; import AssignmentIcon from '@mui/icons-material/Assignment'; 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'; interface RunContentProps { row: Data, currentLog: string, interpretationInProgress: boolean, logEndRef: React.RefObject, abortRunHandler: () => void, } export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRef, abortRunHandler }: RunContentProps) => { 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)) { setTableData(data); if (data.length > 0) { setColumns(Object.keys(data[0])); } } } }, [row.serializableOutput]); // Function to convert table data to CSV format const convertToCSV = (data: any[], columns: string[]): string => { const header = columns.join(','); // Create CSV header row const rows = data.map(row => columns.map(col => JSON.stringify(row[col], null, 2)).join(',') ); // Map each row of data to a CSV row return [header, ...rows].join('\n'); // Combine header and rows with newline characters } // Function to download CSV file when called const downloadCSV = () => { const csvContent = convertToCSV(tableData, columns); // Convert data to CSV format const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); // Create a Blob object with CSV content const url = URL.createObjectURL(blob); // Create a temporary URL for the Blob // Create a temporary link to download the CSV file const link = document.createElement("a"); link.href = url; link.setAttribute("download", "data.csv"); // Set the download filename document.body.appendChild(link); link.click(); // Programmatically click the link to trigger the download document.body.removeChild(link); // Remove the link element after download } return ( setTab(newTab)} aria-label="run-content-tabs"> {/* */}
{interpretationInProgress ? currentLog : row.log}
{interpretationInProgress ? : null} {!row || !row.serializableOutput || !row.binaryOutput || (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0) ? The output is empty. : null} {row.serializableOutput && Object.keys(row.serializableOutput).length !== 0 &&
Captured Data {Object.keys(row.serializableOutput).map((key) => { return ( ) })} {tableData.length > 0 ? ( <> {columns.map((column) => ( {column} ))} {tableData.map((row, index) => ( {columns.map((column) => ( {row[column]} ))} ))}
) : (
                    {JSON.stringify(row.serializableOutput, null, 2)}
                  
)}
} {row.binaryOutput && Object.keys(row.binaryOutput).length !== 0 &&
Captured Screenshot {Object.keys(row.binaryOutput).map((key) => { try { const imageUrl = row.binaryOutput[key]; return ( Download Screenshot {key} ) } catch (e) { console.log(e) return {key}: The image failed to render } })}
}
); }