diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsx
index a6e5fe2bbc..96dddd6266 100644
--- a/packages/desktop-client/src/components/accounts/Account.jsx
+++ b/packages/desktop-client/src/components/accounts/Account.jsx
@@ -315,7 +315,7 @@ class AccountInternal extends PureComponent {
fetchTransactions = filters => {
const query = this.makeRootQuery();
- this.rootQuery = this.currentQuery = this.filterQuery = query;
+ this.rootQuery = this.currentQuery = query;
if (filters) this.applyFilters(filters);
else this.updateQuery(query);
@@ -680,16 +680,20 @@ class AccountInternal extends PureComponent {
};
}
- getFilterQuery(filters, conditionsOpKey) {
- return {
- name: `filtered-query`,
- query: this.makeRootQuery()
+ getFilteredAmount = async (filters, conditionsOpKey) => {
+ const filteredQuery = await runQuery(
+ q('transactions')
.filter({
[conditionsOpKey]: [...filters],
})
- .calculate({ $sum: '$amount' }),
- };
- }
+ .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);
@@ -1312,7 +1316,7 @@ class AccountInternal extends PureComponent {
conditions: conditions.filter(cond => !cond.customName),
});
const conditionsOpKey = this.state.conditionsOp === 'or' ? '$or' : '$and';
- this.filterQuery = this.getFilterQuery(filters, conditionsOpKey);
+ this.filteredAmount = await this.getFilteredAmount(filters, conditionsOpKey);
this.currentQuery = this.rootQuery.filter({
[conditionsOpKey]: [...filters, ...customFilters],
});
@@ -1530,7 +1534,7 @@ class AccountInternal extends PureComponent {
>
);
@@ -143,7 +138,7 @@ export function Balances({
onToggleExtraBalances,
account,
filteredItems,
- filterQuery,
+ filteredAmount,
}) {
const selectedItems = useSelectedItems();
@@ -202,7 +197,7 @@ export function Balances({
)}
{filteredItems.length > 0 && (
-
+
)}
);
diff --git a/packages/desktop-client/src/components/accounts/Header.jsx b/packages/desktop-client/src/components/accounts/Header.jsx
index 296bbf98ca..a3daf4b750 100644
--- a/packages/desktop-client/src/components/accounts/Header.jsx
+++ b/packages/desktop-client/src/components/accounts/Header.jsx
@@ -32,7 +32,7 @@ import { Balances } from './Balance';
import { ReconcilingMessage, ReconcileTooltip } from './Reconcile';
export function AccountHeader({
- filterQuery,
+ filteredAmount,
tableRef,
editingName,
isNameEditable,
@@ -243,7 +243,7 @@ export function AccountHeader({
onToggleExtraBalances={onToggleExtraBalances}
account={account}
filteredItems={filters}
- filterQuery={filterQuery}
+ filteredAmount={filteredAmount}
/>