Open-source personal finance manager. Self-hosted, privacy-first.
fix(transactions): keep the description badges inside their column (#1315)
Tássio Noronha1f08cc685e3c
diff --git a/frontend/src/pages/transactions-description-badges.test.tsx b/frontend/src/pages/transactions-description-badges.test.tsxnew file mode 100644index 00000000..748880e5--- /dev/null+++ b/frontend/src/pages/transactions-description-badges.test.tsx@@ -0,0 +1,151 @@+/**+ * The description cell keeps its badges inside its own column (#1306).+ *+ * The Description column has a fixed width. A row that carries several+ * badges at once (a transfer with its counterpart account, the report+ * exclusion marker, an installment counter) needed more room than the+ * column has, and because the badges sat on a single non-wrapping line+ * they ran past the cell and painted over the Category column next to+ * it. The description itself was squeezed to nothing in the process.+ *+ * jsdom has no layout, so the guarantee is checked structurally: the+ * line wraps, and every badge on it is either small enough to never+ * need shrinking (`shrink-0`) or capped at the cell width so its own+ * text truncates (`max-w-full`). Either way nothing can push the line+ * wider than the column.+ */+import { beforeEach, describe, expect, it, vi } from 'vitest'+import { screen } from '@testing-library/react'++import TransactionsPage from '@/pages/transactions'+import { renderWithProviders } from '@/test/utils'+import type { Transaction } from '@/types'++const api = vi.hoisted(() => ({+ transactions: { list: vi.fn(), update: vi.fn(), delete: vi.fn(), create: vi.fn() },+ categories: { list: vi.fn(), listIncludingHidden: vi.fn() },+ categoryGroups: { list: vi.fn() },+ accounts: {+ get: vi.fn(), list: vi.fn(), bills: vi.fn(), summary: vi.fn(),+ update: vi.fn(), runningBalance: vi.fn(),+ },+ recurring: { list: vi.fn() },+ payees: { list: vi.fn() },+ admin: { accountingMode: vi.fn() },+ groups: { get: vi.fn(), list: vi.fn() },+ rules: { create: vi.fn() },+ reconciliation: { suggestions: vi.fn() },+ currencies: { list: vi.fn() },+ settings: { attachments: vi.fn() },+}))++vi.mock('@/lib/api', () => ({+ transactions: api.transactions,+ categories: api.categories,+ categoryGroups: api.categoryGroups,+ accounts: api.accounts,+ recurring: api.recurring,+ payees: api.payees,+ admin: api.admin,+ groups: api.groups,+ rules: api.rules,+ reconciliation: api.reconciliation,+ currencies: api.currencies,+ settings: api.settings,+}))+vi.mock('@/hooks/use-mobile', () => ({ useIsMobile: () => false }))+vi.mock('@/hooks/use-display-locale', () => ({+ useDisplayLocale: () => 'en-US',+ useDateLocale: () => 'en-US',+}))+vi.mock('@/hooks/use-privacy-mode', () => ({+ usePrivacyMode: () => ({ mask: (value: string) => value, privacyMode: false, MASK: '***' }),+}))+vi.mock('@/contexts/auth-context', () => ({+ useAuth: () => ({ user: { id: 'user-1', preferences: { currency_display: 'BRL' } } }),+}))+vi.mock('@/contexts/workspace-context', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@/contexts/workspace-context')>()+ return { ...actual, useWorkspace: () => ({ canWrite: true, hasModule: () => true }) }+})+vi.mock('@/contexts/collection-filter-context', () => ({+ useCollectionFilter: () => ({+ collections: [], activeCollectionId: null, activeCollection: null,+ setActiveCollectionId: () => {}, activeAccountIds: null, activeWalletIds: null,+ }),+}))++// The row from the report: a transfer-categorised purchase split into 18+// installments and kept out of the reports, so three badges land on the+// same line as the description.+const crowded: Transaction = {+ id: 'tx-crowded', user_id: 'user-1', account_id: 'acc-1',+ // Deliberately free of the badge words: an assertion on the badges below+ // would otherwise pass on the description's own text.+ description: 'Payment to Vinicius in 18 parts',+ category_id: 'cat-1',+ category: {+ id: 'cat-1', name: 'Transfers', icon: 'arrow-left-right',+ color: '#6B7280', treat_as_transfer: true,+ } as Transaction['category'],+ external_id: null, original_description: null, amount: 180, currency: 'BRL',+ date: '2026-10-08', type: 'debit', source: 'manual', status: 'posted',+ payee: null, payee_id: null, payee_name: null, notes: null,+ transfer_pair_id: null,+ transfer_counterpart: null,+ amount_primary: null, fx_rate_used: null, fx_fallback: false,+ installment_number: 18, total_installments: 18, installment_total_amount: 3240,+ installment_purchase_date: '2025-05-08', installment_series_id: 'series-1',+ bill_id: null, effective_bill_date: null, splits: [], is_ignored: false,+ exclude_from_pnl: true,+}++beforeEach(() => {+ vi.clearAllMocks()+ vi.setSystemTime(new Date('2026-10-20T12:00:00'))+ api.transactions.list.mockResolvedValue({ items: [crowded], total: 1, page: 1, limit: 50 })+ api.categories.list.mockResolvedValue([])+ api.categories.listIncludingHidden.mockResolvedValue([])+ api.categoryGroups.list.mockResolvedValue([])+ api.accounts.list.mockResolvedValue([])+ api.recurring.list.mockResolvedValue([])+ api.payees.list.mockResolvedValue([])+ api.admin.accountingMode.mockResolvedValue(false)+ api.groups.list.mockResolvedValue([])+ api.reconciliation.suggestions.mockResolvedValue([])+ api.currencies.list.mockResolvedValue([])+ api.settings.attachments.mockResolvedValue(false)+})++describe('the description cell on a row with several badges', () => {+ it('wraps the badges instead of letting them run into the next column', async () => {+ renderWithProviders(<TransactionsPage />, { route: '/transactions', path: '/transactions' })++ const description = await screen.findByText('Payment to Vinicius in 18 parts')+ const line = description.parentElement!++ // All three badges share the line with the description. Each one is+ // looked up as its own element, so dropping a badge fails the test+ // instead of being covered by the text of its neighbours.+ const badges = Array.from(line.children).filter((child) => child !== description)+ const labels = badges.map((badge) => badge.textContent?.trim())+ expect(labels).toContain('Transfer')+ expect(labels).toContain('Not in reports')+ expect(labels).toContain('18/18')++ expect(line.className).toContain('flex-wrap')++ // The description truncates rather than widening the line, and every+ // badge beside it is either unshrinkable-but-small or capped at the+ // cell width. Nothing here can overflow the column.+ expect(description.className).toContain('truncate')+ expect(description.className).toContain('max-w-full')+ for (const badge of Array.from(line.children)) {+ if (badge === description) continue+ expect(+ badge.className.includes('max-w-full') || badge.className.includes('shrink-0'),+ `badge "${badge.textContent}" can push the description line past the column`,+ ).toBe(true)+ }+ })+})diff --git a/frontend/src/pages/transactions.tsx b/frontend/src/pages/transactions.tsxindex cff1f8e3..b807ca6b 100644--- a/frontend/src/pages/transactions.tsx+++ b/frontend/src/pages/transactions.tsx@@ -1114,25 +1114,39 @@ export default function TransactionsPage() {const showInlineTags = !grid.isVisible('tags')const noteText = tx.notes ? stripHashtags(tx.notes) : ''const noteTags = tx.notes ? parseHashtags(tx.notes) : []+ // A long group or author name truncates inside its badge, so the label+ // doubles as its own tooltip and stays readable on hover.+ const groupBadgeLabel = tx.group_id+ ? tx.is_shared && tx.parent_owner_name+ ? t('splitGroups.sharedRowBadgeAuthor', {+ author: tx.parent_owner_name,+ group: groupNameById.get(tx.group_id) ?? '',+ })+ : t('splitGroups.ownerRowBadge', {+ group: groupNameById.get(tx.group_id) ?? '',+ })+ : ''return (<div className="flex items-center gap-2 md:gap-3"><CategoryIcon icon={tx.category?.icon} color={tx.category?.color} size="lg" /><div className="min-w-0 flex-1">- <div className="flex items-center gap-2">- <p className="text-sm font-semibold text-foreground truncate">{tx.description}</p>+ {/* The column has a fixed width, so a row carrying several badges+ (transfer with its counterpart account, report exclusion, an+ installment counter) runs past the cell and paints over the+ Category column next to it (issue #1306). Wrapping keeps every+ badge inside the cell: they move to a second line instead of+ escaping, and the description keeps its own width rather than+ being squeezed to nothing. The overflow guard is the backstop:+ the column can be dragged down to 41px, narrower than a single+ badge, and there the badges clip at the cell edge instead. */}+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1 overflow-hidden">+ <p className="max-w-full text-sm font-semibold text-foreground truncate">{tx.description}</p>{tx.group_id && (<span- className="inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-violet-700 bg-violet-50 border border-violet-200 dark:bg-violet-950/40 dark:text-violet-300 dark:border-violet-900 px-1.5 py-0.5 rounded-full"+ className="inline-flex max-w-full items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-violet-700 bg-violet-50 border border-violet-200 dark:bg-violet-950/40 dark:text-violet-300 dark:border-violet-900 px-1.5 py-0.5 rounded-full"title={t('splitGroups.sharedRowTooltip')}>- {tx.is_shared && tx.parent_owner_name- ? t('splitGroups.sharedRowBadgeAuthor', {- author: tx.parent_owner_name,- group: groupNameById.get(tx.group_id) ?? '',- })- : t('splitGroups.ownerRowBadge', {- group: groupNameById.get(tx.group_id) ?? '',- })}+ <span className="truncate" title={groupBadgeLabel}>{groupBadgeLabel}</span></span>)}{/* The invoice this settles. Same badge shape as the split@@ -1152,10 +1166,10 @@ export default function TransactionsPage() {to="/rules?tab=queue"onClick={(e) => e.stopPropagation()}title={t('transactions.suggestionBadgeTooltip')}- className="inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-amber-700 bg-amber-50 border border-amber-200 dark:bg-amber-950/40 dark:text-amber-300 dark:border-amber-900 px-1.5 py-0.5 rounded-full hover:bg-amber-100 dark:hover:bg-amber-950/70 transition-colors"+ className="inline-flex max-w-full items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-amber-700 bg-amber-50 border border-amber-200 dark:bg-amber-950/40 dark:text-amber-300 dark:border-amber-900 px-1.5 py-0.5 rounded-full hover:bg-amber-100 dark:hover:bg-amber-950/70 transition-colors">- <HelpCircle className="h-3 w-3" />- {t('transactions.suggestionBadge')}+ <HelpCircle className="h-3 w-3 shrink-0" />+ <span className="truncate">{t('transactions.suggestionBadge')}</span></Link>)}{(tx.invoice_links ?? []).map((link) => (@@ -1164,20 +1178,27 @@ export default function TransactionsPage() {to={`/invoices/${link.invoice_id}`}onClick={(e) => e.stopPropagation()}title={t('transactions.invoiceBadgeTooltip')}- className="inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-emerald-700 bg-emerald-50 border border-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-300 dark:border-emerald-900 px-1.5 py-0.5 rounded-full hover:bg-emerald-100 dark:hover:bg-emerald-950/70 transition-colors"+ className="inline-flex max-w-full items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-emerald-700 bg-emerald-50 border border-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-300 dark:border-emerald-900 px-1.5 py-0.5 rounded-full hover:bg-emerald-100 dark:hover:bg-emerald-950/70 transition-colors">- <Receipt className="h-3 w-3" />- {link.external_number- ? t('transactions.invoiceBadge', { number: link.external_number })- : link.number != null- ? t('transactions.invoiceBadge', { number: link.number })- : t('transactions.invoiceBadgeNoNumber')}+ <Receipt className="h-3 w-3 shrink-0" />+ <span className="truncate">+ {link.external_number+ ? t('transactions.invoiceBadge', { number: link.external_number })+ : link.number != null+ ? t('transactions.invoiceBadge', { number: link.number })+ : t('transactions.invoiceBadgeNoNumber')}+ </span></Link>))}+ {/* The label and the two icons keep their size, so that a+ narrow column shortens the counterpart account name and+ not the word that says what the badge is. Past the point+ where even that no longer fits, the badge clips at the+ cell edge rather than carrying on into the next column. */}{isTransferTransaction(tx) && (- <span className="inline-flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wide text-blue-600 bg-blue-50 border border-blue-200 px-1.5 py-0.5 rounded-full">- <ArrowLeftRight className="h-3 w-3" />- {t('transactions.transfer')}+ <span className="inline-flex max-w-full items-center gap-1 overflow-hidden text-[10px] font-semibold uppercase tracking-wide text-blue-600 bg-blue-50 border border-blue-200 px-1.5 py-0.5 rounded-full">+ <ArrowLeftRight className="h-3 w-3 shrink-0" />+ <span className="shrink-0">{t('transactions.transfer')}</span>{tx.transfer_counterpart && (<Linkto={`/accounts/${tx.transfer_counterpart.account_id}`}@@ -1188,15 +1209,15 @@ export default function TransactionsPage() {{tx.transfer_counterpart.account_name}</Link>)}- <span title={t('transactions.transferTooltip')}><HelpCircle className="h-3 w-3 text-blue-400" /></span>+ <span className="shrink-0" title={t('transactions.transferTooltip')}><HelpCircle className="h-3 w-3 text-blue-400" /></span></span>)}{tx.is_ignored &&(- <span className="ml-2 inline-flex items-center gap-1 text-xs text-gray-600 font-normal bg-gray-100 border border-gray-200 rounded px-1.5 py-0.5">- <EyeClosed className="h-3 w-3" />- {t('transactions.ignored')}- <span title={t('transactions.ignoreTransferHint')}><HelpCircle className="h-3 w-3 text-blue-400" /></span>+ <span className="inline-flex max-w-full items-center gap-1 text-xs text-gray-600 font-normal bg-gray-100 border border-gray-200 rounded px-1.5 py-0.5">+ <EyeClosed className="h-3 w-3 shrink-0" />+ <span className="truncate">{t('transactions.ignored')}</span>+ <span className="shrink-0" title={t('transactions.ignoreTransferHint')}><HelpCircle className="h-3 w-3 text-blue-400" /></span></span>)}@@ -1204,23 +1225,23 @@ export default function TransactionsPage() {balance, so its amount keeps its colour and sign and onlythe badge marks it. Ignored greys the amount out instead. */}{tx.exclude_from_pnl && !tx.is_ignored && (- <span className="ml-2 inline-flex items-center gap-1 text-xs text-slate-600 font-normal bg-slate-100 border border-slate-200 rounded px-1.5 py-0.5 dark:text-slate-300 dark:bg-slate-500/15 dark:border-slate-500/30">- <ChartNoAxesColumn className="h-3 w-3" />- {t('transactions.excludedFromReports')}- <span title={t('transactions.excludeFromReportsHint')}><HelpCircle className="h-3 w-3 text-blue-400" /></span>+ <span className="inline-flex max-w-full items-center gap-1 text-xs text-slate-600 font-normal bg-slate-100 border border-slate-200 rounded px-1.5 py-0.5 dark:text-slate-300 dark:bg-slate-500/15 dark:border-slate-500/30">+ <ChartNoAxesColumn className="h-3 w-3 shrink-0" />+ <span className="truncate">{t('transactions.excludedFromReports')}</span>+ <span className="shrink-0" title={t('transactions.excludeFromReportsHint')}><HelpCircle className="h-3 w-3 text-blue-400" /></span></span>)}{tx.recurring_transaction_id != null && (<span- className="text-[10px] font-semibold uppercase tracking-wide text-primary bg-primary/5 border border-primary/10 px-1.5 py-0.5 rounded-full"+ className="inline-flex max-w-full items-center text-[10px] font-semibold uppercase tracking-wide text-primary bg-primary/5 border border-primary/10 px-1.5 py-0.5 rounded-full"title={t('transactions.recurringLinkedTooltip')}>- {t('transactions.recurringBadge')}+ <span className="truncate">{t('transactions.recurringBadge')}</span></span>)}{tx.installment_number != null && tx.total_installments != null && (<span- className="inline-flex items-center text-[10px] font-bold tabular-nums text-amber-700 dark:text-amber-400 bg-amber-100 dark:bg-amber-500/20 border border-amber-200 dark:border-amber-500/30 px-1.5 py-0.5 rounded-full"+ className="inline-flex shrink-0 items-center text-[10px] font-bold tabular-nums text-amber-700 dark:text-amber-400 bg-amber-100 dark:bg-amber-500/20 border border-amber-200 dark:border-amber-500/30 px-1.5 py-0.5 rounded-full"title={tx.installment_total_amount != null? t('transactions.installmentTooltip', { count: tx.total_installments, total: tx.installment_total_amount }): undefined}