Skip to content

Commit

Permalink
Merge pull request Expensify#48796 from Expensify/cmartins-updateSort…
Browse files Browse the repository at this point in the history
…Logic

Sort reports by transaction date
  • Loading branch information
jasperhuangg authored Sep 11, 2024
2 parents d30bfe1 + 1ca6b03 commit 762bffc
Showing 1 changed file with 8 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 @@ -348,16 +348,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

0 comments on commit 762bffc

Please sign in to comment.