From d3f959d2166c74c5a70113c02a22a53a7a62bd0c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 26 Jun 2024 14:11:33 -0600 Subject: [PATCH 1/2] sort reports by created date --- src/components/Search.tsx | 2 +- src/libs/SearchUtils.ts | 15 ++++++++++++++- src/types/onyx/SearchResults.ts | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/Search.tsx b/src/components/Search.tsx index 714993204afb..d0a069f5d57b 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -150,7 +150,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { const isSortingAllowed = sortableSearchTabs.includes(query); const shouldShowYear = SearchUtils.shouldShowYear(searchResults?.data); - + console.log('over here', sortedData) return ( customListHeader={ diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 6e6a541ccdff..6c28bdecfd93 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -212,7 +212,7 @@ const searchTypeToItemMap: SearchTypeToItemMap = { listItem: ReportListItem, getSections: getReportSections, // sorting for ReportItems not yet implemented - getSortedSections: (data) => data, + getSortedSections: getSortedReportData, }, }; @@ -273,6 +273,19 @@ function getSortedTransactionData(data: TransactionListItemType[], sortBy?: Sear }); } +function getSortedReportData(data: ReportListItemType[]) { + return data.sort((a, b) => { + const aValue = a?.created; + const bValue = b?.created; + + if (aValue === undefined || bValue === undefined) { + return 0; + } + + return bValue.toLowerCase().localeCompare(aValue); + }); +} + function getSearchParams() { const topmostCentralPaneRoute = getTopmostCentralPaneRoute(navigationRef.getRootState() as State); return topmostCentralPaneRoute?.params as AuthScreensParamList['Search_Central_Pane']; diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 3932752f4325..b0c2c0339761 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -110,6 +110,15 @@ type SearchReport = { /** The report type */ type?: string; + /** The accountID of the report manager */ + managerID?: number; + + /** The accountID of the user who created the report */ + accountID?: number; + + /** The date the report was created */ + created?: string; + /** The action that can be performed for the report */ action?: string; }; From 4eb569959485e23a6f4f717c60b8285aa7785811 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 26 Jun 2024 14:21:46 -0600 Subject: [PATCH 2/2] rm log --- src/components/Search.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search.tsx b/src/components/Search.tsx index d0a069f5d57b..714993204afb 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -150,7 +150,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { const isSortingAllowed = sortableSearchTabs.includes(query); const shouldShowYear = SearchUtils.shouldShowYear(searchResults?.data); - console.log('over here', sortedData) + return ( customListHeader={