2
0
mirror of https://github.com/hibiken/asynqmon.git synced 2026-06-21 21:36:01 +08:00
Files
asynqmon/ui/src/components/TasksTable.tsx

173 lines
4.9 KiB
TypeScript
Raw Normal View History

2020-11-24 06:54:00 -08:00
import React from "react";
import { connect, ConnectedProps } from "react-redux";
import { makeStyles } from "@material-ui/core/styles";
2021-01-12 16:41:14 -08:00
import Typography from "@material-ui/core/Typography";
import Paper from "@material-ui/core/Paper";
2021-01-24 16:33:46 -08:00
import Chip from "@material-ui/core/Chip";
2020-11-24 06:54:00 -08:00
import ActiveTasksTable from "./ActiveTasksTable";
import PendingTasksTable from "./PendingTasksTable";
import ScheduledTasksTable from "./ScheduledTasksTable";
import RetryTasksTable from "./RetryTasksTable";
import ArchivedTasksTable from "./ArchivedTasksTable";
2020-11-24 06:54:00 -08:00
import { useHistory } from "react-router-dom";
import { queueDetailsPath } from "../paths";
import { QueueInfo } from "../reducers/queuesReducer";
import { AppState } from "../store";
2021-04-19 06:56:00 -07:00
import { isDarkTheme } from "../theme";
2020-11-24 06:54:00 -08:00
interface TabPanelProps {
children?: React.ReactNode;
selected: string; // currently selected value
value: string; // tab panel will be shown if selected value equals to the value
}
function TabPanel(props: TabPanelProps) {
const { children, value, selected, ...other } = props;
return (
2021-01-12 16:41:14 -08:00
<div
2020-11-24 06:54:00 -08:00
role="tabpanel"
hidden={value !== selected}
id={`scrollable-auto-tabpanel-${selected}`}
aria-labelledby={`scrollable-auto-tab-${selected}`}
2021-01-12 16:41:14 -08:00
style={{ flex: 1, overflowY: "scroll" }}
2020-11-24 06:54:00 -08:00
{...other}
>
{value === selected && children}
2021-01-12 16:41:14 -08:00
</div>
2020-11-24 06:54:00 -08:00
);
}
function mapStatetoProps(state: AppState, ownProps: Props) {
// TODO: Add loading state for each queue.
const queueInfo = state.queues.data.find(
(q: QueueInfo) => q.name === ownProps.queue
);
const currentStats = queueInfo
? queueInfo.currentStats
: {
queue: ownProps.queue,
paused: false,
size: 0,
active: 0,
pending: 0,
scheduled: 0,
retry: 0,
archived: 0,
2020-11-24 06:54:00 -08:00
processed: 0,
failed: 0,
timestamp: "n/a",
};
return { currentStats };
}
const connector = connect(mapStatetoProps);
type ReduxProps = ConnectedProps<typeof connector>;
interface Props {
queue: string;
selected: string;
}
2021-01-12 16:41:14 -08:00
const useStyles = makeStyles((theme) => ({
container: {
width: "100%",
height: "100%",
2021-01-15 12:09:55 -08:00
background: theme.palette.background.paper,
2021-01-12 16:41:14 -08:00
},
2021-01-24 16:33:46 -08:00
header: {
display: "flex",
alignItems: "center",
paddingTop: theme.spacing(1),
},
2021-01-12 16:41:14 -08:00
heading: {
2021-01-23 22:36:19 -08:00
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1),
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
2021-01-12 16:41:14 -08:00
},
2021-01-24 16:33:46 -08:00
chip: {
marginLeft: theme.spacing(1),
2021-01-12 16:41:14 -08:00
},
2021-01-24 16:33:46 -08:00
taskcount: {
fontSize: "12px",
color: theme.palette.text.secondary,
2021-04-19 06:56:00 -07:00
background: isDarkTheme(theme)
? "#303030"
: theme.palette.background.default,
2021-01-23 22:36:19 -08:00
textAlign: "center",
2021-01-24 16:33:46 -08:00
padding: "3px 6px",
borderRadius: "10px",
marginLeft: "2px",
2021-01-12 16:41:14 -08:00
},
}));
2020-11-24 06:54:00 -08:00
function TasksTable(props: Props & ReduxProps) {
const { currentStats } = props;
const classes = useStyles();
const history = useHistory();
2021-01-24 16:33:46 -08:00
const chips = [
{ key: "active", label: "Active", count: currentStats.active },
{ key: "pending", label: "Pending", count: currentStats.pending },
{ key: "scheduled", label: "Scheduled", count: currentStats.scheduled },
{ key: "retry", label: "Retry", count: currentStats.retry },
{ key: "archived", label: "Archived", count: currentStats.archived },
];
2020-11-24 06:54:00 -08:00
return (
2021-01-23 22:36:19 -08:00
<Paper variant="outlined" className={classes.container}>
2021-01-24 16:33:46 -08:00
<div className={classes.header}>
<Typography color="textPrimary" className={classes.heading}>
Tasks
</Typography>
<div>
{chips.map((c) => (
<Chip
2021-01-29 22:25:01 -08:00
key={c.key}
2021-01-24 16:33:46 -08:00
className={classes.chip}
label={
<div>
{c.label} <span className={classes.taskcount}>{c.count}</span>
</div>
}
variant="outlined"
color={props.selected === c.key ? "primary" : "default"}
onClick={() => history.push(queueDetailsPath(props.queue, c.key))}
/>
))}
</div>
2021-01-12 16:41:14 -08:00
</div>
2020-11-24 06:54:00 -08:00
<TabPanel value="active" selected={props.selected}>
2021-01-24 16:33:46 -08:00
<ActiveTasksTable queue={props.queue} />
2020-11-24 06:54:00 -08:00
</TabPanel>
<TabPanel value="pending" selected={props.selected}>
2021-01-24 16:33:46 -08:00
<PendingTasksTable
queue={props.queue}
totalTaskCount={currentStats.pending}
/>
2020-11-24 06:54:00 -08:00
</TabPanel>
<TabPanel value="scheduled" selected={props.selected}>
2021-01-24 16:33:46 -08:00
<ScheduledTasksTable
queue={props.queue}
totalTaskCount={currentStats.scheduled}
/>
2020-11-24 06:54:00 -08:00
</TabPanel>
<TabPanel value="retry" selected={props.selected}>
2021-01-24 16:33:46 -08:00
<RetryTasksTable
queue={props.queue}
totalTaskCount={currentStats.retry}
/>
2020-11-24 06:54:00 -08:00
</TabPanel>
<TabPanel value="archived" selected={props.selected}>
2021-01-24 16:33:46 -08:00
<ArchivedTasksTable
queue={props.queue}
totalTaskCount={currentStats.archived}
/>
2020-11-24 06:54:00 -08:00
</TabPanel>
2021-01-23 22:36:19 -08:00
</Paper>
2020-11-24 06:54:00 -08:00
);
}
export default connector(TasksTable);