"use client"; import { BarChart, Bar, XAxis, YAxis, Tooltip as RechartsTooltip, ResponsiveContainer, CartesianGrid, } from "recharts"; export interface HistBucket { label: string; time: number; endTime: number; count: number; success: number; error: number; } export interface RequestsHistogramChartProps { data: HistBucket[]; onBarClick: (bucket: HistBucket | undefined) => void; } /** * Histogram chart for the requests page, isolated into its own module so * the parent page can `next/dynamic` import it. Pulling recharts into a * separate chunk keeps the initial JS bundle of the requests page well * below the budget — the entire library lands in the browser only after * the user lands on this view. */ export default function RequestsHistogramChart({ data, onBarClick, }: RequestsHistogramChartProps) { return ( { // Recharts types `activeTooltipIndex` as `string | number | undefined` // depending on how the chart is configured; coerce to a numeric // index and bounds-check before reading from `data` to keep the // bracket access type-safe. const raw = state?.activeTooltipIndex; const idx = typeof raw === "number" ? raw : Number(raw); if (!Number.isInteger(idx) || idx < 0 || idx >= data.length) return; onBarClick(data[idx]); }} > ); }