merge new_starr_app@qas history into apps/web
git-subtree-dir: apps/web git-subtree-mainline:eaa6d2276agit-subtree-split:459af9d46a
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// 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 = {},
|
||||
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]}
|
||||
/>
|
||||
) : (
|
||||
<PieBreakdown
|
||||
key={b.key}
|
||||
label={b.label}
|
||||
data={b.data}
|
||||
onSliceClick={chartLinkMap[b.key]}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user