Files
asynqmon/ui/src/components/QueueSizeChart.tsx
2021-03-01 15:14:12 -08:00

64 lines
1.7 KiB
TypeScript

import React from "react";
import {
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
ResponsiveContainer,
} from "recharts";
import { useHistory } from "react-router-dom";
import { queueDetailsPath } from "../paths";
interface Props {
data: TaskBreakdown[];
}
interface TaskBreakdown {
queue: string; // name of the queue.
active: number; // number of active tasks in the queue.
pending: number; // number of pending tasks in the queue.
scheduled: number; // number of scheduled tasks in the queue.
retry: number; // number of retry tasks in the queue.
archived: number; // number of archived tasks in the queue.
}
function QueueSizeChart(props: Props) {
const handleClick = (params: { activeLabel?: string } | null) => {
const allQueues = props.data.map((b) => b.queue);
if (
params &&
params.activeLabel &&
allQueues.includes(params.activeLabel)
) {
history.push(queueDetailsPath(params.activeLabel));
}
};
const history = useHistory();
return (
<ResponsiveContainer>
<BarChart
data={props.data}
maxBarSize={120}
onClick={handleClick}
style={{ cursor: "pointer" }}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="queue" />
<YAxis />
<Tooltip />
<Legend />
<Bar dataKey="active" stackId="a" fill="#1967d2" />
<Bar dataKey="pending" stackId="a" fill="#669df6" />
<Bar dataKey="scheduled" stackId="a" fill="#fdd663" />
<Bar dataKey="retry" stackId="a" fill="#f666a9" />
<Bar dataKey="archived" stackId="a" fill="#ac4776" />
</BarChart>
</ResponsiveContainer>
);
}
export default QueueSizeChart;