Skip to content

Commit 227c0c5

Browse files
committed
feat: enhance CategoryPieChart with dynamic description support
- Added a new prop `descriptionKey` to the CategoryPieChart component to allow dynamic localization of the chart description. - Updated the English and Chinese locale files to include a new translation for "breakdownByCategoryYearly". - Modified the ExpenseReportsPage to utilize the new descriptionKey for both current and yearly category pie charts.
1 parent 284d5e8 commit 227c0c5

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

src/components/charts/CategoryPieChart.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface CategoryPieChartProps {
1010
data: CategoryExpense[]
1111
currency: string
1212
className?: string
13+
descriptionKey: string
1314
}
1415

1516
// Define colors for different categories - using CSS variables for theme support
@@ -27,7 +28,7 @@ const COLORS = [
2728
"hsl(var(--chart-5))",
2829
]
2930

30-
export function CategoryPieChart({ data, currency, className }: CategoryPieChartProps) {
31+
export function CategoryPieChart({ data, currency, className, descriptionKey }: CategoryPieChartProps) {
3132
const { t } = useTranslation('reports')
3233
const { categories } = useSubscriptionStore()
3334

@@ -56,7 +57,7 @@ export function CategoryPieChart({ data, currency, className }: CategoryPieChart
5657
<Card className={className}>
5758
<CardHeader>
5859
<CardTitle className="text-lg">{t('chart.spendingByCategory')}</CardTitle>
59-
<CardDescription>{t('chart.breakdownByCategory')}</CardDescription>
60+
<CardDescription>{t(descriptionKey)}</CardDescription>
6061
</CardHeader>
6162
<CardContent className="px-2 sm:px-6">
6263
{data.length === 0 ? (

src/i18n/locales/en/reports.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"annualSpendingOverTime": "Annual spending over time",
3939
"annualSpendingByCategory": "Annual spending by category",
4040
"breakdownByCategory": "Breakdown of expenses by subscription category (Last 12 months)",
41+
"breakdownByCategoryYearly": "Breakdown of expenses by subscription category (Last 3 years)",
4142
"paymentDetails": "Payment Details",
4243
"viewPaymentRecords": "View all payment records for this period",
4344
"dailyAvg": "Daily Avg",

src/i18n/locales/zh-CN/reports.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"annualSpendingOverTime": "年度支出趋势",
3939
"annualSpendingByCategory": "按类别年度支出",
4040
"breakdownByCategory": "按订阅类别支出明细(过去12个月)",
41+
"breakdownByCategoryYearly": "按订阅类别支出明细(过去3年)",
4142
"paymentDetails": "支付详情",
4243
"viewPaymentRecords": "查看此期间的所有支付记录",
4344
"dailyAvg": "日均",

src/pages/ExpenseReportsPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ export function ExpenseReportsPage() {
473473
<CategoryPieChart
474474
data={categoryExpenses}
475475
currency={userCurrency}
476+
descriptionKey="chart.breakdownByCategory"
476477
/>
477478
)}
478479
</div>
@@ -522,6 +523,7 @@ export function ExpenseReportsPage() {
522523
<CategoryPieChart
523524
data={yearlyCategoryExpenses}
524525
currency={userCurrency}
526+
descriptionKey="chart.breakdownByCategoryYearly"
525527
/>
526528
)}
527529
</div>

0 commit comments

Comments
 (0)