Skip to content

A local-first personal finance app

[AI] Keep transactions after sorting by date with hidden reconciled ones (#9363)

Martin Boucherc7904f00db5e
diff --git a/packages/desktop-client/e2e/accounts.test.ts b/packages/desktop-client/e2e/accounts.test.ts
index eec5673971..3832b9abac 100644
--- a/packages/desktop-client/e2e/accounts.test.ts
+++ b/packages/desktop-client/e2e/accounts.test.ts
@@ -301,6 +301,76 @@ test.describe('Accounts', () => {
).not.toBeVisible();
});
+ test('keeps unreconciled transactions after sorting with hidden reconciled ones', async () => {
+ accountPage = await navigation.createAccount({
+ name: 'Sort Hidden Reconciled',
+ offBudget: false,
+ balance: 0,
+ });
+ await accountPage.waitFor();
+
+ async function importRows(rows: string[]) {
+ const fileChooserPromise = page.waitForEvent('filechooser');
+ await page.getByRole('button', { name: 'Import' }).click();
+ const fileChooser = await fileChooserPromise;
+ await fileChooser.setFiles({
+ name: 'transactions.csv',
+ mimeType: 'text/csv',
+ buffer: Buffer.from(
+ ['Date,Payee,Notes,Category,Amount', ...rows].join('\n'),
+ ),
+ });
+ const importButton = page.getByRole('button', {
+ name: /Import \d+ transactions?/,
+ });
+ await importButton.click();
+ await expect(importButton).not.toBeVisible();
+ }
+
+ // More reconciled transactions than a single page of results (150),
+ // all older than the unreconciled one, so sorting by oldest first
+ // fills the first page with hidden transactions only.
+ await importRows(
+ Array.from(
+ { length: 160 },
+ (_, i) =>
+ `2024-01-${String((i % 28) + 1).padStart(2, '0')},Old ${i},,,-1.00`,
+ ),
+ );
+
+ await page.getByRole('button', { name: 'Reconcile' }).click();
+ 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();
+
+ await importRows(['2024-06-01,Recent,not-reconciled,,-10.00']);
+
+ await accountPage.setTransactionColumnVisibility('balance', true);
+ await accountPage.accountMenuButton.click();
+ await page
+ .getByRole('button', { name: 'Hide reconciled transactions' })
+ .click();
+
+ const unreconciled = accountPage.transactionTableRow.filter({
+ hasText: 'not-reconciled',
+ });
+ await expect(unreconciled).toBeVisible();
+
+ // Each click toggles the order: newest first, oldest first, then
+ // newest first again.
+ const dateHeader = page.getByRole('button', { name: 'Date', exact: true });
+ await dateHeader.click();
+ await dateHeader.click();
+
+ await expect(unreconciled).toBeVisible();
+
+ await dateHeader.click();
+
+ // The running balance still counts the hidden reconciled transactions.
+ await expect(unreconciled.getByTestId('balance')).toHaveText('-170.00');
+ });
+
test('opens the other side of a transfer from its arrow', async () => {
accountPage = await navigation.goToAccountPage('Bank of America');
await accountPage.createSingleTransaction({
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index b3e4382349..0a740e40c9 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -1800,36 +1800,46 @@ class AccountInternal extends PureComponent<
onSort = (headerClicked: string, ascDesc: 'asc' | 'desc') => {
let prevField: string | undefined;
let prevAscDesc: 'asc' | 'desc' | undefined;
+ // Query once the new sort is in state: whether running balances can be
+ // shown, and so whether hidden reconciled transactions are loaded,
+ // depends on it.
+ const sortAndSearch = () => {
+ this.applySort(headerClicked, ascDesc, prevField, prevAscDesc);
+ if (this.state.search !== '') {
+ this.onSearch(this.state.search);
+ }
+ };
//if staying on same column but switching asc/desc
//then keep prev the same
if (headerClicked === this.state.sort?.field) {
prevField = this.state.sort.prevField;
prevAscDesc = this.state.sort.prevAscDesc;
- this.setState(state => ({
- sort: {
- ...state.sort,
- field: headerClicked,
- ascDesc,
- },
- }));
+ this.setState(
+ state => ({
+ sort: {
+ ...state.sort,
+ field: headerClicked,
+ ascDesc,
+ },
+ }),
+ sortAndSearch,
+ );
} else {
//if switching to new column then capture state
//of current sort column as prev
prevField = this.state.sort?.field;
prevAscDesc = this.state.sort?.ascDesc;
- this.setState(state => ({
- sort: {
- field: headerClicked,
- ascDesc,
- prevField: state.sort?.field,
- prevAscDesc: state.sort?.ascDesc,
- },
- }));
- }
-
- this.applySort(headerClicked, ascDesc, prevField, prevAscDesc);
- if (this.state.search !== '') {
- this.onSearch(this.state.search);
+ this.setState(
+ state => ({
+ sort: {
+ field: headerClicked,
+ ascDesc,
+ prevField: state.sort?.field,
+ prevAscDesc: state.sort?.ascDesc,
+ },
+ }),
+ sortAndSearch,
+ );
}
};
diff --git a/upcoming-release-notes/keep-transactions-after-sorting-with-hidden-reconciled.md b/upcoming-release-notes/keep-transactions-after-sorting-with-hidden-reconciled.md
new file mode 100644
index 0000000000..31cd02518c
--- /dev/null
+++ b/upcoming-release-notes/keep-transactions-after-sorting-with-hidden-reconciled.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [boutchitos]
+---
+
+Keep transactions and running balances after sorting by date while reconciled transactions are hidden