Skip to content

Commit

Permalink
Merge pull request #4873 from meetmangukiya/draft-reports-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
iwiznia authored Aug 27, 2021
2 parents 230c68a + 2f074b5 commit 7e926e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -695,6 +707,7 @@ function getSidebarOptions(
let sideBarOptions = {
prioritizePinnedReports: true,
prioritizeIOUDebts: true,
prioritizeReportsWithDraftComments: true,
};
if (priorityMode === CONST.PRIORITY_MODE.GSD) {
sideBarOptions = {
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -564,7 +566,7 @@ describe('OptionsListUtils', () => {
const results = OptionsListUtils.getSidebarOptions(
reportsWithAddedPinnedMessagelessReport,
PERSONAL_DETAILS,
{},
REPORT_DRAFT_COMMENTS,
0,
CONST.PRIORITY_MODE.DEFAULT,
);
Expand All @@ -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
Expand Down

0 comments on commit 7e926e1

Please sign in to comment.