Skip to content

Commit 676869d

Browse files
committed
refactor(frontend): extract ChartCard into its own component file
Move the ChartCard component out of chartUtils.ts into a dedicated ChartCard.tsx. This keeps chartUtils.ts as pure (non-React) utilities, improving Fast Refresh behavior and matching the many-small-files convention. Updates all import sites in data-explorer and heor.
1 parent fbec601 commit 676869d

7 files changed

Lines changed: 33 additions & 31 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ReactNode } from "react";
2+
3+
interface ChartCardProps {
4+
title?: string;
5+
subtitle?: string;
6+
children: ReactNode;
7+
className?: string;
8+
}
9+
10+
export function ChartCard({ title, subtitle, children, className }: ChartCardProps) {
11+
return (
12+
<div className={`rounded-xl border border-border-default bg-surface-raised p-6 ${className ?? ""}`}>
13+
{title && (
14+
<h3 className="mb-1 text-sm font-semibold uppercase tracking-wider text-text-muted">
15+
{title}
16+
</h3>
17+
)}
18+
{subtitle && (
19+
<p className="mb-4 text-xs text-text-ghost">{subtitle}</p>
20+
)}
21+
{!subtitle && title && <div className="mb-4" />}
22+
{children}
23+
</div>
24+
);
25+
}

frontend/src/features/data-explorer/components/charts/chartUtils.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { ReactNode } from "react";
2-
31
// ── Number formatting ────────────────────────────────────────────────────────
42

53
/** Format large numbers compactly: 1005787 → "1.0M" */
@@ -107,27 +105,3 @@ export function tableToDomain(table: string): string {
107105
}
108106

109107
// ── Shared wrapper ───────────────────────────────────────────────────────────
110-
111-
interface ChartCardProps {
112-
title?: string;
113-
subtitle?: string;
114-
children: ReactNode;
115-
className?: string;
116-
}
117-
118-
export function ChartCard({ title, subtitle, children, className }: ChartCardProps) {
119-
return (
120-
<div className={`rounded-xl border border-border-default bg-surface-raised p-6 ${className ?? ""}`}>
121-
{title && (
122-
<h3 className="mb-1 text-sm font-semibold uppercase tracking-wider text-text-muted">
123-
{title}
124-
</h3>
125-
)}
126-
{subtitle && (
127-
<p className="mb-4 text-xs text-text-ghost">{subtitle}</p>
128-
)}
129-
{!subtitle && title && <div className="mb-4" />}
130-
{children}
131-
</div>
132-
);
133-
}

frontend/src/features/data-explorer/pages/OverviewTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
} from "../hooks/useAchillesData";
1919
import {
2020
formatCompact,
21-
ChartCard,
2221
DOMAIN_COLORS,
2322
GENDER_COLORS,
2423
CHART,
2524
tableToDomain,
2625
formatTableName,
2726
} from "../components/charts/chartUtils";
27+
import { ChartCard } from "../components/charts/ChartCard";
2828
import { Sparkline } from "../components/charts/Sparkline";
2929
import { ProportionalBar } from "../components/charts/ProportionalBar";
3030
import { DemographicsPyramid } from "../components/charts/DemographicsPyramid";

frontend/src/features/heor/components/BudgetImpactChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
} from "recharts";
1111
import { useTranslation } from "react-i18next";
1212
import {
13-
ChartCard,
1413
CHART,
1514
TOOLTIP_CLS,
1615
formatCompact,
1716
} from "@/features/data-explorer/components/charts/chartUtils";
17+
import { ChartCard } from "@/features/data-explorer/components/charts/ChartCard";
1818
import type { HeorResult } from "../types";
1919

2020
interface Props {

frontend/src/features/heor/components/CostEffectivenessPlane.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMemo } from "react";
22
import { useTranslation } from "react-i18next";
3-
import { ChartCard, CHART, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
3+
import { CHART, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
4+
import { ChartCard } from "@/features/data-explorer/components/charts/ChartCard";
45
import type { HeorResult } from "../types";
56

67
interface Props {

frontend/src/features/heor/components/ScenarioComparisonChart.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Cell,
1010
} from "recharts";
1111
import { useTranslation } from "react-i18next";
12-
import { ChartCard, CHART, TOOLTIP_CLS, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
12+
import { CHART, TOOLTIP_CLS, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
13+
import { ChartCard } from "@/features/data-explorer/components/charts/ChartCard";
1314
import type { HeorResult } from "../types";
1415

1516
interface Props {

frontend/src/features/heor/components/TornadoDiagram.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
Cell,
1111
} from "recharts";
1212
import { useTranslation } from "react-i18next";
13-
import { ChartCard, CHART, TOOLTIP_CLS, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
13+
import { CHART, TOOLTIP_CLS, formatCompact } from "@/features/data-explorer/components/charts/chartUtils";
14+
import { ChartCard } from "@/features/data-explorer/components/charts/ChartCard";
1415
import type { TornadoEntry } from "../types";
1516
import { getHeorParameterTypeLabel } from "../lib/i18n";
1617

0 commit comments

Comments
 (0)