Skip to content

Commit

Permalink
sort reports by transaction date
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Sep 9, 2024
1 parent fe44ab2 commit 7ca9e81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,20 @@ function getSortedTransactionData(data: TransactionListItemType[], sortBy?: Sear
});
}

function getReportNewestTransactionDate(report: ReportListItemType) {
return report.transactions?.reduce((max, curr) => (curr.modifiedCreated ?? curr.created > max.created ? curr : max), report.transactions[0])?.created;
}

function getSortedReportData(data: ReportListItemType[]) {
return data.sort((a, b) => {
const aValue = a?.created;
const bValue = b?.created;
const aNewestTransaction = getReportNewestTransactionDate(a);
const bNewestTransaction = getReportNewestTransactionDate(b);

if (aValue === undefined || bValue === undefined) {
if (!aNewestTransaction || !bNewestTransaction) {
return 0;
}

return bValue.toLowerCase().localeCompare(aValue);
return bNewestTransaction.toLowerCase().localeCompare(aNewestTransaction);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet
shouldPlaceSubtitleBelowSwitch
/>
<View style={[styles.containerWithSpaceBetween]}>

Check failure on line 96 in src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'</' expected.
<<<<<<< Updated upstream

Check failure on line 97 in src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Merge conflict marker encountered.
{!!currentPolicy && listItems.length > 0 && canUseWorkspaceRules && (
=======

Check failure on line 99 in src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Merge conflict marker encountered.
{!!currentPolicy && listItems && false && (
>>>>>>> Stashed changes

Check failure on line 101 in src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Merge conflict marker encountered.
<>
<View style={[styles.mh5, styles.mt2, styles.mb1]}>
<Text style={[styles.headerText]}>{translate('workspace.categories.defaultSpendCategories')}</Text>
Expand Down

0 comments on commit 7ca9e81

Please sign in to comment.