From 1238c320ba6a41de74129e745b6a1c7b57451db0 Mon Sep 17 00:00:00 2001 From: Dysto coder Date: Tue, 1 Jul 2025 14:15:40 +0300 Subject: [PATCH 1/5] create a function that sorts outstanding reports by selected id --- src/libs/ReportUtils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f98c74903a79d..ba4f65b6ef4f7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9975,6 +9975,16 @@ function getOutstandingReportsForUser( .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } +function sortOutstandingReportsBySelected(report1: OnyxEntry, report2: OnyxEntry, selectedReportID: string | undefined): number { + if (report1?.reportID === selectedReportID) { + return -1; + } + if (report2?.reportID === selectedReportID) { + return 1; + } + return report1?.reportName?.localeCompare(report2?.reportName?.toLowerCase() ?? '') ?? 0; +} + /** * @returns the object to update `report.hasOutstandingChildRequest` */ @@ -11366,6 +11376,7 @@ export { shouldReportBeInOptionList, shouldReportShowSubscript, shouldShowFlagComment, + sortOutstandingReportsBySelected, getReportActionWithMissingSmartscanFields, shouldShowRBRForMissingSmartscanFields, shouldUseFullTitleToDisplay, From 465c0fd0288e6cab734755cd48fadfe2737c6ce7 Mon Sep 17 00:00:00 2001 From: Dysto coder Date: Tue, 1 Jul 2025 14:20:36 +0300 Subject: [PATCH 2/5] add comment for the sort function --- src/libs/ReportUtils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ba4f65b6ef4f7..e23c8dcd91b0f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9975,6 +9975,12 @@ function getOutstandingReportsForUser( .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } +/** + * Sort outstanding reports by their name, while keeping the selected one at the beginning. + * @param report1 Details of the first report to be compared. + * @param report2 Details of the second report to be compared. + * @param selectedReportID ID of the selected report which needs to be at the beginning. + */ function sortOutstandingReportsBySelected(report1: OnyxEntry, report2: OnyxEntry, selectedReportID: string | undefined): number { if (report1?.reportID === selectedReportID) { return -1; From 9cf25a83a2e40f93ffbb826c0a0259cad05f3eb2 Mon Sep 17 00:00:00 2001 From: Dysto coder Date: Tue, 1 Jul 2025 14:21:40 +0300 Subject: [PATCH 3/5] sort the report on EditReportCommon page --- src/pages/iou/request/step/IOURequestEditReportCommon.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx index 3701dafef8ebf..e17cf245177fc 100644 --- a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx +++ b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx @@ -9,7 +9,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; -import {getOutstandingReportsForUser, getPolicyName} from '@libs/ReportUtils'; +import {getOutstandingReportsForUser, getPolicyName, sortOutstandingReportsBySelected} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; @@ -78,7 +78,7 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport}: const onlyReport = transactionsReports.length === 1 ? transactionsReports.at(0) : undefined; return expenseReports - .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0) + .sort((report1, report2) => sortOutstandingReportsBySelected(report1, report2, onlyReport?.reportID)) .filter((report) => !debouncedSearchValue || report?.reportName?.toLowerCase().includes(debouncedSearchValue.toLowerCase())) .filter((report): report is NonNullable => report !== undefined) .map((report) => { From e777f7108db512b3b60e052fae7b4baf0132b3d8 Mon Sep 17 00:00:00 2001 From: Dysto coder Date: Thu, 3 Jul 2025 23:15:13 +0300 Subject: [PATCH 4/5] add a unit test for sortOutstandingReportsBySelected --- tests/unit/ReportUtilsTest.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 78e81ac2976c4..9258bb132e00c 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -59,6 +59,7 @@ import { shouldDisableThread, shouldReportBeInOptionList, shouldReportShowSubscript, + sortOutstandingReportsBySelected, temporary_getMoneyRequestOptions, } from '@libs/ReportUtils'; import type {OptionData} from '@libs/ReportUtils'; @@ -438,6 +439,21 @@ describe('ReportUtils', () => { }); }); + describe('sortOutstandingReportsBySelected', () => { + it.only('should return -1 when report1 is selected and report2 is not', () => { + const report1 = LHNTestUtils.getFakeReport(); + const report2 = LHNTestUtils.getFakeReport(); + const selectedReportID = report1.reportID; + expect(sortOutstandingReportsBySelected(report1, report2, selectedReportID)).toBe(-1); + }); + it.only('should return 1 when report2 is selected and report1 is not', () => { + const report1 = LHNTestUtils.getFakeReport(); + const report2 = LHNTestUtils.getFakeReport(); + const selectedReportID = report2.reportID; + expect(sortOutstandingReportsBySelected(report1, report2, selectedReportID)).toBe(1); + }); + }); + describe('getDisplayNamesWithTooltips', () => { test('withSingleParticipantReport', () => { const participants = getDisplayNamesWithTooltips(participantsPersonalDetails, false); From 4a3e5419ac6a5f08bcdb3c1f8df0b7ab6d87a53c Mon Sep 17 00:00:00 2001 From: Dysto coder Date: Fri, 4 Jul 2025 14:00:15 +0300 Subject: [PATCH 5/5] remove only call used to isolate new test --- tests/unit/ReportUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 9258bb132e00c..fb771418a0f79 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -440,13 +440,13 @@ describe('ReportUtils', () => { }); describe('sortOutstandingReportsBySelected', () => { - it.only('should return -1 when report1 is selected and report2 is not', () => { + it('should return -1 when report1 is selected and report2 is not', () => { const report1 = LHNTestUtils.getFakeReport(); const report2 = LHNTestUtils.getFakeReport(); const selectedReportID = report1.reportID; expect(sortOutstandingReportsBySelected(report1, report2, selectedReportID)).toBe(-1); }); - it.only('should return 1 when report2 is selected and report1 is not', () => { + it('should return 1 when report2 is selected and report1 is not', () => { const report1 = LHNTestUtils.getFakeReport(); const report2 = LHNTestUtils.getFakeReport(); const selectedReportID = report2.reportID;