A local-first personal finance app
[AI] Fix custom report transfer drilldown filters (#8001)
kikiminyes4518a6758ba2
diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsxindex ae9273421c..e983de9247 100644--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx@@ -185,6 +185,14 @@ const customLabel = (props, typeOp, format) => {return renderCustomLabel(calcX, calcY, textAnchor, display, textSize);};+type ReportDrilldownPayload = Pick<GroupedEntity, 'uncategorizedId'>;++function hasUncategorizedId(value: unknown): value is ReportDrilldownPayload {+ return (+ value !== null && typeof value === 'object' && 'uncategorizedId' in value+ );+}+type BarGraphProps = {style?: CSSProperties;data: DataEntity;@@ -313,24 +321,31 @@ export function BarGraph({!['Group', 'Interval'].includes(groupBy) &&setPointer('pointer')}- onClick={item =>- ((compact && showTooltip) || !compact) &&- !['Group', 'Interval'].includes(groupBy) &&- showActivity({- navigate,- categories,- accounts,- balanceTypeOp,- filters,- showHiddenCategories,- showOffBudget,- type: 'totals',- startDate: data.startDate,- endDate: data.endDate,- field: groupBy.toLowerCase(),- id: item.id,- })- }+ onClick={item => {+ const itemPayload = hasUncategorizedId(item.payload)+ ? item.payload+ : undefined;++ return (+ ((compact && showTooltip) || !compact) &&+ !['Group', 'Interval'].includes(groupBy) &&+ 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,+ })+ );+ }}shape={(props: BarShapeProps) => (<Rectangle{...props}diff --git a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsxindex 7d3fcef6ae..9a5ea04af6 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 @@ const RADIAN = Math.PI / 180;const canDeviceHover = () => window.matchMedia('(hover: hover)').matches;-type ClickablePieItem = PieSectorDataItem & { id?: string };+type ClickablePieItem = PieSectorDataItem &+ Partial<Pick<GroupedEntity, 'id' | 'uncategorizedId'>>;// ---------------------------------------------------------------------------// Dimension helpers@@ -600,6 +601,7 @@ export function DonutGraph({endDate: data.endDate,field: 'category',id: item.id,+ uncategorizedId: item.uncategorizedId,});}}}diff --git a/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx b/packages/desktop-client/src/components/reports/graphs/LineGraph.tsxindex ce49140b72..d7d4dee75f 100644--- a/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/LineGraph.tsx@@ -189,7 +189,7 @@ export function LineGraph({? computeTrendLines(data.intervalData, data.legend): [];- const onShowActivity = (item, id, payload) => {+ const onShowActivity = (id, payload, uncategorizedId) => {showActivity({navigate,categories,@@ -203,6 +203,7 @@ export function LineGraph({endDate: payload.payload.intervalEndDate,field: groupBy.toLowerCase(),id,+ uncategorizedId,interval,});};@@ -295,7 +296,11 @@ export function LineGraph({onClick: (e, payload) =>((compact && showTooltip) || !compact) &&!['Group', 'Interval'].includes(groupBy) &&- onShowActivity(e, entry.id, payload),+ onShowActivity(+ entry.id,+ payload,+ entry.uncategorizedId,+ ),}}/>);diff --git a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsxindex 87fb2d4340..4b130b9c5e 100644--- a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx@@ -303,6 +303,7 @@ export function StackedBarGraph({endDate: e.payload?.intervalEndDate,field: groupBy.toLowerCase(),id: entry.id,+ uncategorizedId: entry.uncategorizedId,interval,})}diff --git a/packages/desktop-client/src/components/reports/graphs/showActivity.test.ts b/packages/desktop-client/src/components/reports/graphs/showActivity.test.tsnew file mode 100644index 0000000000..1a8736bd32--- /dev/null+++ b/packages/desktop-client/src/components/reports/graphs/showActivity.test.ts@@ -0,0 +1,81 @@+import type {+ AccountEntity,+ CategoryEntity,+ CategoryGroupEntity,+} from '@actual-app/core/types/models';+import { describe, expect, it, vi } from 'vitest';++import { showActivity } from './showActivity';++const categories: { grouped: CategoryGroupEntity[]; list: CategoryEntity[] } = {+ grouped: [],+ list: [],+};+const accounts: AccountEntity[] = [];++describe('showActivity', () => {+ it('adds a transfer filter for the virtual Transfers category', () => {+ const navigate = vi.fn();++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp: 'totalAssets',+ filters: [{ field: 'account', op: 'is', value: 'acct-1', type: 'id' }],+ showHiddenCategories: true,+ showOffBudget: true,+ type: 'totals',+ startDate: '2026-05-24',+ endDate: '2026-05-30',+ field: 'category',+ id: '',+ uncategorizedId: 'transfer',+ });++ const [path, options] = navigate.mock.calls[0];+ const filterConditions = options.state.filterConditions;++ expect(path).toBe('/accounts');+ expect(filterConditions).toContainEqual({+ field: 'transfer',+ op: 'is',+ value: true,+ type: 'boolean',+ });+ expect(filterConditions).not.toContainEqual({+ field: 'category',+ op: 'is',+ value: '',+ type: 'id',+ });+ });++ it('keeps the category filter for regular categories', () => {+ const navigate = vi.fn();++ showActivity({+ navigate,+ categories,+ accounts,+ balanceTypeOp: 'totalAssets',+ filters: [],+ showHiddenCategories: true,+ showOffBudget: true,+ type: 'totals',+ startDate: '2026-05-24',+ endDate: '2026-05-30',+ field: 'category',+ id: 'cat-food',+ });++ const [, options] = navigate.mock.calls[0];++ expect(options.state.filterConditions).toContainEqual({+ field: 'category',+ op: 'is',+ value: 'cat-food',+ type: 'id',+ });+ });+});diff --git a/packages/desktop-client/src/components/reports/graphs/showActivity.ts b/packages/desktop-client/src/components/reports/graphs/showActivity.tsindex 266ad481f8..88c6fcd032 100644--- a/packages/desktop-client/src/components/reports/graphs/showActivity.ts+++ b/packages/desktop-client/src/components/reports/graphs/showActivity.ts@@ -24,6 +24,7 @@ type showActivityProps = {endDate?: string;field?: string;id?: string | string[]; // changed: supports array for oneOf+ uncategorizedId?: 'off_budget' | 'transfer' | 'other' | 'all';interval?: string;};@@ -40,6 +41,7 @@ export function showActivity({endDate,field,id,+ uncategorizedId,interval = 'Day',}: showActivityProps) {const isOutFlow =@@ -52,16 +54,25 @@ export function showActivity({: (((ReportOptions.intervalMap.get(interval) || 'Day').toLowerCase() +'FromDate') as 'dayFromDate' | 'monthFromDate' | 'yearFromDate');const isDateOp = interval === 'Weekly' || type !== 'time';+ const drilldownFilter =+ field === 'category' && uncategorizedId === 'transfer'+ ? {+ field: 'transfer',+ op: 'is',+ value: true,+ type: 'boolean',+ }+ : id && {+ // changed: use oneOf when id is an array, is when it's a string+ field,+ op: Array.isArray(id) ? 'oneOf' : 'is',+ value: id,+ type: 'id',+ };const filterConditions = [...filters,- id && {- // changed: use oneOf when id is an array, is when it's a string- field,- op: Array.isArray(id) ? 'oneOf' : 'is',- value: id,- type: 'id',- },+ drilldownFilter,{field: 'date',op: isDateOp ? 'gte' : 'is',diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsxindex 2b8495ae89..32e0b22d0f 100644--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx@@ -178,6 +178,7 @@ export const ReportTableRow = memo(endDate: intervalItem.intervalEndDate || '',field: groupBy.toLowerCase(),id: item.id,+ uncategorizedId: item.uncategorizedId,interval,})}@@ -235,6 +236,7 @@ export const ReportTableRow = memo(endDate,field: groupBy.toLowerCase(),id: item.id,+ uncategorizedId: item.uncategorizedId,})}/>@@ -285,6 +287,7 @@ export const ReportTableRow = memo(endDate,field: groupBy.toLowerCase(),id: item.id,+ uncategorizedId: item.uncategorizedId,})}/>@@ -334,6 +337,7 @@ export const ReportTableRow = memo(endDate,field: groupBy.toLowerCase(),id: item.id,+ uncategorizedId: item.uncategorizedId,})}width="flex"diff --git a/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts b/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.tsindex 9d7b2cd676..9f44358785 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts+++ b/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts@@ -71,6 +71,8 @@ export function calculateLegend(name: item.name || '',color: getColor(item.data, index),dataKey: item.id || item.name || '', // Use id for unique data lookup+ uncategorizedId:+ 'uncategorizedId' in item.data ? item.data.uncategorizedId : undefined,};});return legend;diff --git a/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts b/packages/desktop-client/src/components/reports/spreadsheets/recalculate.tsindex 84266aafd4..14432743b4 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts+++ b/packages/desktop-client/src/components/reports/spreadsheets/recalculate.ts@@ -108,6 +108,7 @@ export function recalculate({return {id: item.id || '',name: item.name,+ uncategorizedId: item.uncategorized_id,totalAssets,totalDebts,netAssets: totalTotals > 0 ? totalTotals : 0,diff --git a/packages/loot-core/src/types/models/reports.ts b/packages/loot-core/src/types/models/reports.tsindex 9b734d76c2..2675c9a3ae 100644--- a/packages/loot-core/src/types/models/reports.ts+++ b/packages/loot-core/src/types/models/reports.ts@@ -95,6 +95,7 @@ export type LegendEntity = {id: string | null;color: string;dataKey: string; // Uses id for unique data lookup when categories have same name+ uncategorizedId?: 'off_budget' | 'transfer' | 'other' | 'all';};export type IntervalEntity = {@@ -113,6 +114,7 @@ export type IntervalEntity = {export type GroupedEntity = {id: string;name: string;+ uncategorizedId?: 'off_budget' | 'transfer' | 'other' | 'all';date?: string;intervalData: IntervalEntity[];totalAssets: number;diff --git a/upcoming-release-notes/8001.md b/upcoming-release-notes/8001.mdnew file mode 100644index 0000000000..db9f89f14f--- /dev/null+++ b/upcoming-release-notes/8001.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [kikiminyes]+---++Fix custom report drilldowns for transfer bars so they only show transfer transactions.