mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 11:06:40 +07:00
feat: custom year range on Cash Flow and Reports, drop redundant 12m preset
"This year" and "12 months" were two different ways of showing roughly the same recent window, which read as duplicated. Replaced the "12m" preset with "custom": pick an arbitrary fromYear-toYear span via a new YearRangeSelector (two dropdowns built on the same internal component YearSelector already uses). Also de-duplicated the RangePreset/computeRange logic that was copied verbatim between CashFlowPage and ReportsPage into shared lib/dateRange.ts — both pages had the identical bug/duplication.
This commit is contained in:
33
frontend/src/lib/dateRange.ts
Normal file
33
frontend/src/lib/dateRange.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/** Shared by CashFlowPage and ReportsPage — both offer the same four
|
||||
* period presets over their respective date-ranged endpoints. */
|
||||
export type RangePreset = "all" | "this_year" | "5y" | "custom";
|
||||
|
||||
export interface CustomYearRange {
|
||||
fromYear: number;
|
||||
toYear: number;
|
||||
}
|
||||
|
||||
function isoDate(date: Date): string {
|
||||
return date.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
export function computeRange(
|
||||
preset: RangePreset,
|
||||
custom?: CustomYearRange
|
||||
): { startDate?: string; endDate?: string } {
|
||||
const today = new Date();
|
||||
switch (preset) {
|
||||
case "all":
|
||||
return {};
|
||||
case "this_year":
|
||||
return { startDate: `${today.getFullYear()}-01-01`, endDate: isoDate(today) };
|
||||
case "5y": {
|
||||
const start = new Date(today.getFullYear() - 5, today.getMonth(), 1);
|
||||
return { startDate: isoDate(start), endDate: isoDate(today) };
|
||||
}
|
||||
case "custom": {
|
||||
if (!custom) return {};
|
||||
return { startDate: `${custom.fromYear}-01-01`, endDate: `${custom.toYear}-12-31` };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,9 +169,9 @@ const ru = {
|
||||
"reports.expenseGroup": "Расходы",
|
||||
"reports.incomeGroup": "Доходы",
|
||||
"reports.rangeAll": "Всё время",
|
||||
"reports.range5y": "5 лет",
|
||||
"reports.range12m": "12 мес",
|
||||
"reports.rangeThisYear": "Этот год",
|
||||
"reports.range5y": "5 лет",
|
||||
"reports.rangeCustom": "Диапазон лет",
|
||||
"reports.transactionsTitle": "Транзакции",
|
||||
"reports.defaultChartTitle": "Расходы по категории",
|
||||
"reports.averagePerMonth": "{{amount}}/мес в среднем",
|
||||
@@ -491,9 +491,9 @@ const en: Record<keyof typeof ru, string> = {
|
||||
"reports.expenseGroup": "Expenses",
|
||||
"reports.incomeGroup": "Income",
|
||||
"reports.rangeAll": "All time",
|
||||
"reports.range5y": "5 years",
|
||||
"reports.range12m": "12 mo",
|
||||
"reports.rangeThisYear": "This year",
|
||||
"reports.range5y": "5 years",
|
||||
"reports.rangeCustom": "Year range",
|
||||
"reports.transactionsTitle": "Transactions",
|
||||
"reports.defaultChartTitle": "Spending by category",
|
||||
"reports.averagePerMonth": "{{amount}}/mo average",
|
||||
|
||||
Reference in New Issue
Block a user