2
0
mirror of https://github.com/hibiken/asynqmon.git synced 2026-04-20 00:07:12 +08:00
Files
asynqmon/ui/src/components/RetryTasksTable.tsx

198 lines
6.7 KiB
TypeScript
Raw Normal View History

2022-01-14 22:46:49 -08:00
import Checkbox from "@material-ui/core/Checkbox";
import IconButton from "@material-ui/core/IconButton";
2020-11-24 06:54:00 -08:00
import TableCell from "@material-ui/core/TableCell";
2022-01-14 22:46:49 -08:00
import TableRow from "@material-ui/core/TableRow";
2020-12-23 14:38:24 -08:00
import Tooltip from "@material-ui/core/Tooltip";
import ArchiveIcon from "@material-ui/icons/Archive";
2022-01-14 22:46:49 -08:00
import DeleteIcon from "@material-ui/icons/Delete";
2022-01-12 22:51:16 -08:00
import FileCopyOutlinedIcon from "@material-ui/icons/FileCopyOutlined";
2020-12-23 14:38:24 -08:00
import MoreHorizIcon from "@material-ui/icons/MoreHoriz";
2022-01-14 22:46:49 -08:00
import PlayArrowIcon from "@material-ui/icons/PlayArrow";
import React from "react";
2022-01-14 22:46:49 -08:00
import { connect, ConnectedProps } from "react-redux";
import { useHistory } from "react-router-dom";
import { taskRowsPerPageChange } from "../actions/settingsActions";
2022-01-12 22:51:16 -08:00
import {
archiveAllRetryTasksAsync,
archiveRetryTaskAsync,
batchArchiveRetryTasksAsync,
batchDeleteRetryTasksAsync,
batchRunRetryTasksAsync,
deleteAllRetryTasksAsync,
deleteRetryTaskAsync,
listRetryTasksAsync,
runAllRetryTasksAsync,
runRetryTaskAsync,
} from "../actions/tasksActions";
import TasksTable, { RowProps, useRowStyles } from "./TasksTable";
2022-01-14 22:46:49 -08:00
import { taskDetailsPath } from "../paths";
import { AppState } from "../store";
2020-12-23 14:38:24 -08:00
import { TableColumn } from "../types/table";
2022-01-14 22:46:49 -08:00
import { durationBefore, prettifyPayload, uuidPrefix } from "../utils";
import SyntaxHighlighter from "./SyntaxHighlighter";
2020-11-24 06:54:00 -08:00
function mapStateToProps(state: AppState) {
return {
loading: state.tasks.retryTasks.loading,
2021-01-26 21:25:42 -08:00
error: state.tasks.retryTasks.error,
2020-11-24 06:54:00 -08:00
tasks: state.tasks.retryTasks.data,
2020-12-18 12:48:05 -08:00
batchActionPending: state.tasks.retryTasks.batchActionPending,
allActionPending: state.tasks.retryTasks.allActionPending,
2020-11-24 06:54:00 -08:00
pollInterval: state.settings.pollInterval,
pageSize: state.settings.taskRowsPerPage,
2020-11-24 06:54:00 -08:00
};
}
const mapDispatchToProps = {
batchDeleteTasks: batchDeleteRetryTasksAsync,
batchRunTasks: batchRunRetryTasksAsync,
batchArchiveTasks: batchArchiveRetryTasksAsync,
deleteAllTasks: deleteAllRetryTasksAsync,
runAllTasks: runAllRetryTasksAsync,
archiveAllTasks: archiveAllRetryTasksAsync,
listTasks: listRetryTasksAsync,
deleteTask: deleteRetryTaskAsync,
runTask: runRetryTaskAsync,
archiveTask: archiveRetryTaskAsync,
taskRowsPerPageChange,
};
2020-11-24 06:54:00 -08:00
const connector = connect(mapStateToProps, mapDispatchToProps);
type ReduxProps = ConnectedProps<typeof connector>;
interface Props {
queue: string; // name of the queue.
totalTaskCount: number; // totoal number of scheduled tasks.
}
const columns: TableColumn[] = [
{ key: "id", label: "ID", align: "left" },
{ key: "type", label: "Type", align: "left" },
{ key: "payload", label: "Payload", align: "left" },
{ key: "retry_in", label: "Retry In", align: "left" },
{ key: "last_error", label: "Last Error", align: "left" },
{ key: "retried", label: "Retried", align: "right" },
{ key: "max_retry", label: "Max Retry", align: "right" },
{ key: "actions", label: "Actions", align: "center" },
];
function Row(props: RowProps) {
2020-11-24 06:54:00 -08:00
const { task } = props;
const classes = useRowStyles();
const history = useHistory();
2020-11-24 06:54:00 -08:00
return (
<TableRow
key={task.id}
className={classes.root}
selected={props.isSelected}
onClick={() => history.push(taskDetailsPath(task.queue, task.id))}
>
{!window.READ_ONLY && (
<TableCell padding="checkbox" onClick={(e) => e.stopPropagation()}>
<IconButton>
<Checkbox
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
props.onSelectChange(event.target.checked)
}
checked={props.isSelected}
/>
</IconButton>
</TableCell>
)}
2022-01-14 22:46:49 -08:00
<TableCell component="th" scope="row" className={classes.idCell}>
<div className={classes.IdGroup}>
2022-01-12 22:51:16 -08:00
{uuidPrefix(task.id)}
<Tooltip title="Copy full ID to clipboard">
<IconButton
onClick={(e) => {
e.stopPropagation();
navigator.clipboard.writeText(task.id);
}}
size="small"
className={classes.copyButton}
>
<FileCopyOutlinedIcon fontSize="small" />
</IconButton>
</Tooltip>
2022-01-14 22:46:49 -08:00
</div>
2021-01-30 07:01:39 -08:00
</TableCell>
<TableCell>{task.type}</TableCell>
<TableCell>
<SyntaxHighlighter
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
2020-12-23 14:38:24 -08:00
>
2021-12-14 00:39:55 +00:00
{prettifyPayload(task.payload)}
2021-01-30 07:01:39 -08:00
</SyntaxHighlighter>
</TableCell>
<TableCell>{durationBefore(task.next_process_at)}</TableCell>
<TableCell>{task.error_message}</TableCell>
<TableCell align="right">{task.retried}</TableCell>
<TableCell align="right">{task.max_retry}</TableCell>
{!window.READ_ONLY && (
<TableCell
align="center"
className={classes.actionCell}
onMouseEnter={props.onActionCellEnter}
onMouseLeave={props.onActionCellLeave}
onClick={(e) => e.stopPropagation()}
>
{props.showActions ? (
<React.Fragment>
<Tooltip title="Delete">
<IconButton
onClick={props.onDeleteClick}
disabled={task.requestPending || props.allActionPending}
size="small"
className={classes.actionButton}
>
<DeleteIcon fontSize="small" />
</IconButton>
</Tooltip>
<Tooltip title="Archive">
<IconButton
onClick={props.onArchiveClick}
disabled={task.requestPending || props.allActionPending}
size="small"
className={classes.actionButton}
>
<ArchiveIcon fontSize="small" />
</IconButton>
</Tooltip>
<Tooltip title="Run">
<IconButton
onClick={props.onRunClick}
disabled={task.requestPending || props.allActionPending}
size="small"
className={classes.actionButton}
>
<PlayArrowIcon fontSize="small" />
</IconButton>
</Tooltip>
</React.Fragment>
) : (
<IconButton size="small" onClick={props.onActionCellEnter}>
<MoreHorizIcon fontSize="small" />
</IconButton>
)}
</TableCell>
)}
2021-01-30 07:01:39 -08:00
</TableRow>
2020-11-24 06:54:00 -08:00
);
}
function RetryTasksTable(props: Props & ReduxProps) {
return (
<TasksTable
taskState="retry"
columns={columns}
renderRow={(rowProps: RowProps) => <Row {...rowProps} />}
{...props}
/>
);
}
2020-11-24 06:54:00 -08:00
export default connector(RetryTasksTable);