feat: show output data in table
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Box, Tabs, Typography, Tab } from "@mui/material";
|
import { Box, Tabs, Typography, Tab, Paper } from "@mui/material";
|
||||||
import Highlight from "react-highlight";
|
import Highlight from "react-highlight";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
@@ -8,8 +8,14 @@ import SettingsIcon from '@mui/icons-material/Settings';
|
|||||||
import ImageIcon from '@mui/icons-material/Image';
|
import ImageIcon from '@mui/icons-material/Image';
|
||||||
import ArticleIcon from '@mui/icons-material/Article';
|
import ArticleIcon from '@mui/icons-material/Article';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AssignmentIcon from '@mui/icons-material/Assignment';
|
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';
|
||||||
|
|
||||||
interface RunContentProps {
|
interface RunContentProps {
|
||||||
row: Data,
|
row: Data,
|
||||||
@@ -21,11 +27,26 @@ interface RunContentProps {
|
|||||||
|
|
||||||
export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRef, abortRunHandler }: RunContentProps) => {
|
export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRef, abortRunHandler }: RunContentProps) => {
|
||||||
const [tab, setTab] = React.useState<string>('log');
|
const [tab, setTab] = React.useState<string>('log');
|
||||||
|
const [tableData, setTableData] = useState<any[]>([]);
|
||||||
|
const [columns, setColumns] = useState<string[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTab(tab);
|
setTab(tab);
|
||||||
}, [interpretationInProgress])
|
}, [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]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: '100%' }}>
|
<Box sx={{ width: '100%' }}>
|
||||||
<TabContext value={tab}>
|
<TabContext value={tab}>
|
||||||
@@ -102,34 +123,50 @@ export const RunContent = ({ row, currentLog, interpretationInProgress, logEndRe
|
|||||||
|| (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0)
|
|| (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0)
|
||||||
? <Typography>The output is empty.</Typography> : null}
|
? <Typography>The output is empty.</Typography> : null}
|
||||||
|
|
||||||
|
{!row || !row.serializableOutput || !row.binaryOutput
|
||||||
|
|| (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0)
|
||||||
|
? <Typography>The output is empty.</Typography> : null}
|
||||||
|
|
||||||
{row.serializableOutput &&
|
{row.serializableOutput &&
|
||||||
Object.keys(row.serializableOutput).length !== 0 &&
|
Object.keys(row.serializableOutput).length !== 0 &&
|
||||||
<div>
|
<div>
|
||||||
<Typography variant='h6' sx={{ display: 'flex', alignItems: 'center' }}>
|
<Typography variant='h6' sx={{ display: 'flex', alignItems: 'center' }}>
|
||||||
<ArticleIcon sx={{ marginRight: '15px' }} />
|
<ArticleIcon sx={{ marginRight: '15px' }} />
|
||||||
Serializable output</Typography>
|
Serializable output
|
||||||
{Object.keys(row.serializableOutput).map((key) => {
|
</Typography>
|
||||||
return (
|
{tableData.length > 0 ? (
|
||||||
<div key={`number-of-serializable-output-${key}`}>
|
<TableContainer component={Paper} sx={{ maxHeight: 440, marginTop: 2 }}>
|
||||||
<Typography>
|
<Table stickyHeader aria-label="sticky table">
|
||||||
{key}:
|
<TableHead>
|
||||||
<a href={`data:application/json;utf8,${JSON.stringify(row.serializableOutput[key], null, 2)}`}
|
<TableRow>
|
||||||
download={key} style={{ margin: '10px' }}>Download</a>
|
{columns.map((column) => (
|
||||||
</Typography>
|
<TableCell key={column}>{column}</TableCell>
|
||||||
<Box sx={{
|
))}
|
||||||
width: 'fit-content',
|
</TableRow>
|
||||||
background: 'rgba(0,0,0,0.06)',
|
</TableHead>
|
||||||
maxHeight: '300px',
|
<TableBody>
|
||||||
overflow: 'scroll',
|
{tableData.map((row, index) => (
|
||||||
}}>
|
<TableRow key={index}>
|
||||||
<pre key={`serializable-output-${key}`}>
|
{columns.map((column) => (
|
||||||
{row.serializableOutput[key] ? JSON.stringify(row.serializableOutput[key], null, 2)
|
<TableCell key={column}>{row[column]}</TableCell>
|
||||||
: 'The output is empty.'}
|
))}
|
||||||
</pre>
|
</TableRow>
|
||||||
</Box>
|
))}
|
||||||
</div>
|
</TableBody>
|
||||||
)
|
</Table>
|
||||||
})}
|
</TableContainer>
|
||||||
|
) : (
|
||||||
|
<Box sx={{
|
||||||
|
width: 'fit-content',
|
||||||
|
background: 'rgba(0,0,0,0.06)',
|
||||||
|
maxHeight: '300px',
|
||||||
|
overflow: 'scroll',
|
||||||
|
}}>
|
||||||
|
<pre>
|
||||||
|
{JSON.stringify(row.serializableOutput, null, 2)}
|
||||||
|
</pre>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{row.binaryOutput
|
{row.binaryOutput
|
||||||
|
|||||||
Reference in New Issue
Block a user