From b3f781e4efdec9604e506c0aaa1d0a7c475bc43e Mon Sep 17 00:00:00 2001 From: 31b4 Date: Wed, 4 Nov 2026 18:51:02 +0100 Subject: [PATCH 1/4] Filter dashboard transactions and analytics by cash account --- .../analytics-module/Analytics.test.tsx | 28 ++++++++++++++-- .../components/analytics-module/Analytics.tsx | 31 ++++++++++++------ .../components/common/AccountFilterSelect.tsx | 32 +++++++++++++++++++ .../dashboard-module/TransactionCalendar.tsx | 16 ++++++---- .../dashboard-module/TransactionList.test.tsx | 22 +++++++++++++ .../dashboard-module/TransactionList.tsx | 31 +++++++++++++----- client/src/navigation/filters.test.ts | 13 ++++++++ client/src/navigation/filters.ts | 18 +++++++++-- client/src/pages/AnalyticsPage.tsx | 5 ++- client/src/pages/DashboardPage.tsx | 5 ++- 10 files changed, 172 insertions(+), 29 deletions(-) create mode 100644 client/src/components/common/AccountFilterSelect.tsx diff --git a/client/src/components/analytics-module/Analytics.test.tsx b/client/src/components/analytics-module/Analytics.test.tsx index 95d61700..cead7e54 100644 --- a/client/src/components/analytics-module/Analytics.test.tsx +++ b/client/src/components/analytics-module/Analytics.test.tsx @@ -67,11 +67,35 @@ describe('Analytics Projected mode', () => { vi.useRealTimers() }) + it('scopes actual and projected totals and ignores unrelated missing exchange rates', () => { + render() + const select = screen.getByRole('combobox', { name: 'Analytics account' }) + fireEvent.change(select, { target: { value: 'cash' } }) + expect(income()).toContain('+100') + fireEvent.click(screen.getByRole('button', { name: 'Projected (1)' })) + expect(income()).toContain('+110') + fireEvent.change(select, { target: { value: 'all' } }) + expect(screen.getByRole('button', { name: 'Projected (2)' })).toBeInTheDocument() + expect(screen.getByText(/unavailable until exchange rates recover/)).toBeInTheDocument() + }) + it('applies the chart range pill to the page filters and returns projected data to Actual in one update', () => { localStorage.setItem('analytics-widget-visibility', JSON.stringify({ 'cash-balance-trend': true })) const onFiltersChange = vi.fn() render() + filters={{ account: 'all', period: 'month', date: '2026-09-01', pinned: false, mode: 'projected', expenseCategory: 'all', incomeCategory: 'all', resolution: 'quarter' }} onFiltersChange={onFiltersChange} />) fireEvent.click(within(screen.getByRole('group', { name: 'Cash balance range' })).getByRole('button', { name: '1Y' })) expect(onFiltersChange).toHaveBeenCalledExactlyOnceWith({ period: 'year', mode: 'actual', resolution: 'default' }, false) }) @@ -210,7 +234,7 @@ describe('Analytics Projected mode', () => { { id: 'september', account_id: 'cash', date: '2026-09-05', amount: -100, status: 'posted' }, ] const cash: Account = { id: 'cash', name: 'Cash', type: 'checking', balance: 1000, currency: 'HUF' } - const filters = (date: string) => ({ period: 'month' as const, date, pinned: false, mode: 'actual' as const, expenseCategory: 'all', incomeCategory: 'all', resolution: 'default' as const }) + const filters = (date: string) => ({ account: 'all', period: 'month' as const, date, pinned: false, mode: 'actual' as const, expenseCategory: 'all', incomeCategory: 'all', resolution: 'default' as const }) const points = () => JSON.parse(screen.getByTestId('account-trend-cash').getAttribute('data-points')!) const { rerender } = render() expect(points()).toHaveLength(15) diff --git a/client/src/components/analytics-module/Analytics.tsx b/client/src/components/analytics-module/Analytics.tsx index ff70d4aa..765d3365 100644 --- a/client/src/components/analytics-module/Analytics.tsx +++ b/client/src/components/analytics-module/Analytics.tsx @@ -6,6 +6,7 @@ import { FinanceDataBoundary } from '../common/FinanceDataStatus' import type { useFinancialOutlookData } from '../../hooks/useFinancialOutlookData' import { useState, useMemo, useEffect, useCallback } from 'react' import { Card, CardContent } from '../common/card' +import { AccountFilterSelect } from '../common/AccountFilterSelect' import { Button } from '../common/button' import { Calendar, ChevronLeft, ChevronRight, SlidersHorizontal } from 'lucide-react' import { loadWidgetVisibility, saveWidgetVisibility, type WidgetId } from './widgetConfig' @@ -52,10 +53,10 @@ type AnalyticsProps = { } export function Analytics({ - transactions, - upcomingTransactions = [], + transactions: allTransactions, + upcomingTransactions: allUpcomingTransactions = [], categories, - accounts, + accounts: allAccounts, masterCurrency = 'HUF', exchangeRates = {}, loading = false, @@ -68,13 +69,20 @@ export function Analytics({ }: AnalyticsProps) { const [localFilters, setLocalFilters] = useState(() => ({ period: 'month', date: format(startOfMonth(new Date()), 'yyyy-MM-dd'), pinned: false, - mode: 'actual', expenseCategory: 'all', incomeCategory: 'all', resolution: 'default', + account: 'all', mode: 'actual', expenseCategory: 'all', incomeCategory: 'all', resolution: 'default', })) const viewFilters = filters ?? localFilters const changeFilters = useCallback((patch: Partial, replace = false) => { if (onFiltersChange) onFiltersChange(patch, replace) else setLocalFilters(previous => ({ ...previous, ...patch })) }, [onFiltersChange]) + const accountFilter = viewFilters.account + const accounts = useMemo(() => accountFilter === 'all' ? allAccounts + : allAccounts.filter(account => account.id === accountFilter), [allAccounts, accountFilter]) + const transactions = useMemo(() => accountFilter === 'all' ? allTransactions + : allTransactions.filter(tx => tx.account_id === accountFilter), [allTransactions, accountFilter]) + const upcomingTransactions = useMemo(() => accountFilter === 'all' ? allUpcomingTransactions + : allUpcomingTransactions.filter(tx => tx.account_id === accountFilter), [allUpcomingTransactions, accountFilter]) const period = viewFilters.period const projectionMode = viewFilters.mode const selectedExpenseCategory = viewFilters.expenseCategory @@ -217,11 +225,11 @@ export function Analytics({ ) const convertToHuf = useCallback((amount: number, accountId: string): number | null => { - const account = accounts.find(item => item.id === accountId) + const account = allAccounts.find(item => item.id === accountId) if (!account) return null if (account.currency === 'HUF') return amount return convertCurrency(amount, account.currency, 'HUF', exchangeRates, masterCurrency).value - }, [accounts, exchangeRates, masterCurrency]) + }, [allAccounts, exchangeRates, masterCurrency]) // Filter transactions by period (exclude investment accounts only) const filteredTransactions = useMemo(() => { @@ -909,6 +917,8 @@ export function Analytics({ */}
+ changeFilters({ account })} + label="Analytics account" className="w-full min-[430px]:w-52" />
{(Object.keys(periodLabels) as TimePeriod[]).map((p) => (

No transactions for {period === 'allTime' ? 'all time' : periodDisplayLabel.toLowerCase()}

-

Add some transactions to see analytics

+ {accountFilter === 'all' ?

Add some transactions to see analytics

+ : <>

This account has no activity in the selected period.

+ }
@@ -1093,6 +1105,7 @@ export function Analytics({ {show('ai-financial-forecast') && ( + {accountFilter !== 'all' &&

The saved forecast covers all accounts.

}
diff --git a/client/src/components/common/AccountFilterSelect.tsx b/client/src/components/common/AccountFilterSelect.tsx new file mode 100644 index 00000000..ef0a7603 --- /dev/null +++ b/client/src/components/common/AccountFilterSelect.tsx @@ -0,0 +1,32 @@ +import { Select } from './select' + +type AccountOption = { + id: string + name: string + currency: string + type: string + archived_at?: number | null +} + +export function AccountFilterSelect({ accounts, value, onChange, label, className }: { + accounts: AccountOption[] + value: string + onChange: (value: string) => void + label: string + className?: string +}) { + const cashAccounts = accounts.filter(account => account.type === 'cash') + .sort((a, b) => Number(a.archived_at != null) - Number(b.archived_at != null) || a.name.localeCompare(b.name)) + + return
+ +
+} diff --git a/client/src/components/dashboard-module/TransactionCalendar.tsx b/client/src/components/dashboard-module/TransactionCalendar.tsx index 86dd6490..56c92fad 100644 --- a/client/src/components/dashboard-module/TransactionCalendar.tsx +++ b/client/src/components/dashboard-module/TransactionCalendar.tsx @@ -26,6 +26,8 @@ const dateKey = (date: Date) => format(date, 'yyyy-MM-dd') export function TransactionCalendar({ transactions, + linkedTransactions = transactions, + accountFiltered = false, accounts, currentMonth, privacyMode, @@ -38,6 +40,8 @@ export function TransactionCalendar({ sortOrder, }: { transactions: Transaction[] + linkedTransactions?: Transaction[] + accountFiltered?: boolean accounts: Account[] currentMonth: Date privacyMode: 'visible' | 'hidden' @@ -58,7 +62,7 @@ export function TransactionCalendar({ const displayTransactions = useMemo(() => { const all = transactions - const byId = new Map(all.map(tx => [tx.id, tx])) + const byId = new Map(linkedTransactions.map(tx => [tx.id, tx])) const consumedIds = new Set() return all.flatMap(tx => { @@ -75,13 +79,13 @@ export function TransactionCalendar({ return [tx] } - const primary = tx.amount < 0 ? tx : related.amount < 0 ? related : tx.amount <= related.amount ? tx : related + const primary = accountFiltered ? tx : tx.amount < 0 ? tx : related.amount < 0 ? related : tx.amount <= related.amount ? tx : related const secondary = primary.id === tx.id ? related : tx consumedIds.add(primary.id) consumedIds.add(secondary.id) return [{ ...primary, relatedTx: secondary }] }) - }, [transactions]) + }, [transactions, linkedTransactions, accountFiltered]) const transactionsByDay = useMemo(() => displayTransactions.reduce>((days, tx) => { const key = tx.date.slice(0, 10) @@ -171,7 +175,7 @@ export function TransactionCalendar({
-
+ {!accountFiltered &&
BALANCE TREND
{baseline === null ?

Balance trend unavailable: missing exchange rates.

: @@ -220,7 +224,7 @@ export function TransactionCalendar({ }
-
+
}
{['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'].map(day =>
{day}
)} @@ -280,7 +284,7 @@ export function TransactionCalendar({
{selectedTransactions.length ? selectedTransactions.map(tx => { const transfer = !!tx.linked_transaction_id - const label = transfer ? `Transfer to ${tx.relatedTx ? getAccountName(tx.relatedTx.account_id) : 'account'}` : (tx.description || getCategoryName(tx.category_id)) + const label = transfer ? `Transfer ${tx.amount < 0 || !accountFiltered ? 'to' : 'from'} ${tx.relatedTx ? getAccountName(tx.relatedTx.account_id) : 'account'}` : (tx.description || getCategoryName(tx.category_id)) return
= 0 ? 'bg-success/10' : 'bg-secondary'}`}>{transfer ? : getCategoryIcon(tx.category_id)}
{label}
{getAccountName(tx.account_id)} · {transfer ? 'Transfer' : getCategoryName(tx.category_id)}
diff --git a/client/src/components/dashboard-module/TransactionList.test.tsx b/client/src/components/dashboard-module/TransactionList.test.tsx index 89b00eea..8da7f106 100644 --- a/client/src/components/dashboard-module/TransactionList.test.tsx +++ b/client/src/components/dashboard-module/TransactionList.test.tsx @@ -120,6 +120,28 @@ function mockRates(rate = 0.2) { } describe('TransactionList redesigned transfers', () => { + it('filters the list and calendar by receiving account without losing the transfer pair', async () => { + const user = userEvent.setup() + renderTransfers({ transactions: [...postedTransfer, + { id: 'other-expense', account_id: 'other', amount: -50, date: '2020-01-01', description: 'Other expense' }, + ] }) + const filter = screen.getByRole('combobox', { name: 'Transaction account' }) + expect(within(filter).getByRole('option', { name: 'Archived cash (HUF) · Archived' })).toBeInTheDocument() + await user.selectOptions(filter, 'destination') + expect(screen.queryByText('Other expense')).not.toBeInTheDocument() + expect(screen.getByRole('button', { name: 'Edit transfer' })).toBeInTheDocument() + expect(screen.getByText('1 posted')).toBeInTheDocument() + + await user.click(screen.getByRole('button', { name: 'Calendar', exact: true })) + expect(screen.getByText('Transfer from Savings')).toBeInTheDocument() + expect(screen.queryByText('Other expense')).not.toBeInTheDocument() + + await user.selectOptions(filter, 'archived') + await user.click(screen.getByRole('button', { name: 'Show all accounts' })) + expect(filter).toHaveValue('all') + expect(screen.getByText('Other expense')).toBeInTheDocument() + }) + it('previews posted edit deltas, preserves both native amounts when swapping, and reverts the full edit', async () => { mockRates() const user = userEvent.setup() diff --git a/client/src/components/dashboard-module/TransactionList.tsx b/client/src/components/dashboard-module/TransactionList.tsx index 89b219cc..d741787b 100644 --- a/client/src/components/dashboard-module/TransactionList.tsx +++ b/client/src/components/dashboard-module/TransactionList.tsx @@ -10,6 +10,7 @@ import { useState, useEffect, useRef } from 'react' import { Button } from '../common/button' import { Input } from '../common/input' import { Label } from '../common/label' +import { AccountFilterSelect } from '../common/AccountFilterSelect' import { Select } from '../common/select' import { Card, CardContent, CardHeader, CardTitle } from '../common/card' import { Modal } from '../common/modal' @@ -205,6 +206,10 @@ export function TransactionList({ manual_price: false, }) const editedTransferPairRef = useRef(null) + const [localAccountFilter, setLocalAccountFilter] = useState('all') + const accountFilter = filters?.account ?? localAccountFilter + const setAccountFilter = (account: string) => onFiltersChange ? onFiltersChange({ account }) : setLocalAccountFilter(account) + const matchesAccount = (tx: Transaction) => accountFilter === 'all' || tx.account_id === accountFilter const [localCategoryFilter, setCategoryFilterLocal] = useState('all') const categoryFilter = filters?.category ?? localCategoryFilter const setCategoryFilter = (value: string) => onFiltersChange ? onFiltersChange({ category: value }) : setCategoryFilterLocal(value) @@ -256,7 +261,7 @@ export function TransactionList({ // Reset showAllTransactions when filter, sort, search, or date range changes useEffect(() => { setShowAllTransactions(false) - }, [categoryFilter, sortOrder, searchQuery, dateRange]) + }, [accountFilter, categoryFilter, sortOrder, searchQuery, dateRange]) useEffect(() => { onCalendarViewChange?.(transactionView === 'calendar') @@ -1254,7 +1259,7 @@ export function TransactionList({ : categoryFilter === 'all-income' ? (tx.amount > 0 && !tx.linked_transaction_id) : categoryFilter === 'transfer' ? !!tx.linked_transaction_id : tx.category_id === categoryFilter - return catMatch && matchesSearch(tx) + return matchesAccount(tx) && catMatch && matchesSearch(tx) } const visibleUpcomingTransactions = upcomingTransactions.filter(tx => !resolvedPendingIds.has(tx.id)) @@ -1270,7 +1275,7 @@ export function TransactionList({ return [{ ...group[0], id: `split:${tx.split_id}`, description: tx.split_description, amount: group.reduce((sum, line) => sum + line.amount, 0), splitGroup: group }] }) } - const standardPendingCount = visibleUpcomingTransactions.filter(tx => !isMcpReviewTransaction(tx)).length + const standardPendingCount = visibleUpcomingTransactions.filter(tx => !isMcpReviewTransaction(tx) && matchesAccount(tx)).length const mcpReviewTransactions = groupPendingSplits(getMcpReviewItems(visibleUpcomingTransactions, applyFilters)) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) const mcpReviewCount = mcpReviewTransactions.length @@ -1284,7 +1289,8 @@ export function TransactionList({ const readyTransactions = pendingFilteredTransactions.filter(tx => tx.date <= today) const futureTransactions = pendingFilteredTransactions.filter(tx => tx.date > today) - const totalFilteredCount = transactions.filter(applyFilters).length + const filteredPostedTransactions = transactions.filter(applyFilters) + const totalFilteredCount = filteredPostedTransactions.length + pendingFilteredTransactions.length + mcpReviewTransactions.length @@ -1490,7 +1496,9 @@ export function TransactionList({ {!composerOnly &&
-
Transactions

{processTransactions(transactions).length} posted{standardPendingCount > 0 ? ` · ${standardPendingCount} upcoming` : ''}{mcpReviewCount > 0 ? ` · ${mcpReviewCount} MCP drafts` : ''}

+
Transactions

{processTransactions(transactions.filter(matchesAccount)).length} posted{standardPendingCount > 0 ? ` · ${standardPendingCount} upcoming` : ''}{mcpReviewCount > 0 ? ` · ${mcpReviewCount} MCP drafts` : ''}

+
@@ -1736,7 +1744,13 @@ export function TransactionList({ {!composerOnly && - {transactionView === 'calendar' ? +

No matching posted transactions for this account.

+ +
} + {transactionView === 'calendar' ? :
{reviewTransactions.length > 0 &&
@@ -1756,7 +1770,7 @@ export function TransactionList({ {upcomingOpen &&
{futureTransactions.map(tx => renderPendingTransaction(tx, false))}
}
} {(() => { - const allProcessed = sortOrder === 'date' ? sortedDates.flatMap(date => processTransactions(groupedTransactions[date].filter(applyFilters))) : processTransactions(transactions.filter(applyFilters)).sort((a, b) => sortOrder === 'amount-high' ? Math.abs(b.amount) - Math.abs(a.amount) : Math.abs(a.amount) - Math.abs(b.amount)) + const allProcessed = sortOrder === 'date' ? sortedDates.flatMap(date => processTransactions(groupedTransactions[date].filter(applyFilters))) : processTransactions(filteredPostedTransactions).sort((a, b) => sortOrder === 'amount-high' ? Math.abs(b.amount) - Math.abs(a.amount) : Math.abs(a.amount) - Math.abs(b.amount)) const shown = showAllTransactions ? allProcessed : allProcessed.slice(0, DISPLAY_LIMIT) return <> {sortOrder === 'date' ? sortedDates.map(date => { @@ -1776,8 +1790,9 @@ export function TransactionList({ })()} {loading && transactions.length === 0 && upcomingTransactions.length === 0 &&
Loading transactions…
} {!loading && totalFilteredCount === 0 && !isAdding &&
-

{transactions.length === 0 && upcomingTransactions.length === 0 ? 'No transactions yet' : 'No transactions found'}

+

{accountFilter !== 'all' ? 'No matching transactions for this account' : transactions.length === 0 && upcomingTransactions.length === 0 ? 'No transactions yet' : 'No transactions found'}

{transactions.length === 0 && upcomingTransactions.length === 0 ? 'Record your first transaction to start tracking' : 'Try changing the filters or period.'}

+ {accountFilter !== 'all' && } {searchQuery && !isAllTimeRange(dateRange) && }
}
} diff --git a/client/src/navigation/filters.test.ts b/client/src/navigation/filters.test.ts index c766c079..4863c159 100644 --- a/client/src/navigation/filters.test.ts +++ b/client/src/navigation/filters.test.ts @@ -51,3 +51,16 @@ describe('view URL contract', () => { expect(parseDashboardFilters(params('view=calendar&range=allTime'), today)).toMatchObject({ range: 'allTime', view: 'list' }) }) }) + + +it('round trips a cash account on both pages and validates only with loaded accounts', () => { + const accounts = [{ id: 'archived-cash', type: 'cash', archived_at: 1 }, { id: 'holding', type: 'investment' }] + const query = params('account=archived-cash') + expect(dashboardSearch(parseDashboardFilters(query, today, undefined, accounts))).toBe(query.toString()) + expect(analyticsSearch(parseAnalyticsFilters(query, today, undefined, accounts))).toBe(query.toString()) + for (const parse of [parseDashboardFilters, parseAnalyticsFilters]) { + expect(parse(query, today).account).toBe('archived-cash') + expect(parse(params('account=holding'), today, undefined, accounts).account).toBe('all') + expect(parse(params('account=missing'), today, undefined, accounts).account).toBe('all') + } +}) diff --git a/client/src/navigation/filters.ts b/client/src/navigation/filters.ts index 90769b83..bd8734a9 100644 --- a/client/src/navigation/filters.ts +++ b/client/src/navigation/filters.ts @@ -2,8 +2,11 @@ import { endOfMonth, format, isValid, parseISO, startOfMonth } from 'date-fns' import type { IncomeExpensesTrendResolution } from '../components/analytics-module/IncomeExpensesTrendChart' import type { TimePeriod } from '../components/analytics-module/types' +type CashAccountOption = { id: string; type: string } + type Category = { id: string; type: 'income' | 'expense' } export type DashboardFilters = { + account: string range: 'current' | 'custom' | 'allTime' startDate: string endDate: string @@ -12,6 +15,7 @@ export type DashboardFilters = { view: 'list' | 'calendar' } export type AnalyticsFilters = { + account: string period: TimePeriod date: string pinned: boolean @@ -33,11 +37,18 @@ function category(value: string | null, categories?: Category[], type?: Category return !categories || categories.some(item => item.id === value && (!type || item.type === type)) ? value : 'all' } -export function parseDashboardFilters(params: URLSearchParams, today = new Date(), categories?: Category[]): DashboardFilters { +function accountFilter(params: URLSearchParams, accounts?: CashAccountOption[]): string { + const value = params.get('account') + if (!value || value === 'all' || value.length > 128) return 'all' + return !accounts || accounts.some(item => item.id === value && item.type === 'cash') ? value : 'all' +} + +export function parseDashboardFilters(params: URLSearchParams, today = new Date(), categories?: Category[], accounts?: CashAccountOption[]): DashboardFilters { const from = params.get('from'), to = params.get('to') const allTime = params.get('range') === 'allTime' || (from === '1900-01-01' && to === '2100-12-31') const custom = !allTime && calendarDate(from) && calendarDate(to) && from <= to const filters: DashboardFilters = { + account: accountFilter(params, accounts), range: allTime ? 'allTime' : custom ? 'custom' : 'current', startDate: allTime ? '1900-01-01' : custom ? from : format(startOfMonth(today), 'yyyy-MM-dd'), endDate: allTime ? '2100-12-31' : custom ? to : format(endOfMonth(today), 'yyyy-MM-dd'), @@ -65,10 +76,11 @@ export function dashboardSearch(filters: DashboardFilters): string { if (filters.category !== 'all') params.set('category', filters.category) if (filters.sort !== 'date') params.set('sort', filters.sort) if (filters.view !== 'list') params.set('view', filters.view) + if (filters.account !== 'all') params.set('account', filters.account) return params.toString() } -export function parseAnalyticsFilters(params: URLSearchParams, today = new Date(), categories?: Category[]): AnalyticsFilters { +export function parseAnalyticsFilters(params: URLSearchParams, today = new Date(), categories?: Category[], accounts?: CashAccountOption[]): AnalyticsFilters { const period = params.get('period') === 'year' || params.get('period') === 'allTime' ? params.get('period') as TimePeriod : 'month' const month = params.get('month'), year = params.get('year') const monthDate = month && /^\d{4}-\d{2}$/.test(month) ? `${month}-01` : null @@ -76,6 +88,7 @@ export function parseAnalyticsFilters(params: URLSearchParams, today = new Date( const explicitDate = period === 'month' ? monthDate : period === 'year' ? yearDate : null const pinned = calendarDate(explicitDate) return { + account: accountFilter(params, accounts), period, date: pinned ? explicitDate : format(startOfMonth(today), 'yyyy-MM-dd'), pinned, mode: params.get('mode') === 'projected' ? 'projected' : 'actual', expenseCategory: category(params.get('expenseCategory'), categories, 'expense'), @@ -94,5 +107,6 @@ export function analyticsSearch(filters: AnalyticsFilters): string { if (filters.expenseCategory !== 'all') params.set('expenseCategory', filters.expenseCategory) if (filters.incomeCategory !== 'all') params.set('incomeCategory', filters.incomeCategory) if (filters.resolution !== 'default') params.set('resolution', filters.resolution) + if (filters.account !== 'all') params.set('account', filters.account) return params.toString() } diff --git a/client/src/pages/AnalyticsPage.tsx b/client/src/pages/AnalyticsPage.tsx index 42fe9441..22701b5e 100644 --- a/client/src/pages/AnalyticsPage.tsx +++ b/client/src/pages/AnalyticsPage.tsx @@ -10,7 +10,10 @@ export function AnalyticsPage() { const { finance, masterCurrency, outlook } = useOutletContext() const { dataStatus } = finance const categoriesReady = dataStatus.categories.loaded && !dataStatus.categories.loading && !dataStatus.categories.error - const parseFilters = useCallback((params: URLSearchParams) => parseAnalyticsFilters(params, new Date(), categoriesReady ? finance.categories : undefined), [categoriesReady, finance.categories]) + const accountsStatus = finance.dataStatus.accounts + const accountsReady = accountsStatus.loaded && !accountsStatus.loading && !accountsStatus.error + const parseFilters = useCallback((params: URLSearchParams) => parseAnalyticsFilters(params, new Date(), categoriesReady ? finance.categories : undefined, + accountsReady ? finance.accounts : undefined), [categoriesReady, finance.categories, accountsReady, finance.accounts]) const [filters, updateFilters] = useUrlFilters(parseFilters, analyticsSearch) const projectionReady = dataStatus.upcoming.loaded && !dataStatus.upcoming.loading && !dataStatus.upcoming.error const comparisonReady = [dataStatus.accounts, dataStatus.history].every(status => status.loaded && !status.loading && !status.error) diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index 39b9cf54..9b24a256 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -20,7 +20,10 @@ export function DashboardPage() { const searchRequest = location.state as { transactionSearch?: string } | null const { finance, masterCurrency } = useOutletContext() const categoriesReady = finance.dataStatus.categories.loaded && !finance.dataStatus.categories.loading && !finance.dataStatus.categories.error - const parseFilters = useCallback((params: URLSearchParams) => parseDashboardFilters(params, new Date(), categoriesReady ? finance.categories : undefined), [categoriesReady, finance.categories]) + const accountsStatus = finance.dataStatus.accounts + const accountsReady = accountsStatus.loaded && !accountsStatus.loading && !accountsStatus.error + const parseFilters = useCallback((params: URLSearchParams) => parseDashboardFilters(params, new Date(), categoriesReady ? finance.categories : undefined, + accountsReady ? finance.accounts : undefined), [categoriesReady, finance.categories, accountsReady, finance.accounts]) const [filters, updateFilters] = useUrlFilters(parseFilters, dashboardSearch) const dateRange = useMemo(() => ({ startDate: filters.startDate, endDate: filters.endDate }), [filters.startDate, filters.endDate]) const currentMonth = filters.range === 'allTime' ? new Date() : parseISO(filters.startDate) From 5165800f2573ce3cd9a2b17a5ba22a1fd2f10999 Mon Sep 17 00:00:00 2001 From: 31b4 Date: Wed, 4 Nov 2026 18:53:56 +0100 Subject: [PATCH 2/4] Group the Dashboard account selector with transaction filters --- client/src/components/dashboard-module/TransactionList.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/components/dashboard-module/TransactionList.tsx b/client/src/components/dashboard-module/TransactionList.tsx index d741787b..35dd68c1 100644 --- a/client/src/components/dashboard-module/TransactionList.tsx +++ b/client/src/components/dashboard-module/TransactionList.tsx @@ -1497,15 +1497,13 @@ export function TransactionList({ {!composerOnly &&
Transactions

{processTransactions(transactions.filter(matchesAccount)).length} posted{standardPendingCount > 0 ? ` · ${standardPendingCount} upcoming` : ''}{mcpReviewCount > 0 ? ` · ${mcpReviewCount} MCP drafts` : ''}

-
-
+
@@ -1519,6 +1517,8 @@ export function TransactionList({ {!['all', 'all-expenses', 'all-income', 'transfer'].includes(categoryFilter) && !categories.some(category => category.id === categoryFilter) && } {(['expense', 'income'] as const).map(type => {categories.filter(c => c.type === type).map(cat => )})} + From 2344f1cbc99ebd00eb5590804e17bbb9b455bb2e Mon Sep 17 00:00:00 2001 From: 31b4 Date: Wed, 4 Nov 2026 18:57:06 +0100 Subject: [PATCH 3/4] Open mobile transaction filters in a bottom sheet --- .../components/common/AccountFilterSelect.tsx | 5 +- .../dashboard-module/TransactionList.tsx | 63 +++++++++++++------ 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/client/src/components/common/AccountFilterSelect.tsx b/client/src/components/common/AccountFilterSelect.tsx index ef0a7603..f75f4f3c 100644 --- a/client/src/components/common/AccountFilterSelect.tsx +++ b/client/src/components/common/AccountFilterSelect.tsx @@ -8,18 +8,19 @@ type AccountOption = { archived_at?: number | null } -export function AccountFilterSelect({ accounts, value, onChange, label, className }: { +export function AccountFilterSelect({ accounts, value, onChange, label, className, selectClassName }: { accounts: AccountOption[] value: string onChange: (value: string) => void label: string className?: string + selectClassName?: string }) { const cashAccounts = accounts.filter(account => account.type === 'cash') .sort((a, b) => Number(a.archived_at != null) - Number(b.archived_at != null) || a.name.localeCompare(b.name)) return
- onChange(event.target.value)} className={`truncate ${selectClassName ?? ''}`}> {value !== 'all' && !cashAccounts.some(account => account.id === value) && ( diff --git a/client/src/components/dashboard-module/TransactionList.tsx b/client/src/components/dashboard-module/TransactionList.tsx index 35dd68c1..fcae7e25 100644 --- a/client/src/components/dashboard-module/TransactionList.tsx +++ b/client/src/components/dashboard-module/TransactionList.tsx @@ -6,7 +6,7 @@ import type { HoldingFields } from '../../../../shared/holding' import type { DashboardFilters, FilterChange } from '../../navigation/filters' import { useUnsavedChanges } from '../../navigation/UnsavedChanges' import { matchesTransaction } from '../../lib/global-search' -import { useState, useEffect, useRef } from 'react' +import { useCallback, useState, useEffect, useRef } from 'react' import { Button } from '../common/button' import { Input } from '../common/input' import { Label } from '../common/label' @@ -174,6 +174,14 @@ export function TransactionList({ const categories = availableCategories ?? fetchedCategories const [upcomingOpen, setUpcomingOpen] = useState(false) const [filtersOpen, setFiltersOpen] = useState(false) + const closeFilters = useCallback(() => setFiltersOpen(false), []) + useEffect(() => { + if (!filtersOpen) return + const desktop = window.matchMedia('(min-width: 640px)') + const handleChange = () => { if (desktop.matches) closeFilters() } + desktop.addEventListener('change', handleChange) + return () => desktop.removeEventListener('change', handleChange) + }, [filtersOpen, closeFilters]) const [activeTxId, setActiveTxId] = useState(null) const [pendingDetails, setPendingDetails] = useState(null) const [legacyTradeId,setLegacyTradeId]=useState(null) @@ -1492,6 +1500,26 @@ export function TransactionList({ if (composerOnly && isAdding) handleCancel() }, [navigationKey, composerOnly, isAdding, handleCancel]) + const filterControls = (<> +
+ + setSearchQuery(e.target.value)} placeholder="Search transactions..." className="h-11 sm:h-10 w-full rounded-lg border border-border bg-background pl-8 pr-3 text-base sm:text-[13px] outline-none focus:ring-1 focus:ring-primary" /> +
+
+ {([['all', 'All'], ['all-expenses', 'Expenses'], ['all-income', 'Income'], ['transfer', 'Transfers']] as const).map(([value, label]) => )} +
+ + + + ) + return ( {!composerOnly && @@ -1503,28 +1531,23 @@ export function TransactionList({
-
-
-
- - setSearchQuery(e.target.value)} placeholder="Search transactions..." className="h-10 w-full rounded-lg border border-border bg-background pl-8 pr-3 text-[13px] outline-none focus:ring-1 focus:ring-primary" /> -
-
- {([['all', 'All'], ['all-expenses', 'Expenses'], ['all-income', 'Income'], ['transfer', 'Transfers']] as const).map(([value, label]) => )} -
- - - +
+
+ {filterControls}
} + {!composerOnly && filtersOpen && ( + +
{filterControls}
+
+ +
+
+ )} + Date: Wed, 4 Nov 2026 18:58:45 +0100 Subject: [PATCH 4/4] Discard unapplied mobile transaction filters on close --- .../dashboard-module/TransactionList.tsx | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/client/src/components/dashboard-module/TransactionList.tsx b/client/src/components/dashboard-module/TransactionList.tsx index fcae7e25..8d5f6d31 100644 --- a/client/src/components/dashboard-module/TransactionList.tsx +++ b/client/src/components/dashboard-module/TransactionList.tsx @@ -74,6 +74,8 @@ type Account = HoldingFields & { is_locked?: boolean } +type TransactionFilters = Pick & { search: string } + type Category = { id: string name: string @@ -173,8 +175,9 @@ export function TransactionList({ const [fetchedCategories, setCategories] = useState([]) const categories = availableCategories ?? fetchedCategories const [upcomingOpen, setUpcomingOpen] = useState(false) - const [filtersOpen, setFiltersOpen] = useState(false) - const closeFilters = useCallback(() => setFiltersOpen(false), []) + const [filterDraft, setFilterDraft] = useState(null) + const filtersOpen = filterDraft !== null + const closeFilters = useCallback(() => setFilterDraft(null), []) useEffect(() => { if (!filtersOpen) return const desktop = window.matchMedia('(min-width: 640px)') @@ -220,10 +223,8 @@ export function TransactionList({ const matchesAccount = (tx: Transaction) => accountFilter === 'all' || tx.account_id === accountFilter const [localCategoryFilter, setCategoryFilterLocal] = useState('all') const categoryFilter = filters?.category ?? localCategoryFilter - const setCategoryFilter = (value: string) => onFiltersChange ? onFiltersChange({ category: value }) : setCategoryFilterLocal(value) const [localSortOrder, setSortOrderLocal] = useState<'date' | 'amount-high' | 'amount-low'>('date') const sortOrder = filters?.sort ?? localSortOrder - const setSortOrder = (value: 'date' | 'amount-high' | 'amount-low') => onFiltersChange ? onFiltersChange({ sort: value }) : setSortOrderLocal(value) const [showAllTransactions, setShowAllTransactions] = useState(false) const [localTransactionView, setTransactionViewLocal] = useState<'list' | 'calendar'>('list') const transactionView = filters?.view ?? localTransactionView @@ -1500,22 +1501,37 @@ export function TransactionList({ if (composerOnly && isAdding) handleCancel() }, [navigationKey, composerOnly, isAdding, handleCancel]) - const filterControls = (<> + const appliedFilters: TransactionFilters = { account: accountFilter, category: categoryFilter, sort: sortOrder, search: searchQuery } + const applyFilterChanges = ({ search, ...patch }: Partial) => { + if (search !== undefined) setSearchQuery(search) + if (onFiltersChange) { + if (Object.keys(patch).length > 0) onFiltersChange(patch) + } else { + if (patch.account !== undefined) setLocalAccountFilter(patch.account) + if (patch.category !== undefined) setCategoryFilterLocal(patch.category) + if (patch.sort !== undefined) setSortOrderLocal(patch.sort) + } + } + + const filterControls = ( + { account, category: selectedCategory, sort, search }: TransactionFilters, + onChange: (patch: Partial) => void, + ) => (<>
- setSearchQuery(e.target.value)} placeholder="Search transactions..." className="h-11 sm:h-10 w-full rounded-lg border border-border bg-background pl-8 pr-3 text-base sm:text-[13px] outline-none focus:ring-1 focus:ring-primary" /> + onChange({ search: e.target.value })} placeholder="Search transactions..." className="h-11 sm:h-10 w-full rounded-lg border border-border bg-background pl-8 pr-3 text-base sm:text-[13px] outline-none focus:ring-1 focus:ring-primary" />
- {([['all', 'All'], ['all-expenses', 'Expenses'], ['all-income', 'Income'], ['transfer', 'Transfers']] as const).map(([value, label]) => )} + {([['all', 'All'], ['all-expenses', 'Expenses'], ['all-income', 'Income'], ['transfer', 'Transfers']] as const).map(([value, label]) => )}
- onChange({ category: e.target.value })} className="h-11 w-full min-w-0 sm:h-10 sm:w-auto text-base sm:text-[13px] sm:max-w-44"> - {!['all', 'all-expenses', 'all-income', 'transfer'].includes(categoryFilter) && !categories.some(category => category.id === categoryFilter) && } + {!['all', 'all-expenses', 'all-income', 'transfer'].includes(selectedCategory) && !categories.some(category => category.id === selectedCategory) && } {(['expense', 'income'] as const).map(type => {categories.filter(c => c.type === type).map(cat => )})} - onChange({ account: value })} label="Transaction account" className="w-full sm:w-52" selectClassName="h-11 text-base sm:h-10 sm:text-sm" /> - onChange({ sort: e.target.value as TransactionFilters['sort'] })} className="h-11 w-full min-w-0 sm:h-10 sm:w-auto text-base sm:text-[13px] sm:max-w-36"> ) @@ -1531,19 +1547,19 @@ export function TransactionList({
-
+
- {filterControls} + {filterControls(appliedFilters, applyFilterChanges)}
} - {!composerOnly && filtersOpen && ( + {!composerOnly && filterDraft && ( -
{filterControls}
+
{filterControls(filterDraft, patch => setFilterDraft(current => current && { ...current, ...patch }))}
- +
)}