Make barchart clickable

This commit is contained in:
Ken Hibino 2021-03-01 07:54:10 -08:00
parent 93ef083abc
commit 50b7af8421
2 changed files with 20 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import {
Legend, Legend,
ResponsiveContainer, ResponsiveContainer,
} from "recharts"; } from "recharts";
import { useHistory } from "react-router-dom";
import { queueDetailsPath } from "../paths";
interface Props { interface Props {
data: TaskBreakdown[]; data: TaskBreakdown[];
@ -24,9 +26,25 @@ interface TaskBreakdown {
} }
function QueueSizeChart(props: Props) { 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 ( return (
<ResponsiveContainer> <ResponsiveContainer>
<BarChart data={props.data} maxBarSize={120}> <BarChart
data={props.data}
maxBarSize={120}
onClick={handleClick}
style={{ cursor: "pointer" }}
>
<CartesianGrid strokeDasharray="3 3" /> <CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="queue" /> <XAxis dataKey="queue" />
<YAxis /> <YAxis />

View File

@ -196,6 +196,7 @@ export default function QueuesOverviewTable(props: Props) {
<TableBody> <TableBody>
{sortQueues(props.queues, cmpFunc).map((q) => ( {sortQueues(props.queues, cmpFunc).map((q) => (
<Row <Row
key={q.queue}
queue={q} queue={q}
onPauseClick={() => props.onPauseClick(q.queue)} onPauseClick={() => props.onPauseClick(q.queue)}
onResumeClick={() => props.onResumeClick(q.queue)} onResumeClick={() => props.onResumeClick(q.queue)}