From 2f074b5ef41b9bb724a9235edd4488129bfa44e0 Mon Sep 17 00:00:00 2001 From: Meet Mangukiya Date: Fri, 27 Aug 2021 14:16:18 +0530 Subject: [PATCH] Prioritize reports with draft comments in the Most Recent priority mode --- src/libs/OptionsListUtils.js | 15 ++++++++++++++- tests/unit/OptionsListUtilsTest.js | 13 +++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index afeced90ac9..f832b957227 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -340,11 +340,13 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { sortByAlphaAsc = false, forcePolicyNamePreview = false, prioritizeIOUDebts = false, + prioritizeReportsWithDraftComments = false, }) { let recentReportOptions = []; const pinnedReportOptions = []; const personalDetailsOptions = []; const iouDebtReportOptions = []; + const draftReportOptions = []; const reportMapForLogins = {}; let sortProperty = sortByLastMessageTimestamp @@ -456,6 +458,8 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { pinnedReportOptions.push(reportOption); } else if (prioritizeIOUDebts && reportOption.hasOutstandingIOU && !reportOption.isIOUReportOwner) { iouDebtReportOptions.push(reportOption); + } else if (prioritizeReportsWithDraftComments && reportOption.hasDraftComment) { + draftReportOptions.push(reportOption); } else { recentReportOptions.push(reportOption); } @@ -467,7 +471,15 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { } } - // If we are prioritizing IOUs the user owes, add them before the normal recent report options + // If we are prioritizing reports with draft comments, add them before the normal recent report options + // and sort them by report name. + if (prioritizeReportsWithDraftComments) { + const sortedDraftReports = lodashOrderBy(draftReportOptions, ['text'], ['asc']); + recentReportOptions = sortedDraftReports.concat(recentReportOptions); + } + + // If we are prioritizing IOUs the user owes, add them before the normal recent report options and reports + // with draft comments. if (prioritizeIOUDebts) { const sortedIOUReports = lodashOrderBy(iouDebtReportOptions, ['iouReportAmount'], ['desc']); recentReportOptions = sortedIOUReports.concat(recentReportOptions); @@ -695,6 +707,7 @@ function getSidebarOptions( let sideBarOptions = { prioritizePinnedReports: true, prioritizeIOUDebts: true, + prioritizeReportsWithDraftComments: true, }; if (priorityMode === CONST.PRIORITY_MODE.GSD) { sideBarOptions = { diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 3a9b992050a..0a16c61e642 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -215,6 +215,8 @@ describe('OptionsListUtils', () => { }, }; + const REPORT_DRAFT_COMMENTS = {[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}1`]: 'Draft comment'}; + // Set the currently logged in user, report data, and personal details beforeAll(() => { Onyx.init({ @@ -564,7 +566,7 @@ describe('OptionsListUtils', () => { const results = OptionsListUtils.getSidebarOptions( reportsWithAddedPinnedMessagelessReport, PERSONAL_DETAILS, - {}, + REPORT_DRAFT_COMMENTS, 0, CONST.PRIORITY_MODE.DEFAULT, ); @@ -585,13 +587,16 @@ describe('OptionsListUtils', () => { // And the third report is the report with an IOU debt expect(results.recentReports[2].login).toBe('mistersinister@marauders.com'); - // And the fourth report is the report with the lastMessage timestamp - expect(results.recentReports[3].login).toBe('steverogers@expensify.com'); + // And the fourth report is the report with a draft comment + expect(results.recentReports[3].text).toBe('tonystark@expensify.com, reedrichards@expensify.com'); + + // And the fifth report is the report with the lastMessage timestamp + expect(results.recentReports[4].login).toBe('steverogers@expensify.com'); }); it('getSidebarOptions() with GSD priority mode', () => { // When we call getSidebarOptions() with no search value - const results = OptionsListUtils.getSidebarOptions(REPORTS, PERSONAL_DETAILS, {}, 0, CONST.PRIORITY_MODE.GSD); + const results = OptionsListUtils.getSidebarOptions(REPORTS, PERSONAL_DETAILS, REPORT_DRAFT_COMMENTS, 0, CONST.PRIORITY_MODE.GSD); // Then expect all of the reports to be shown both multiple and single participant except the // report that has no lastMessageTimestamp and the chat with Thor who's message is read