diff --git a/esbuild.config.js b/esbuild.config.js new file mode 100644 index 00000000..e69de29b diff --git a/src/components/molecules/RunContent.tsx b/src/components/molecules/RunContent.tsx index ea51bd03..5b041525 100644 --- a/src/components/molecules/RunContent.tsx +++ b/src/components/molecules/RunContent.tsx @@ -1,14 +1,11 @@ -import { Box, Tabs, Typography, Tab, Paper } from "@mui/material"; +import { Box, Tabs, Typography, Tab, Paper, Button } 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 ImageIcon from '@mui/icons-material/Image'; 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'; @@ -32,7 +29,7 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe useEffect(() => { setTab(tab); - }, [interpretationInProgress]) + }, [interpretationInProgress]); useEffect(() => { if (row.serializableOutput && Object.keys(row.serializableOutput).length > 0) { @@ -47,6 +44,29 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe } }, [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'); + }; + + // Function to download CSV file when called + 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 ( @@ -54,7 +74,6 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe setTab(newTab)} aria-label="run-content-tabs"> - {/* */} @@ -94,16 +113,30 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe Captured Data - {Object.keys(row.serializableOutput).map((key) => { - return ( -
- - Download as JSON - -
- ) - })} + + + + Download as JSON + + + + Download as CSV + + {tableData.length > 0 ? ( @@ -139,12 +172,12 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe )} } - {row.binaryOutput - && Object.keys(row.binaryOutput).length !== 0 && + {row.binaryOutput && Object.keys(row.binaryOutput).length !== 0 &&
- Captured Screenshot + Captured Screenshot + {Object.keys(row.binaryOutput).map((key) => { try { const imageUrl = row.binaryOutput[key]; @@ -152,10 +185,10 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe - + Download Screenshot - {key} + {key} ) } catch (e) { @@ -171,4 +204,4 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe ); -} +};