A local-first personal finance app
[AI] Fix shift-click range selection including hidden reconciled transactions (#8177)
Augusto Xavier061004b0b104
diff --git a/packages/desktop-client/e2e/accounts.test.ts b/packages/desktop-client/e2e/accounts.test.tsindex 3010eb0f04..fa6b1583c3 100644--- a/packages/desktop-client/e2e/accounts.test.ts+++ b/packages/desktop-client/e2e/accounts.test.ts@@ -56,6 +56,68 @@ test.describe('Accounts', () => {await expect(page).toMatchThemeScreenshots();});+ test('shift-click range selection skips hidden reconciled transactions', async () => {+ accountPage = await navigation.createAccount({+ name: 'Range Select',+ offBudget: false,+ balance: 0,+ });+ await accountPage.waitFor();++ // Newest transactions are shown first, so the rows read+ // 'range-three' through 'range-one' from top to bottom.+ for (const note of ['one', 'two', 'three']) {+ await accountPage.createSingleTransaction({+ payee: '',+ notes: `range-${note}`,+ debit: '10.00',+ });+ }++ // Mark the middle transaction as cleared and lock it via+ // reconciliation so it becomes reconciled.+ await accountPage.transactionTableRow+ .filter({ hasText: 'range-two' })+ .getByTestId('cleared')+ .click();++ await page.getByRole('button', { name: 'Reconcile' }).click();+ // The reconciliation amount is pre-filled with the cleared balance,+ // so submitting right away results in a zero difference.+ const reconcilePopover = page.locator('[data-popover]');+ await reconcilePopover.getByRole('textbox').waitFor();+ await reconcilePopover.getByRole('button', { name: 'Reconcile' }).click();+ await page.getByRole('button', { name: 'Lock transactions' }).click();++ // Showing the running balance keeps reconciled transactions loaded+ // even when they are hidden; they must still be excluded from+ // range selection.+ await accountPage.accountMenuButton.click();+ await page.getByRole('button', { name: 'Show running balance' }).click();+ await accountPage.accountMenuButton.click();+ await page+ .getByRole('button', { name: 'Hide reconciled transactions' })+ .click();++ await expect(+ accountPage.transactionTableRow.filter({ hasText: 'range-two' }),+ ).not.toBeVisible();++ // Shift-click from the first to the last visible transaction.+ await accountPage.transactionTableRow+ .filter({ hasText: 'range-three' })+ .getByTestId('select')+ .click();+ await accountPage.transactionTableRow+ .filter({ hasText: 'range-one' })+ .getByTestId('select')+ .click({ modifiers: ['Shift'] });++ // Only the two visible transactions should be selected — not the+ // hidden reconciled one in between.+ await expect(accountPage.selectButton).toHaveText('2 transactions');+ });+test.describe('On Budget Accounts', () => {// Reset filterstest.afterEach(async () => {diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex 07bd64658a..0b4ca24606 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -1771,7 +1771,16 @@ class AccountInternal extends PureComponent<{(allTransactions, allBalances) => (<SelectedProviderWithItemsname="transactions"- items={allTransactions}+ // When reconciled transactions are hidden they are still+ // loaded (e.g. to calculate running balances), but they must+ // not be selectable. Mirror the filtering the transaction+ // table applies when rendering so that range selection+ // (shift+click) only covers visible transactions.+ items={+ showReconciled+ ? allTransactions+ : allTransactions.filter(t => !t.reconciled)+ }fetchAllIds={this.fetchAllIds}registerDispatch={dispatch => (this.dispatchSelected = dispatch)}selectAllFilter={selectAllFilter}diff --git a/packages/desktop-client/src/hooks/useSelected.test.ts b/packages/desktop-client/src/hooks/useSelected.test.tsnew file mode 100644index 0000000000..7878b46dba--- /dev/null+++ b/packages/desktop-client/src/hooks/useSelected.test.ts@@ -0,0 +1,71 @@+import { act, renderHook } from '@testing-library/react';++import { useSelected } from './useSelected';++vi.mock(+ '@actual-app/core/platform/client/connection',+ () => import('#mocks/connection'),+);++type TestItem = { id: string };++function renderUseSelected(initialItems: TestItem[]) {+ return renderHook(+ ({ items }: { items: TestItem[] }) => useSelected('test', items, []),+ { initialProps: { items: initialItems } },+ );+}++describe('useSelected', () => {+ it('selects and deselects a single item', () => {+ const { result } = renderUseSelected([{ id: 'one' }, { id: 'two' }]);++ act(() => result.current.dispatch({ type: 'select', id: 'one' }));+ expect(result.current.items).toEqual(new Set(['one']));++ act(() => result.current.dispatch({ type: 'select', id: 'one' }));+ expect(result.current.items).toEqual(new Set());+ });++ it('range selection covers only the items passed to the hook', () => {+ // The account register passes only the visible transactions as+ // `items` (e.g. hidden reconciled transactions are excluded).+ // Range selection operates on indexes of `items`, so it must+ // select exactly the visible transactions in the range.+ const visibleItems = [{ id: 'one' }, { id: 'three' }, { id: 'five' }];+ const { result } = renderUseSelected(visibleItems);++ act(() => result.current.dispatch({ type: 'select', id: 'one' }));+ act(() =>+ result.current.dispatch({+ type: 'select',+ id: 'five',+ isRangeSelect: true,+ }),+ );++ expect(result.current.items).toEqual(new Set(['one', 'three', 'five']));+ });++ it('removes selected ids that are no longer in items', () => {+ // Simulates hiding transactions (e.g. toggling “hide reconciled+ // transactions”) while they are selected: the selection must be+ // pruned to the items that are still visible.+ const allItems = [{ id: 'one' }, { id: 'two' }, { id: 'three' }];+ const { result, rerender } = renderUseSelected(allItems);++ act(() => result.current.dispatch({ type: 'select', id: 'one' }));+ act(() =>+ result.current.dispatch({+ type: 'select',+ id: 'three',+ isRangeSelect: true,+ }),+ );+ expect(result.current.items).toEqual(new Set(['one', 'two', 'three']));++ rerender({ items: [{ id: 'one' }, { id: 'three' }] });++ expect(result.current.items).toEqual(new Set(['one', 'three']));+ });+});diff --git a/upcoming-release-notes/8177.md b/upcoming-release-notes/8177.mdnew file mode 100644index 0000000000..b5f1eea363--- /dev/null+++ b/upcoming-release-notes/8177.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [augustocbx]+---++Fix shift-click selection including hidden reconciled transactions in the account view