import React, { useEffect, useState } from "react"; import { connect, ConnectedProps } from "react-redux"; import { makeStyles } from "@material-ui/core/styles"; import Table from "@material-ui/core/Table"; import TableBody from "@material-ui/core/TableBody"; import TableCell from "@material-ui/core/TableCell"; import Alert from "@material-ui/lab/Alert"; import AlertTitle from "@material-ui/lab/AlertTitle"; import Button from "@material-ui/core/Button"; import TableContainer from "@material-ui/core/TableContainer"; import TableHead from "@material-ui/core/TableHead"; import TableRow from "@material-ui/core/TableRow"; import TableFooter from "@material-ui/core/TableFooter"; import TablePagination from "@material-ui/core/TablePagination"; import Paper from "@material-ui/core/Paper"; import Box from "@material-ui/core/Box"; import Collapse from "@material-ui/core/Collapse"; import IconButton from "@material-ui/core/IconButton"; import KeyboardArrowUpIcon from "@material-ui/icons/KeyboardArrowUp"; import KeyboardArrowDownIcon from "@material-ui/icons/KeyboardArrowDown"; import Typography from "@material-ui/core/Typography"; import SyntaxHighlighter from "react-syntax-highlighter"; import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github"; import { listActiveTasksAsync } from "../actions/tasksActions"; import { AppState } from "../store"; import { ActiveTask } from "../api"; import TablePaginationActions, { rowsPerPageOptions, defaultPageSize, } from "./TablePaginationActions"; const useStyles = makeStyles({ table: { minWidth: 650, }, }); function mapStateToProps(state: AppState) { return { loading: state.tasks.activeTasks.loading, tasks: state.tasks.activeTasks.data, pollInterval: state.settings.pollInterval, }; } const mapDispatchToProps = { listActiveTasksAsync }; const connector = connect(mapStateToProps, mapDispatchToProps); type ReduxProps = ConnectedProps; interface Props { queue: string; // name of the queue } function ActiveTasksTable(props: Props & ReduxProps) { const { pollInterval, listActiveTasksAsync, queue } = props; const classes = useStyles(); const [page, setPage] = useState(0); const [pageSize, setPageSize] = useState(defaultPageSize); const handleChangePage = ( event: React.MouseEvent | null, newPage: number ) => { setPage(newPage); }; const handleChangeRowsPerPage = ( event: React.ChangeEvent ) => { setPageSize(parseInt(event.target.value, 10)); setPage(0); }; useEffect(() => { listActiveTasksAsync(queue); const interval = setInterval( () => listActiveTasksAsync(queue), pollInterval * 1000 ); return () => clearInterval(interval); }, [pollInterval, listActiveTasksAsync, queue]); if (props.tasks.length === 0) { return ( Info No active tasks at this time. ); } const columns = [ { label: "" }, { label: "ID" }, { label: "Type" }, { label: "Actions" }, ]; return ( {columns.map((col) => ( {col.label} ))} {/* TODO: loading and empty state */} {props.tasks.map((task) => ( ))}
); } const useRowStyles = makeStyles({ root: { "& > *": { borderBottom: "unset", }, }, }); function Row(props: { task: ActiveTask }) { const { task } = props; const [open, setOpen] = React.useState(false); const classes = useRowStyles(); return ( setOpen(!open)} > {open ? : } {task.id} {task.type} Payload {JSON.stringify(task.payload, null, 2)} ); } export default connector(ActiveTasksTable);