Skip to content

A local-first personal finance app

[AI] Add toggleable Group column to transaction list (#8441)

Ngoc Do79f7860cca17
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index aa2afb36ae..1de7a9da65 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -219,6 +219,8 @@ type AccountInternalProps = {
setShowCleared: (newValue: boolean) => void;
showReconciled: boolean;
setShowReconciled: (newValue: boolean) => void;
+ showGroup: boolean;
+ setShowGroup: (newValue: boolean) => void;
showExtraBalances?: boolean;
setShowExtraBalances: (newValue: boolean) => void;
modalShowing?: boolean;
@@ -270,6 +272,7 @@ type AccountInternalState = {
showCleared?: boolean | undefined;
prevShowCleared?: boolean | undefined;
showReconciled: boolean;
+ showGroup: boolean;
nameError: string;
isAdding: boolean;
modalShowing?: boolean;
@@ -320,6 +323,7 @@ class AccountInternal extends PureComponent<
balances: null,
showCleared: props.showCleared,
showReconciled: props.showReconciled,
+ showGroup: props.showGroup,
nameError: '',
isAdding: false,
sort: null,
@@ -566,6 +570,7 @@ class AccountInternal extends PureComponent<
balances: null,
showCleared: nextProps.showCleared,
showReconciled: nextProps.showReconciled,
+ showGroup: nextProps.showGroup,
reconcileAmount: null,
},
() => {
@@ -810,6 +815,7 @@ class AccountInternal extends PureComponent<
| 'remove-sorting'
| 'toggle-cleared'
| 'toggle-reconciled'
+ | 'toggle-group'
| 'toggle-net-worth-chart',
) => {
const accountId = this.props.accountId!;
@@ -912,6 +918,15 @@ class AccountInternal extends PureComponent<
);
}
break;
+ case 'toggle-group':
+ if (this.state.showGroup) {
+ this.props.setShowGroup(false);
+ this.setState({ showGroup: false });
+ } else {
+ this.props.setShowGroup(true);
+ this.setState({ showGroup: true });
+ }
+ break;
case 'toggle-net-worth-chart':
if (this.props.showNetWorthChart) {
this.props.setShowNetWorthChart(false);
@@ -1701,6 +1716,7 @@ class AccountInternal extends PureComponent<
balances,
showCleared,
showReconciled,
+ showGroup,
filteredAmount,
} = this.state;
@@ -1777,6 +1793,7 @@ class AccountInternal extends PureComponent<
showExtraBalances={showExtraBalances ?? false}
showCleared={showCleared ?? false}
showReconciled={showReconciled ?? false}
+ showGroup={showGroup}
showEmptyMessage={showEmptyMessage ?? false}
balanceQuery={balanceQuery}
canCalculateBalance={this?.canCalculateBalance ?? undefined}
@@ -1841,6 +1858,7 @@ class AccountInternal extends PureComponent<
showBalances={!!allBalances}
showReconciled={showReconciled}
showCleared={!!showCleared}
+ showGroup={showGroup}
showAccount={
!accountId ||
accountId === 'offbudget' ||
@@ -1980,6 +1998,9 @@ export function Account() {
const [hideReconciled, setHideReconciled] = useSyncedPref(
`hide-reconciled-${params.id}`,
);
+ const [showGroup, setShowGroup] = useSyncedPref(
+ `show-group-${params.id || 'all-accounts'}`,
+ );
const [showExtraBalances, setShowExtraBalances] = useSyncedPref(
`show-extra-balances-${params.id || 'all-accounts'}`,
);
@@ -2035,6 +2056,8 @@ export function Account() {
setShowCleared={val => setHideCleared(String(!val))}
showReconciled={String(hideReconciled) !== 'true'}
setShowReconciled={val => setHideReconciled(String(!val))}
+ showGroup={String(showGroup) === 'true'}
+ setShowGroup={val => setShowGroup(String(val))}
showExtraBalances={String(showExtraBalances) === 'true'}
setShowExtraBalances={extraBalances =>
setShowExtraBalances(String(extraBalances))
diff --git a/packages/desktop-client/src/components/accounts/Header.tsx b/packages/desktop-client/src/components/accounts/Header.tsx
index 7d18353b46..873bafd257 100644
--- a/packages/desktop-client/src/components/accounts/Header.tsx
+++ b/packages/desktop-client/src/components/accounts/Header.tsx
@@ -71,6 +71,7 @@ type AccountHeaderProps = {
showExtraBalances: boolean;
showCleared: boolean;
showReconciled: boolean;
+ showGroup: boolean;
showEmptyMessage: boolean;
balanceQuery: ComponentProps<typeof ReconcilingMessage>['balanceQuery'];
reconcileAmount?: number | null;
@@ -146,6 +147,7 @@ export function AccountHeader({
showExtraBalances,
showCleared,
showReconciled,
+ showGroup,
showEmptyMessage,
balanceQuery,
reconcileAmount,
@@ -516,6 +518,7 @@ export function AccountHeader({
showBalances={showBalances}
showCleared={showCleared}
showReconciled={showReconciled}
+ showGroup={showGroup}
onMenuSelect={onMenuSelect}
/>
</Dialog>
@@ -548,6 +551,12 @@ export function AccountHeader({
]
: []),
{ name: 'export', text: t('Export') },
+ {
+ name: 'toggle-group',
+ text: showGroup
+ ? t('Hide category group')
+ : t('Show category group'),
+ },
{
name: 'toggle-net-worth-chart',
text: showNetWorthChart
@@ -731,6 +740,7 @@ type AccountMenuProps = {
canShowBalances: boolean;
showCleared: boolean;
showReconciled: boolean;
+ showGroup: boolean;
isSorted: boolean;
onMenuSelect: (
item:
@@ -743,6 +753,7 @@ type AccountMenuProps = {
| 'remove-sorting'
| 'toggle-cleared'
| 'toggle-reconciled'
+ | 'toggle-group'
| 'toggle-net-worth-chart',
) => void;
};
@@ -755,6 +766,7 @@ function AccountMenu({
canShowBalances,
showCleared,
showReconciled,
+ showGroup,
isSorted,
onMenuSelect,
}: AccountMenuProps) {
@@ -804,6 +816,10 @@ function AccountMenu({
? t('Hide reconciled transactions')
: t('Show reconciled transactions'),
},
+ {
+ name: 'toggle-group',
+ text: showGroup ? t('Hide category group') : t('Show category group'),
+ },
{ name: 'export', text: t('Export') },
...(account && !account.closed
? canSync
diff --git a/packages/desktop-client/src/components/transactions/TransactionList.tsx b/packages/desktop-client/src/components/transactions/TransactionList.tsx
index dc5b27da05..7f5e3c2acb 100644
--- a/packages/desktop-client/src/components/transactions/TransactionList.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionList.tsx
@@ -266,6 +266,7 @@ type TransactionListProps = Pick<
| 'showAccount'
| 'showBalances'
| 'showCleared'
+ | 'showGroup'
| 'showReconciled'
| 'showSelection'
| 'sortField'
@@ -301,6 +302,7 @@ export function TransactionList({
showBalances,
showReconciled,
showCleared,
+ showGroup,
showAccount,
isAdding,
isNew,
@@ -741,6 +743,7 @@ export function TransactionList({
showCleared={showCleared}
showAccount={showAccount}
showCategory
+ showGroup={showGroup}
currentAccountId={account && account.id}
currentCategoryId={category && category.id}
isAdding={isAdding}
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
index 8473e48440..ed4b4a3f06 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.test.tsx
@@ -148,6 +148,7 @@ type LiveTransactionTableProps = {
currentAccountId: string | null;
showAccount: boolean;
showCategory: boolean;
+ showGroup?: boolean;
showCleared: boolean;
isAdding: boolean;
onTransactionsChange?: (newTrans: TransactionEntity[]) => void;
@@ -534,6 +535,56 @@ describe('Transactions', () => {
});
});
+ describe('Group column', () => {
+ test('group column is hidden by default', () => {
+ const { container } = renderTransactions();
+ expect(
+ container.querySelector('[data-testid="group"]'),
+ ).not.toBeInTheDocument();
+ });
+
+ test('group column header renders when showGroup is true', () => {
+ const { container } = renderTransactions({ showGroup: true });
+ expect(
+ container.querySelector(
+ '[data-testid="transaction-table"] [data-testid="group"]',
+ ),
+ ).toBeInTheDocument();
+ });
+
+ test('group cell shows the correct group name', () => {
+ const { container } = renderTransactions({ showGroup: true });
+
+ // Transaction 0 has no category — group cell should be empty
+ expect(queryField(container, 'group', 'div', 0).textContent).toBe('');
+
+ // Transaction 1 has category "General" in group "Usual Expenses"
+ expect(queryField(container, 'group', 'div', 1).textContent).toBe(
+ 'Usual Expenses',
+ );
+
+ // Transaction 2 has category "Food" in group "Usual Expenses"
+ expect(queryField(container, 'group', 'div', 2).textContent).toBe(
+ 'Usual Expenses',
+ );
+ });
+
+ test('group column renders for child transactions as well', () => {
+ const transactions = generateTransactions(3, [1]);
+ transactions[0].amount = -1000;
+
+ const { container } = renderTransactions({
+ showGroup: true,
+ transactions,
+ });
+
+ const children = container.querySelectorAll(
+ '[data-testid="transaction-table"] [data-testid="group"]',
+ );
+ expect(children.length).toBe(5);
+ });
+ });
+
test('keybindings enter/tab/alt should move around', async () => {
const { container } = renderTransactions();
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index 2ea5963742..d0fa62d9bc 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -158,6 +158,7 @@ type TransactionHeaderProps = {
hasSelected: boolean;
showAccount: boolean;
showCategory: boolean;
+ showGroup?: boolean;
showBalance: boolean;
showCleared: boolean;
scrollWidth: number;
@@ -172,6 +173,7 @@ const TransactionHeader = memo(
hasSelected,
showAccount,
showCategory,
+ showGroup,
showBalance,
showCleared,
scrollWidth,
@@ -279,6 +281,15 @@ const TransactionHeader = memo(
onSort('notes', selectAscDesc(field, ascDesc, 'notes', 'asc'))
}
/>
+ {showGroup && (
+ <HeaderCell
+ value={t('Group')}
+ width="flex"
+ alignItems="flex"
+ marginLeft={-5}
+ id="group"
+ />
+ )}
{showCategory && (
<HeaderCell
value={t('Category')}
@@ -924,6 +935,7 @@ type TransactionProps = {
};
editing: boolean;
showAccount?: boolean;
+ showGroup?: boolean;
showBalance?: boolean;
showCleared?: boolean;
showZeroInDeposit?: boolean;
@@ -991,6 +1003,7 @@ const Transaction = memo(function Transaction({
transferAccountsByTransaction,
editing,
showAccount,
+ showGroup,
showBalance,
showCleared,
showZeroInDeposit,
@@ -1657,6 +1670,23 @@ const Transaction = memo(function Transaction({
onExpose={name => !isPreview && onEdit(id, name)}
/>
+ {showGroup && (
+ <Cell
+ name="group"
+ width="flex"
+ style={{
+ fontStyle: 'italic',
+ color: theme.pageTextSubdued,
+ fontWeight: 300,
+ }}
+ value={
+ categoryId
+ ? (getGroupByCatId(categoryGroups)[categoryId]?.name ?? '')
+ : ''
+ }
+ />
+ )}
+
{(isPreview && !isChild) || isParent ? (
<Cell
/* Category field (Split button) for parent transactions */
@@ -2179,6 +2209,7 @@ type NewTransactionProps = {
onSplit: (id: TransactionEntity['id']) => void;
payees: PayeeEntity[];
showAccount?: boolean;
+ showGroup?: boolean;
showBalance?: boolean;
balance?: number | null;
showCleared?: boolean;
@@ -2197,6 +2228,7 @@ function NewTransaction({
editingTransaction,
focusedField,
showAccount,
+ showGroup,
showBalance,
showCleared,
dateFormat,
@@ -2262,6 +2294,7 @@ function NewTransaction({
subtransactions={transaction.is_parent ? childTransactions : null}
transferAccountsByTransaction={transferAccountsByTransaction}
showAccount={showAccount}
+ showGroup={showGroup}
showBalance={showBalance}
showCleared={showCleared}
focusedField={
@@ -2360,6 +2393,7 @@ type TransactionTableInnerProps = {
showCleared: boolean;
showAccount: boolean;
showCategory: boolean;
+ showGroup?: boolean;
currentAccountId: AccountEntity['id'];
currentCategoryId: CategoryEntity['id'];
isAdding: boolean;
@@ -2496,6 +2530,7 @@ function TransactionTableInner({
payees,
showCleared,
showAccount,
+ showGroup,
showBalances,
balances,
hideFraction,
@@ -2568,6 +2603,7 @@ function TransactionTableInner({
transferAccountsByTransaction={props.transferAccountsByTransaction}
subtransactions={childTransactions}
showAccount={showAccount}
+ showGroup={showGroup}
showBalance={showBalances}
showCleared={showCleared}
selected={selected}
@@ -2646,6 +2682,7 @@ function TransactionTableInner({
hasSelected={props.selectedItems.size > 0}
showAccount={props.showAccount}
showCategory={props.showCategory}
+ showGroup={props.showGroup}
showBalance={props.showBalances}
showCleared={props.showCleared}
scrollWidth={scrollWidth}
@@ -2672,6 +2709,7 @@ function TransactionTableInner({
categoryGroups={props.categoryGroups}
payees={props.payees || []}
showAccount={props.showAccount}
+ showGroup={props.showGroup}
showBalance={props.showBalances}
showCleared={props.showCleared}
dateFormat={dateFormat}
@@ -2754,6 +2792,7 @@ export type TransactionTableProps = {
showCleared: boolean;
showAccount: boolean;
showCategory: boolean;
+ showGroup?: boolean;
currentAccountId: AccountEntity['id'];
currentCategoryId: CategoryEntity['id'];
isAdding: boolean;
@@ -3056,6 +3095,7 @@ export const TransactionTable = forwardRef(
'account',
'payee',
'notes',
+ 'group',
'category',
'debit',
'credit',
@@ -3074,6 +3114,7 @@ export const TransactionTable = forwardRef(
'account',
'payee',
'notes',
+ 'group',
'category',
'debit',
'credit',
@@ -3089,7 +3130,8 @@ export const TransactionTable = forwardRef(
: fields.filter(
f =>
(props.showAccount || f !== 'account') &&
- (props.showCategory || f !== 'category'),
+ (props.showCategory || f !== 'category') &&
+ (props.showGroup || f !== 'group'),
);
if (item?.id && isPreviewId(item.id)) {
@@ -3605,3 +3647,16 @@ const getCategoriesById = memoizeOne(
return res;
},
);
+
+const getGroupByCatId = memoizeOne(
+ (categoryGroups: CategoryGroupEntity[] | null | undefined) => {
+ const res: { [id: CategoryEntity['id']]: CategoryGroupEntity } = {};
+ categoryGroups?.forEach(group => {
+ group.categories?.forEach(cat => {
+ res[cat.id] = group;
+ });
+ });
+
+ return res;
+ },
+);
diff --git a/packages/loot-core/src/types/prefs.ts b/packages/loot-core/src/types/prefs.ts
index 253c94e60d..4f3f3ccf54 100644
--- a/packages/loot-core/src/types/prefs.ts
+++ b/packages/loot-core/src/types/prefs.ts
@@ -33,6 +33,7 @@ export type SyncedPrefs = Partial<
| `show-extra-balances-${string}`
| `hide-cleared-${string}`
| `hide-reconciled-${string}`
+ | `show-group-${string}`
// TODO: pull from src/components/modals/ImportTransactions.js
| `parse-date-${string}-${'csv' | 'qif'}`
| `import-reimport-deleted-${string}`
diff --git a/upcoming-release-notes/show-group-column.md b/upcoming-release-notes/show-group-column.md
new file mode 100644
index 0000000000..7e548f2e3e
--- /dev/null
+++ b/upcoming-release-notes/show-group-column.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [ngoc-minh-do]
+---
+
+Add Group column to the transaction list to show which category group each transaction belongs to