import * as React from 'react'; import Paper from '@mui/material/Paper'; 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 TablePagination from '@mui/material/TablePagination'; import TableRow from '@mui/material/TableRow'; import { useEffect } from "react"; import { WorkflowFile } from "maxun-core"; import { IconButton } from "@mui/material"; import { Schedule, DeleteForever, Edit, PlayCircle } from "@mui/icons-material"; import LinkIcon from '@mui/icons-material/Link'; import { useGlobalInfoStore } from "../../context/globalInfo"; import { deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage"; import { Typography } from '@mui/material'; /** TODO: * 1. allow editing existing robot after persisting browser steps * 2. show robot settings: id, url, etc. */ interface Column { id: 'interpret' | 'name' | 'delete' | 'schedule' | 'integrate'; label: string; minWidth?: number; align?: 'right'; format?: (value: string) => string; } const columns: readonly Column[] = [ { id: 'interpret', label: 'Run', minWidth: 80 }, { id: 'name', label: 'Name', minWidth: 80 }, // { // id: 'createdAt', // label: 'Created at', // minWidth: 80, // //format: (value: string) => value.toLocaleString('en-US'), // }, // { // id: 'edit', // label: 'Edit', // minWidth: 80, // }, { id: 'schedule', label: 'Schedule', minWidth: 80, }, { id: 'integrate', label: 'Integrate', minWidth: 80, }, // { // id: 'updatedAt', // label: 'Updated at', // minWidth: 80, // //format: (value: string) => value.toLocaleString('en-US'), // }, { id: 'delete', label: 'Delete', minWidth: 80, }, ]; interface Data { id: string; name: string; createdAt: string; updatedAt: string; content: WorkflowFile; params: string[]; } interface RecordingsTableProps { handleEditRecording: (id: string, fileName: string) => void; handleRunRecording: (id: string, fileName: string, params: string[]) => void; handleScheduleRecording: (id: string, fileName: string, params: string[]) => void; handleIntegrateRecording: (id: string, fileName: string, params: string[]) => void; } export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handleScheduleRecording, handleIntegrateRecording }: RecordingsTableProps) => { const [page, setPage] = React.useState(0); const [rowsPerPage, setRowsPerPage] = React.useState(10); const [rows, setRows] = React.useState([]); const { notify, setRecordings } = useGlobalInfoStore(); const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage); }; const handleChangeRowsPerPage = (event: React.ChangeEvent) => { setRowsPerPage(+event.target.value); setPage(0); }; const fetchRecordings = async () => { const recordings = await getStoredRecordings(); if (recordings) { const parsedRows: Data[] = []; recordings.map((recording: any, index: number) => { if (recording && recording.recording_meta) { parsedRows.push({ id: index, ...recording.recording_meta, content: recording.recording }); } }); setRecordings(parsedRows.map((recording) => recording.name)); setRows(parsedRows); } else { console.log('No recordings found.'); } } useEffect(() => { if (rows.length === 0) { fetchRecordings(); } }, []); return ( My Robots {columns.map((column) => ( {column.label} ))} {rows.length !== 0 ? rows .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row) => { return ( {columns.map((column) => { // @ts-ignore const value: any = row[column.id]; if (value !== undefined) { return ( {value} ); } else { switch (column.id) { case 'interpret': return ( handleRunRecording(row.id, row.name, row.params || [])} /> ); // case 'edit': // return ( // // { // handleEditRecording(row.id, row.name); // }} sx={{ '&:hover': { color: '#1976d2', backgroundColor: 'transparent' } }}> // // // // ); case 'schedule': return ( handleScheduleRecording(row.id, row.name, row.params || [])} /> ); case 'integrate': return ( handleIntegrateRecording(row.id, row.name, row.params || [])} /> ); case 'delete': return ( { deleteRecordingFromStorage(row.id).then((result: boolean) => { if (result) { setRows([]); notify('success', 'Recording deleted successfully'); fetchRecordings(); } }) }} sx={{ '&:hover': { color: '#1976d2', backgroundColor: 'transparent' } }}> ); default: return null; } } })} ); }) : null}
); } interface InterpretButtonProps { handleInterpret: () => void; } const InterpretButton = ({ handleInterpret }: InterpretButtonProps) => { return ( { handleInterpret(); }} sx={{ '&:hover': { color: '#1976d2', backgroundColor: 'transparent' } }}> ) } interface ScheduleButtonProps { handleSchedule: () => void; } const ScheduleButton = ({ handleSchedule }: ScheduleButtonProps) => { return ( { handleSchedule(); }} sx={{ '&:hover': { color: '#1976d2', backgroundColor: 'transparent' } }}> ) } interface IntegrateButtonProps { handleIntegrate: () => void; } const IntegrateButton = ({ handleIntegrate }: IntegrateButtonProps) => { return ( { handleIntegrate(); }} sx={{ '&:hover': { color: '#1976d2', backgroundColor: 'transparent' } }}> ) }