From 7ca9e818fd1d8d087f769c496e9d52786e31e61c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 9 Sep 2024 10:33:55 -0600 Subject: [PATCH 1/2] sort reports by transaction date --- src/libs/SearchUtils.ts | 12 ++++++++---- .../categories/WorkspaceCategoriesSettingsPage.tsx | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 1b1fcaee8682..162fe05d68ab 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -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); }); } diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 02547090cfe6..0c481fa8ada7 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -94,7 +94,11 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet shouldPlaceSubtitleBelowSwitch /> +<<<<<<< Updated upstream {!!currentPolicy && listItems.length > 0 && canUseWorkspaceRules && ( +======= + {!!currentPolicy && listItems && false && ( +>>>>>>> Stashed changes <> {translate('workspace.categories.defaultSpendCategories')} From 1ca6b037e54d724b8b9745119f8c505c3e169f3f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 9 Sep 2024 13:28:57 -0600 Subject: [PATCH 2/2] resolve conflicts --- .../workspace/categories/WorkspaceCategoriesSettingsPage.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 0c481fa8ada7..02547090cfe6 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -94,11 +94,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet shouldPlaceSubtitleBelowSwitch /> -<<<<<<< Updated upstream {!!currentPolicy && listItems.length > 0 && canUseWorkspaceRules && ( -======= - {!!currentPolicy && listItems && false && ( ->>>>>>> Stashed changes <> {translate('workspace.categories.defaultSpendCategories')}