Skip to content

Commit

Permalink
Filter Balance fix (#2777)
Browse files Browse the repository at this point in the history
* filterQuery

* notes

* update

* lint fix

* VRT

* fix account filter

* VRT

---------

Co-authored-by: youngcw <calebyoung94@gmail.com>
  • Loading branch information
carkom and youngcw committed May 29, 2024
1 parent e4bc0ca commit 1195af7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,26 @@ class AccountInternal extends PureComponent {
};
}

getFilteredAmount = async (filters, conditionsOpKey) => {
const filter = queries.getAccountFilter(this.props.accountId);

let query = q('transactions').filter({
[conditionsOpKey]: [...filters],
});
if (filter) {
query = query.filter(filter);
}

const filteredQuery = await runQuery(
query.select([{ amount: { $sum: '$amount' } }]),
);
const filteredAmount = filteredQuery.data.reduce(
(a, v) => (a = a + v.amount),
0,
);
return filteredAmount;
};

isNew = id => {
return this.props.newTransactions.includes(id);
};
Expand Down Expand Up @@ -1307,6 +1327,10 @@ class AccountInternal extends PureComponent {
conditions: conditions.filter(cond => !cond.customName),
});
const conditionsOpKey = this.state.conditionsOp === 'or' ? '$or' : '$and';
this.filteredAmount = await this.getFilteredAmount(
filters,
conditionsOpKey,
);
this.currentQuery = this.rootQuery.filter({
[conditionsOpKey]: [...filters, ...customFilters],
});
Expand Down Expand Up @@ -1524,6 +1548,7 @@ class AccountInternal extends PureComponent {
>
<View style={styles.page}>
<AccountHeader
filteredAmount={this.filteredAmount}
tableRef={this.table}
editingName={editingName}
isNameEditable={isNameEditable}
Expand Down
12 changes: 4 additions & 8 deletions packages/desktop-client/src/components/accounts/Balance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ function SelectedBalance({ selectedItems, account }) {
);
}

function FilteredBalance({ selectedItems }) {
const balance = selectedItems
.filter(item => !item._unmatched && !item.is_parent)
.reduce((sum, product) => sum + product.amount, 0);

function FilteredBalance({ filteredAmount }) {
return (
<DetailedBalance
name="Filtered balance:"
balance={balance}
balance={filteredAmount || 0}
isExactBalance={true}
/>
);
Expand Down Expand Up @@ -142,7 +138,7 @@ export function Balances({
onToggleExtraBalances,
account,
filteredItems,
transactions,
filteredAmount,
}) {
const selectedItems = useSelectedItems();

Expand Down Expand Up @@ -201,7 +197,7 @@ export function Balances({
<SelectedBalance selectedItems={selectedItems} account={account} />
)}
{filteredItems.length > 0 && (
<FilteredBalance selectedItems={transactions} />
<FilteredBalance filteredAmount={filteredAmount} />
)}
</View>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/accounts/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Balances } from './Balance';
import { ReconcilingMessage, ReconcileTooltip } from './Reconcile';

export function AccountHeader({
filteredAmount,
tableRef,
editingName,
isNameEditable,
Expand Down Expand Up @@ -242,7 +243,7 @@ export function AccountHeader({
onToggleExtraBalances={onToggleExtraBalances}
account={account}
filteredItems={filters}
transactions={transactions}
filteredAmount={filteredAmount}
/>

<Stack
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2777.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [carkom]
---

On the accounts page - filter balance only adds up transactions that are showing. If your filter has more than one page it won't be added to the balance unless you scroll to the bottom and reveal all transactions. This fixes that.

0 comments on commit 1195af7

Please sign in to comment.