2024-06-24 22:32:34 +05:30
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
|
import * as React from "react";
|
|
|
|
|
import TableRow from "@mui/material/TableRow";
|
|
|
|
|
import TableCell from "@mui/material/TableCell";
|
2024-10-28 20:14:02 +05:30
|
|
|
import { Box, Collapse, IconButton, Typography, Chip } from "@mui/material";
|
2024-06-24 22:32:34 +05:30
|
|
|
import { DeleteForever, KeyboardArrowDown, KeyboardArrowUp } from "@mui/icons-material";
|
|
|
|
|
import { deleteRunFromStorage } from "../../api/storage";
|
|
|
|
|
import { columns, Data } from "./RunsTable";
|
|
|
|
|
import { RunContent } from "./RunContent";
|
|
|
|
|
|
|
|
|
|
interface CollapsibleRowProps {
|
|
|
|
|
row: Data;
|
|
|
|
|
handleDelete: () => void;
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
currentLog: string;
|
|
|
|
|
abortRunHandler: () => void;
|
|
|
|
|
runningRecordingName: string;
|
|
|
|
|
}
|
2024-10-19 03:55:36 +05:30
|
|
|
export const CollapsibleRow = ({ row, handleDelete, isOpen, currentLog, abortRunHandler, runningRecordingName }: CollapsibleRowProps) => {
|
2024-06-24 22:32:34 +05:30
|
|
|
const [open, setOpen] = useState(isOpen);
|
|
|
|
|
|
2024-10-19 03:55:36 +05:30
|
|
|
const logEndRef = useRef<HTMLDivElement | null>(null);
|
2024-06-24 22:32:34 +05:30
|
|
|
|
|
|
|
|
const scrollToLogBottom = () => {
|
|
|
|
|
if (logEndRef.current) {
|
|
|
|
|
logEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleAbort = () => {
|
|
|
|
|
abortRunHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
scrollToLogBottom();
|
|
|
|
|
}, [currentLog])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<TableRow sx={{ '& > *': { borderBottom: 'unset' } }} hover role="checkbox" tabIndex={-1} key={row.id}>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="expand row"
|
|
|
|
|
size="small"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setOpen(!open);
|
|
|
|
|
scrollToLogBottom();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{open ? <KeyboardArrowUp /> : <KeyboardArrowDown />}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</TableCell>
|
|
|
|
|
{columns.map((column) => {
|
|
|
|
|
// @ts-ignore
|
2024-10-19 03:55:36 +05:30
|
|
|
const value: any = row[column.id];
|
2024-06-24 22:32:34 +05:30
|
|
|
if (value !== undefined) {
|
|
|
|
|
return (
|
|
|
|
|
<TableCell key={column.id} align={column.align}>
|
2024-10-28 20:14:02 +05:30
|
|
|
{value}
|
2024-06-24 22:32:34 +05:30
|
|
|
</TableCell>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
switch (column.id) {
|
2024-10-28 20:14:02 +05:30
|
|
|
case 'robotStatus':
|
|
|
|
|
return (
|
|
|
|
|
<TableCell key={column.id} align={column.align}>
|
|
|
|
|
{row.status === 'success' && <Chip label="Success" color="success" variant="outlined" />}
|
|
|
|
|
{row.status === 'running' && <Chip label="Running" color="warning" variant="outlined" />}
|
|
|
|
|
{row.status === 'scheduled' && <Chip label="Scheduled" variant="outlined" />}
|
|
|
|
|
{row.status === 'failed' && <Chip label="Failed" color="error" variant="outlined" />}
|
|
|
|
|
</TableCell>
|
|
|
|
|
)
|
2024-06-24 22:32:34 +05:30
|
|
|
case 'delete':
|
|
|
|
|
return (
|
|
|
|
|
<TableCell key={column.id} align={column.align}>
|
2024-10-19 03:55:36 +05:30
|
|
|
<IconButton aria-label="add" size="small" onClick={() => {
|
2024-10-10 02:25:48 +05:30
|
|
|
deleteRunFromStorage(`${row.runId}`).then((result: boolean) => {
|
2024-06-24 22:32:34 +05:30
|
|
|
if (result) {
|
|
|
|
|
handleDelete();
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-10-19 03:55:27 +05:30
|
|
|
}}>
|
2024-10-19 03:55:36 +05:30
|
|
|
<DeleteForever />
|
2024-06-24 22:32:34 +05:30
|
|
|
</IconButton>
|
|
|
|
|
</TableCell>
|
|
|
|
|
);
|
2024-10-25 02:07:59 +05:30
|
|
|
case 'runBy':
|
|
|
|
|
return (
|
|
|
|
|
<TableCell key={column.id} align={column.align}>
|
|
|
|
|
{
|
|
|
|
|
row.runByUserId ? `User: ${row.runByUserId}` : row.runByScheduleId ? `Schedule ID: ${row.runByScheduleId}` : row.runByAPI ? 'API' : 'Unknown'
|
|
|
|
|
}
|
|
|
|
|
</TableCell>
|
|
|
|
|
)
|
2024-06-24 22:32:34 +05:30
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
</TableRow>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
|
|
|
|
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
|
|
|
|
<RunContent row={row} abortRunHandler={handleAbort} currentLog={currentLog}
|
2024-10-19 03:55:36 +05:30
|
|
|
logEndRef={logEndRef} interpretationInProgress={runningRecordingName === row.name} />
|
2024-06-24 22:32:34 +05:30
|
|
|
</Collapse>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|