A local-first personal finance app
[AI] Allow click-through on reports split by interval (#9175)
James N52ac1f91e5b8
diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsxindex f9da791e3c..87a89f1ceb 100644--- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx+++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx@@ -105,8 +105,11 @@ export function ChooseGraph({style={graphStyle}compact={compact}data={data}+ filters={filters}balanceTypeOp={balanceTypeOp}viewLabels={viewLabels}+ showHiddenCategories={showHiddenCategories}+ showOffBudget={showOffBudget}showTooltip={showTooltip}/>);diff --git a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsxindex 0514af3566..aae6e34115 100644--- a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx@@ -1,4 +1,4 @@-import React from 'react';+import React, { useState } from 'react';import type { CSSProperties, SVGAttributes } from 'react';import { useTranslation } from 'react-i18next';@@ -7,6 +7,8 @@ import { theme } from '@actual-app/components/theme';import type {balanceTypeOpType,DataEntity,+ IntervalEntity,+ RuleConditionEntity,} from '@actual-app/core/types/models';import { css } from '@emotion/css';import {@@ -23,12 +25,16 @@ import type { LabelProps } from 'recharts';import { FinancialText } from '#components/FinancialText';import { useRechartsAnimation } from '#components/reports/chart-theme';import { Container } from '#components/reports/Container';+import { useAccounts } from '#hooks/useAccounts';+import { useCategories } from '#hooks/useCategories';import { useFormat } from '#hooks/useFormat';import type { FormatType } from '#hooks/useFormat';+import { useNavigate } from '#hooks/useNavigate';import { usePrivacyMode } from '#hooks/usePrivacyMode';import { adjustTextSize } from './adjustTextSize';import { renderCustomLabel } from './renderCustomLabel';+import { showActivity } from './showActivity';type PayloadItem = {payload: {@@ -174,24 +180,42 @@ const customLabel = ({return renderCustomLabel(calcX, calcY, textAnchor, display, textSize);};+// Recharts calls activeDot handlers with the dot's props (including the data+// point) as the second argument, although its types declare a MouseEvent+function hasIntervalPayload(+ value: unknown,+): value is { payload: IntervalEntity } {+ return value !== null && typeof value === 'object' && 'payload' in value;+}+type AreaGraphProps = {style?: CSSProperties;data: DataEntity;+ filters?: RuleConditionEntity[];balanceTypeOp: balanceTypeOpType;compact?: boolean;viewLabels: boolean;+ showHiddenCategories?: boolean;+ showOffBudget?: boolean;showTooltip?: boolean;};export function AreaGraph({style,data,+ filters = [],balanceTypeOp,compact,viewLabels,+ showHiddenCategories = false,+ showOffBudget = false,showTooltip = true,}: AreaGraphProps) {const format = useFormat();+ const navigate = useNavigate();+ const { data: categories = { grouped: [], list: [] } } = useCategories();+ const { data: accounts = [] } = useAccounts();+ const [pointer, setPointer] = useState('');const animationProps = useRechartsAnimation({ animationDuration: 1000 });const privacyMode = usePrivacyMode();@@ -251,6 +275,7 @@ export function AreaGraph({width={width}height={height}data={data.intervalData}+ style={{ cursor: pointer }}margin={{top: 0,right: labelsMargin,@@ -334,7 +359,33 @@ export function AreaGraph({<Areatype="linear"dot={false}- activeDot={false}+ activeDot={{+ r: pointer && !compact ? 8 : 3,+ onMouseEnter: () => setPointer('pointer'),+ onMouseLeave: () => setPointer(''),+ onClick: (_, dot: unknown) => {+ const intervalItem = hasIntervalPayload(dot)+ ? dot.payload+ : undefined;+ const startDate =+ intervalItem?.intervalStartDate ?? data.startDate;++ if (((compact && showTooltip) || !compact) && startDate) {+ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp,+ filters,+ showHiddenCategories,+ showOffBudget,+ type: 'totals',+ startDate,+ endDate: intervalItem?.intervalEndDate ?? data.endDate,+ });+ }+ },+ }}{...animationProps}dataKey={balanceTypeOp}stroke={`url(#stroke${balanceTypeOp})`}diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsxindex 2e07b346d0..a8e03a178c 100644--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx@@ -193,6 +193,18 @@ function hasUncategorizedId(value: unknown): value is ReportDrilldownPayload {);}+// Recharts types the bar's payload as `any`, so check it holds interval dates+type IntervalDrilldownPayload = Pick<+ IntervalEntity,+ 'intervalStartDate' | 'intervalEndDate'+>;++function hasIntervalDates(value: unknown): value is IntervalDrilldownPayload {+ return (+ value !== null && typeof value === 'object' && 'intervalStartDate' in value+ );+}+type BarGraphProps = {style?: CSSProperties;data: DataEntity;@@ -317,33 +329,48 @@ export function BarGraph({stackId="a"{...animationProps}onMouseLeave={() => setPointer('')}- onMouseEnter={() =>- groupBy !== 'Interval' && setPointer('pointer')- }+ onMouseEnter={() => setPointer('pointer')}onClick={item => {+ if (compact && !showTooltip) {+ return;+ }++ const intervalPayload = hasIntervalDates(item.payload)+ ? item.payload+ : undefined;const itemPayload = hasUncategorizedId(item.payload)? item.payload: undefined;- return (- ((compact && showTooltip) || !compact) &&- groupBy !== 'Interval' &&- showActivity({- navigate,- categories,- accounts,- balanceTypeOp,- filters,- showHiddenCategories,- showOffBudget,- type: 'totals',- startDate: data.startDate,- endDate: data.endDate,- field: groupBy.toLowerCase(),- id: item.id,- uncategorizedId: itemPayload?.uncategorizedId,- })- );+ // Interval bars drill down by their own date range instead of a field+ const drilldown =+ groupBy === 'Interval'+ ? {+ startDate:+ intervalPayload?.intervalStartDate ??+ data.startDate,+ endDate:+ intervalPayload?.intervalEndDate ?? data.endDate,+ }+ : {+ startDate: data.startDate,+ endDate: data.endDate,+ field: groupBy.toLowerCase(),+ id: item.id,+ uncategorizedId: itemPayload?.uncategorizedId,+ };++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp,+ filters,+ showHiddenCategories,+ showOffBudget,+ type: 'totals',+ ...drilldown,+ });}}shape={(props: BarShapeProps) => (<Rectanglediff --git a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsxindex eb44d9257e..ca9e22bbb4 100644--- a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx@@ -31,7 +31,8 @@ import { showActivity } from './showActivity';const RADIAN = Math.PI / 180;type ClickablePieItem = PieSectorDataItem &- Partial<Pick<GroupedEntity, 'id' | 'uncategorizedId'>>;+ Partial<Pick<GroupedEntity, 'id' | 'uncategorizedId'>> &+ Partial<Pick<IntervalEntity, 'intervalStartDate' | 'intervalEndDate'>>;// ---------------------------------------------------------------------------// Dimension helpers@@ -665,9 +666,7 @@ export function DonutGraph({onMouseEnter={(_, index) => {if (!isTouchDevice()) {setActiveIndex(index);- if (groupBy !== 'Interval') {- setPointer('pointer');- }+ setPointer('pointer');}}}onClick={(item: ClickablePieItem, index) => {@@ -675,10 +674,25 @@ export function DonutGraph({setActiveIndex(index);}if (- groupBy !== 'Interval' &&(!isTouchDevice() || activeIndex === index) &&((compact && showTooltip) || !compact)) {+ // Interval slices drill down by their own date range instead of a field+ const drilldown =+ groupBy === 'Interval'+ ? {+ startDate:+ item.intervalStartDate ?? data.startDate,+ endDate: item.intervalEndDate ?? data.endDate,+ }+ : {+ startDate: data.startDate,+ endDate: data.endDate,+ field: groupBy.toLowerCase(),+ id: item.id,+ uncategorizedId: item.uncategorizedId,+ };+showActivity({navigate,categories,@@ -688,11 +702,7 @@ export function DonutGraph({showHiddenCategories,showOffBudget,type: 'totals',- startDate: data.startDate,- endDate: data.endDate,- field: groupBy.toLowerCase(),- id: item.id,- uncategorizedId: item.uncategorizedId,+ ...drilldown,});}}}diff --git a/packages/desktop-client/src/components/reports/graphs/showActivity.test.ts b/packages/desktop-client/src/components/reports/graphs/showActivity.test.tsindex 12ec90394b..cba503451a 100644--- a/packages/desktop-client/src/components/reports/graphs/showActivity.test.ts+++ b/packages/desktop-client/src/components/reports/graphs/showActivity.test.ts@@ -167,4 +167,107 @@ describe('showActivity', () => {type: 'id',});});++ it.each([+ // Deposit and Payment charts+ { balanceTypeOp: 'totalAssets', type: 'totals', inflow: true },+ { balanceTypeOp: 'totalDebts', type: 'totals', inflow: false },+ // Deposits and Payments columns of a Net table+ { balanceTypeOp: 'totalTotals', type: 'assets', inflow: true },+ { balanceTypeOp: 'totalTotals', type: 'debts', inflow: false },+ ] as const)(+ 'filters a $balanceTypeOp $type interval drilldown to that interval and direction',+ ({ balanceTypeOp, type, inflow }) => {+ const navigate = vi.fn();++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp,+ filters: [],+ showHiddenCategories: true,+ showOffBudget: true,+ type,+ startDate: '2026-05-01',+ endDate: '2026-05-31',+ });++ const [, options] = navigate.mock.calls[0];++ expect(options.state.filterConditions).toEqual([+ { field: 'date', op: 'gte', value: '2026-05-01', type: 'date' },+ {+ field: 'date',+ op: 'lte',+ value: '2026-05-31',+ options: { date: true },+ },+ {+ field: 'amount',+ op: 'gte',+ value: 0,+ options: { type: 'number', inflow, outflow: !inflow },+ },+ ]);+ },+ );++ it.each([+ { interval: 'Monthly', startDate: '2026-06', expected: '2026-06-01' },+ { interval: 'Yearly', startDate: '2026', expected: '2026-01-01' },+ ])(+ 'expands a $interval interval key into a full start date',+ ({ startDate, expected }) => {+ const navigate = vi.fn();++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp: 'totalTotals',+ filters: [],+ showHiddenCategories: true,+ showOffBudget: true,+ type: 'totals',+ startDate,+ endDate: '2026-06-30',+ });++ const [, options] = navigate.mock.calls[0];++ expect(options.state.filterConditions).toContainEqual({+ field: 'date',+ op: 'gte',+ value: expected,+ type: 'date',+ });+ },+ );++ it.each(['totalTotals', 'netAssets', 'netDebts'] as const)(+ 'includes all transactions for a %s interval drilldown',+ balanceTypeOp => {+ const navigate = vi.fn();++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp,+ filters: [],+ showHiddenCategories: true,+ showOffBudget: true,+ type: 'totals',+ startDate: '2026-05-01',+ endDate: '2026-05-31',+ });++ const [, options] = navigate.mock.calls[0];++ expect(+ options.state.filterConditions.map((f: { field: string }) => f.field),+ ).toEqual(['date', 'date']);+ },+ );});diff --git a/packages/desktop-client/src/components/reports/graphs/showActivity.ts b/packages/desktop-client/src/components/reports/graphs/showActivity.tsindex 2080db61d5..07f9161ff8 100644--- a/packages/desktop-client/src/components/reports/graphs/showActivity.ts+++ b/packages/desktop-client/src/components/reports/graphs/showActivity.ts@@ -107,7 +107,11 @@ export function showActivity({{field: 'date',op: isDateOp ? 'gte' : 'is',- value: isDateOp ? startDate : monthUtils[fromDate](startDate),+ // Interval start dates may be month or year keys (e.g. '2026-06'),+ // so normalise them to a full day for range filters+ value: isDateOp+ ? monthUtils.dayFromDate(startDate)+ : monthUtils[fromDate](startDate),type: 'date',},isDateOp && {diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.test.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.test.tsxnew file mode 100644index 0000000000..6422f52736--- /dev/null+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.test.tsx@@ -0,0 +1,81 @@+import React from 'react';++import type { DataEntity, IntervalEntity } from '@actual-app/core/types/models';+import { render } from '@testing-library/react';+import { describe, expect, it, vi } from 'vitest';++import { TestProviders } from '#mocks';++import { ReportTableList } from './ReportTableList';++function makeInterval(+ date: string,+ intervalStartDate: string,+ intervalEndDate: string,+): IntervalEntity {+ return {+ date,+ intervalStartDate,+ intervalEndDate,+ totalAssets: 0,+ totalDebts: 0,+ netAssets: 0,+ netDebts: 0,+ totalTotals: 0,+ totalBudgeted: 0,+ };+}++describe('ReportTableList', () => {+ it('passes each interval date range to its row when split by interval', () => {+ const renderRow = vi.fn(() => null);+ const data: DataEntity = {+ intervalData: [+ makeInterval('May 2026', '2026-05-01', '2026-05-31'),+ makeInterval('Jun 2026', '2026-06-01', '2026-06-30'),+ ],+ totalAssets: 0,+ totalDebts: 0,+ netAssets: 0,+ netDebts: 0,+ totalTotals: 0,+ totalBudgeted: 0,+ };++ render(+ <TestProviders>+ <ReportTableList+ data={data}+ mode="total"+ groupBy="Interval"+ renderRow={renderRow}+ />+ </TestProviders>,+ );++ expect(renderRow).toHaveBeenCalledWith(+ expect.objectContaining({+ item: expect.objectContaining({+ intervalData: [+ expect.objectContaining({+ intervalStartDate: '2026-05-01',+ intervalEndDate: '2026-05-31',+ }),+ ],+ }),+ }),+ );+ expect(renderRow).toHaveBeenCalledWith(+ expect.objectContaining({+ item: expect.objectContaining({+ intervalData: [+ expect.objectContaining({+ intervalStartDate: '2026-06-01',+ intervalEndDate: '2026-06-30',+ }),+ ],+ }),+ }),+ );+ });+});diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsxindex 75ce230359..ac6d13f8a9 100644--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx@@ -40,7 +40,8 @@ export function ReportTableList({netDebts: interval.netDebts,totalTotals: interval.totalTotals,totalBudgeted: interval.totalBudgeted,- intervalData: [],+ // Keeps the interval's date range available for drilldowns+ intervalData: [interval],categories: [],};})diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsxindex b5bf972136..c8ee75f477 100644--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx@@ -80,8 +80,23 @@ export const ReportTableRow = memo(item.uncategorizedId === 'all' ||categories.grouped.some(g => g.id === item.id);const drilldownField = isGroupRow ? 'group' : groupBy.toLowerCase();- const canShowActivity =- !isNarrowWidth && groupBy !== 'Interval' && !compact;+ // Interval rows drill down by the date range of their intervals (a single+ // interval, or all of them for the totals row) instead of a field+ const firstInterval = item.intervalData[0];+ const lastInterval = item.intervalData[item.intervalData.length - 1];+ const drilldown =+ groupBy === 'Interval'+ ? {+ startDate: firstInterval?.intervalStartDate ?? startDate,+ endDate: lastInterval?.intervalEndDate ?? endDate,+ }+ : {+ startDate,+ endDate,+ field: drilldownField,+ id: item.id,+ };+ const canShowActivity = !isNarrowWidth && !compact;const pointer = canShowActivity ? 'pointer' : 'inherit';@@ -223,10 +238,7 @@ export const ReportTableRow = memo(showHiddenCategories,showOffBudget,type: 'assets',- startDate,- endDate,- field: drilldownField,- id: item.id,+ ...drilldown,uncategorizedId: item.uncategorizedId,})}@@ -271,10 +283,7 @@ export const ReportTableRow = memo(showHiddenCategories,showOffBudget,type: 'debts',- startDate,- endDate,- field: drilldownField,- id: item.id,+ ...drilldown,uncategorizedId: item.uncategorizedId,})}@@ -318,10 +327,7 @@ export const ReportTableRow = memo(showHiddenCategories,showOffBudget,type: 'totals',- startDate,- endDate,- field: drilldownField,- id: item.id,+ ...drilldown,uncategorizedId: item.uncategorizedId,})}diff --git a/upcoming-release-notes/report-interval-click-through.md b/upcoming-release-notes/report-interval-click-through.mdnew file mode 100644index 0000000000..5478e5e735--- /dev/null+++ b/upcoming-release-notes/report-interval-click-through.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [RandomSpaceship]+---++Allow clicking a custom report split by interval to view that interval's transactions