Skip to content

Commit

Permalink
Merge pull request #11725 from Expensify/tgolen-archive-filtering
Browse files Browse the repository at this point in the history
Make sure that archived reports are shown properly in the LHN and the search options
  • Loading branch information
ctkochan22 authored Oct 11, 2022
2 parents 62394cc + 31b9684 commit 9090055
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 108 deletions.
9 changes: 5 additions & 4 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
let hasMultipleParticipants = personalDetailList.length > 1;
let subtitle;

result.participantsList = personalDetailList;

if (report) {
result.isChatRoom = ReportUtils.isChatRoom(report);
result.isDefaultRoom = ReportUtils.isDefaultRoom(report);
Expand Down Expand Up @@ -354,10 +356,9 @@ function createOption(logins, personalDetails, report, reportActions = {}, {

const reportName = ReportUtils.getReportName(report, personalDetailMap, policies);
result.text = reportName;
result.subtitle = subtitle;
result.participantsList = personalDetailList;
result.icons = ReportUtils.getIcons(report, personalDetails, policies, personalDetail.avatar);
result.searchText = getSearchText(report, reportName, personalDetailList, result.isChatRoom || result.isPolicyExpenseChat);
result.icons = ReportUtils.getIcons(report, personalDetails, policies, personalDetail.avatar);
result.subtitle = subtitle;

return result;
}
Expand Down Expand Up @@ -505,7 +506,7 @@ function getOptions(reports, personalDetails, {

if (sortPersonalDetailsByAlphaAsc) {
// PersonalDetails should be ordered Alphabetically by default - https://github.com/Expensify/App/issues/8220#issuecomment-1104009435
allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text.toLowerCase()], 'asc');
allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text && personalDetail.text.toLowerCase()], 'asc');
}

// Always exclude already selected options and the currently logged in user
Expand Down
24 changes: 9 additions & 15 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,12 @@ function findLastAccessedReport(reports, ignoreDefaultRooms, policies) {
/**
* Whether the provided report is an archived room
* @param {Object} report
* @param {String} report.chatType
* @param {Number} report.stateNum
* @param {Number} report.statusNum
* @returns {Boolean}
*/
function isArchivedRoom(report) {
if (!isChatRoom(report) && !isPolicyExpenseChat(report)) {
return false;
}

return report.statusNum === CONST.REPORT.STATUS.CLOSED && report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED;
return lodashGet(report, ['statusNum']) === CONST.REPORT.STATUS.CLOSED && lodashGet(report, ['stateNum']) === CONST.REPORT.STATE_NUM.SUBMITTED;
}

/**
Expand Down Expand Up @@ -903,6 +898,8 @@ function hasOutstandingIOU(report, currentUserLogin, iouReports) {
* @returns {boolean}
*/
function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, iouReports, betas, policies) {
const isInDefaultMode = !isInGSDMode;

// Exclude reports that have no data because there wouldn't be anything to show in the option item.
// This can happen if data is currently loading from the server or a report is in various stages of being created.
if (!report || !report.reportID || !report.participants || _.isEmpty(report.participants)) {
Expand All @@ -928,19 +925,16 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr
return true;
}

// Exclude reports that don't have any comments
// User created policy rooms are OK to show when the don't have any comments, only if they aren't archived.
const hasNoComments = report.lastMessageTimestamp === 0;
if (hasNoComments && (isArchivedRoom(report) || !isUserCreatedPolicyRoom(report))) {
return false;
}

// Include unread reports when in GSD mode
// GSD mode is specifically for focusing the user on the most relevant chats, primarily, the unread ones
// All unread chats (even archived ones) in GSD mode will be shown. This is because GSD mode is specifically for focusing the user on the most relevant chats, primarily, the unread ones
if (isInGSDMode) {
return isUnread(report);
}

// Archived reports should always be shown when in default (most recent) mode. This is because you should still be able to access and search for the chats to find them.
if (isInDefaultMode && isArchivedRoom(report)) {
return true;
}

// Include default rooms for free plan policies
if (isDefaultRoom(report) && getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE) {
return true;
Expand Down
10 changes: 9 additions & 1 deletion src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ function getOrderedReportIDs(reportIDFromRoute) {
// - Regardless of mode, all archived reports should remain at the bottom
const orderedReports = _.sortBy(filteredReportsWithReportName, (report) => {
if (ReportUtils.isArchivedRoom(report)) {
return isInDefaultMode ? -Infinity : 'ZZZZZZZZZZZZZ';
return isInDefaultMode

// -Infinity is used here because there is no chance that a report will ever have an older timestamp than -Infinity and it ensures that archived reports
// will always be listed last
? -Infinity

// Similar logic is used for 'ZZZZZZZZZZZZZ' to reasonably assume that no report will ever have a report name that will be listed alphabetically after this, ensuring that
// archived reports will be listed last
: 'ZZZZZZZZZZZZZ';
}

return isInDefaultMode ? report.lastMessageTimestamp : report.reportDisplayName;
Expand Down
Loading

0 comments on commit 9090055

Please sign in to comment.