Skip to content

Commit

Permalink
Make transaction list sortable by cleared status
Browse files Browse the repository at this point in the history
  • Loading branch information
jaarasys-henria committed Feb 1, 2024
1 parent 43ebe9e commit 8e11484
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 21 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.
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.
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.
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.
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.
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.
81 changes: 61 additions & 20 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,10 @@ class AccountInternal extends PureComponent {
}
};


Check warning on line 1200 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
applySort = (field, ascDesc, prevField, prevAscDesc) => {
const filters = this.state.filters;
const isFiltered = (filters.length > 0)

Check warning on line 1203 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Replace `(filters.length·>·0)` with `filters.length·>·0;`
const sortField = getField(!field ? this.state.sort.field : field);
const sortAscDesc = !ascDesc ? this.state.sort.ascDesc : ascDesc;
const sortPrevField = getField(
Expand All @@ -1208,34 +1210,73 @@ class AccountInternal extends PureComponent {
? this.state.sort.prevAscDesc
: prevAscDesc;

if (!field) {
//no sort was made (called by applyFilters)
this.currentQuery = this.currentQuery.orderBy({
const sortCurrentQuery = function(that, sortField, sortAscDesc) {

Check warning on line 1213 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
if (sortField === 'cleared') {
that.currentQuery = that.currentQuery.orderBy({
['reconciled']: sortAscDesc,

Check warning on line 1216 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessarily computed property ['reconciled'] found
});
}

that.currentQuery = that.currentQuery.orderBy({
[sortField]: sortAscDesc,
});
} else {
//sort called directly
if (filters.length > 0) {
//if filters already exist then apply them
this.applyFilters([...filters]);
this.currentQuery = this.currentQuery.orderBy({
[sortField]: sortAscDesc,
});
} else {
//no filters exist make new rootquery
this.currentQuery = this.rootQuery.orderBy({
[sortField]: sortAscDesc,
}

Check warning on line 1223 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

const sortRootQuery = function(that, sortField, sortAscDesc) {

Check warning on line 1225 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
// sort cleared field by reconciliation status first

Check warning on line 1226 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `······`
if (sortField === 'cleared') {

Check warning on line 1227 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
that.currentQuery = that.rootQuery.orderBy({

Check warning on line 1228 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Replace `··········` with `········`
['reconciled']: sortAscDesc,

Check warning on line 1229 in packages/desktop-client/src/components/accounts/Account.jsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
});
that.currentQuery = that.currentQuery.orderBy({
['cleared']: sortAscDesc,
});
} else {
that.currentQuery = that.rootQuery.orderBy({
[sortField]: sortAscDesc,
});
}
}

// sort by previously used sort field, if any
const maybeSortByPreviousField = function(that, sortPrevField, sortPrevAscDesc) {
if (!sortPrevField) {
return;
}

if (sortPrevField === 'cleared') {
that.currentQuery = that.currentQuery.orderBy({
['reconciled']: sortPrevAscDesc,
});
}
}
if (sortPrevField) {
//apply previos sort if it exists
this.currentQuery = this.currentQuery.orderBy({

that.currentQuery = that.currentQuery.orderBy({
[sortPrevField]: sortPrevAscDesc,
});
}

this.updateQuery(this.currentQuery, this.state.filters.length > 0);
switch (true) {
// called by applyFilters to sort an already filtered result
case !field:
sortCurrentQuery(this, sortField, sortAscDesc);
break;

// called directly from UI by sorting a column.
// active filters need to be applied before sorting
case isFiltered:
this.applyFilters([...filters]);
sortCurrentQuery(this, sortField, sortAscDesc);
break;

// called directly from UI by sorting a column.
// no active filters, start a new root query.
case !isFiltered:
sortRootQuery(this, sortField, sortAscDesc);
break;
}

maybeSortByPreviousField(this, sortPrevField, sortPrevAscDesc);
this.updateQuery(this.currentQuery, isFiltered);
};

onSort = (headerClicked, ascDesc) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,21 @@ const TransactionHeader = memo(
}
/>
{showBalance && <Cell value="Balance" width={88} textAlign="right" />}
{showCleared && <Field width={23} truncate={false} />}

{showCleared && (
<HeaderCell
value="✓"
width={28}
alignItems="center"
id="cleared"
icon={field === 'cleared' ? ascDesc : 'clickable'}
onClick={() => {
onSort('cleared', selectAscDesc(field, ascDesc, 'cleared', 'asc'))
}
}
/>
)}

<Cell value="" width={5 + (scrollWidth ?? 0)} />
</Row>
);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1994.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [jaarasys-henria]
---

Make transaction list sortable by cleared status

0 comments on commit 8e11484

Please sign in to comment.