78 lines
2.4 KiB
React
78 lines
2.4 KiB
React
// components/generic/Dashboard/DashboardSection.jsx
|
|
|
|
import { StatGrid } from "./StatGrid";
|
|
import { PieBreakdown } from "./PieBreakdown";
|
|
import { BarBreakdown } from "./BarBreakdown";
|
|
|
|
/**
|
|
* Renders a titled section with a stat grid and breakdown charts.
|
|
*
|
|
* @param {Object} props
|
|
* @param {string} props.title
|
|
* @param {Array} props.stats [{ key, label, value, icon? }]
|
|
* @param {Array} [props.breakdowns] [{ key, label, chartType, data[] }]
|
|
* @param {Object} [props.iconMap] { [statKey]: <ReactNode> }
|
|
* @param {Object} [props.linkMap] { [statKey]: () => void } — stat card click handlers
|
|
* @param {Object} [props.chartLinkMap] { [breakdownKey]: (entry) => void } — chart segment click handlers
|
|
* @param {string} [props.className]
|
|
*
|
|
* @example
|
|
* <DashboardSection
|
|
* title="Users"
|
|
* stats={dashboard.users.stats}
|
|
* breakdowns={dashboard.users.breakdowns}
|
|
* iconMap={USER_ICON_MAP}
|
|
* linkMap={{
|
|
* total: () => navigate('/admin/users/all'),
|
|
* archived: () => navigate('/admin/users/all/archived'),
|
|
* }}
|
|
* chartLinkMap={{
|
|
* acc_type: (entry) => navigate(`/admin/users/all`),
|
|
* }}
|
|
* />
|
|
*/
|
|
export function DashboardSection({
|
|
title,
|
|
stats = [],
|
|
breakdowns = [],
|
|
iconMap = {},
|
|
linkMap = {},
|
|
chartLinkMap = {},
|
|
chartHeight = 240,
|
|
className = "",
|
|
}) {
|
|
return (
|
|
<section className={`flex flex-col gap-4 ${className}`}>
|
|
{title && <h2 className="text-base font-medium">{title}</h2>}
|
|
|
|
{stats.length > 0 && (
|
|
<StatGrid stats={stats} iconMap={iconMap} linkMap={linkMap} />
|
|
)}
|
|
|
|
{breakdowns.length > 0 && (
|
|
<div className={`grid gap-4 ${breakdowns.length > 1 ? "sm:grid-cols-2" : "grid-cols-1"}`}>
|
|
{breakdowns.map((b) =>
|
|
b.chartType === "bar" ? (
|
|
<BarBreakdown
|
|
key={b.key}
|
|
label={b.label}
|
|
data={b.data}
|
|
onBarClick={chartLinkMap[b.key]}
|
|
height={b.height ?? chartHeight}
|
|
yAxisWidth={b.yAxisWidth}
|
|
/>
|
|
) : (
|
|
<PieBreakdown
|
|
key={b.key}
|
|
label={b.label}
|
|
data={b.data}
|
|
onSliceClick={chartLinkMap[b.key]}
|
|
height={b.height ?? chartHeight}
|
|
/>
|
|
)
|
|
)}
|
|
</div>
|
|
)}
|
|
</section>
|
|
);
|
|
} |