Skip to content

Commit

Permalink
Merge pull request #32140 from waterim/feat-30668-refactor-requiresAt…
Browse files Browse the repository at this point in the history
…tentionFromCurrentUser

Feature: refactor requiresAttentionFromCurrentUser function
  • Loading branch information
puneetlath authored Dec 11, 2023
2 parents c518c5e + a4dcc97 commit 6e533fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
26 changes: 11 additions & 15 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,14 +1549,14 @@ function isWaitingForAssigneeToCompleteTask(report: OnyxEntry<Report>, parentRep
return isTaskReport(report) && isReportManager(report) && isOpenTaskReport(report, parentReportAction);
}

function isUnreadWithMention(report: OnyxEntry<Report> | OptionData): boolean {
if (!report) {
function isUnreadWithMention(reportOrOption: OnyxEntry<Report> | OptionData): boolean {
if (!reportOrOption) {
return false;
}
// lastMentionedTime and lastReadTime are both datetime strings and can be compared directly
const lastMentionedTime = report.lastMentionedTime ?? '';
const lastReadTime = report.lastReadTime ?? '';
return lastReadTime < lastMentionedTime;
const lastMentionedTime = reportOrOption.lastMentionedTime ?? '';
const lastReadTime = reportOrOption.lastReadTime ?? '';
return Boolean('isUnreadWithMention' in reportOrOption && reportOrOption.isUnreadWithMention) || lastReadTime < lastMentionedTime;
}

/**
Expand All @@ -1568,29 +1568,25 @@ function isUnreadWithMention(report: OnyxEntry<Report> | OptionData): boolean {
* @param option (report or optionItem)
* @param parentReportAction (the report action the current report is a thread of)
*/
function requiresAttentionFromCurrentUser(option: OnyxEntry<Report> | OptionData, parentReportAction: EmptyObject | OnyxEntry<ReportAction> = {}) {
if (!option) {
return false;
}

if (isArchivedRoom(option)) {
function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry<Report> | OptionData, parentReportAction: EmptyObject | OnyxEntry<ReportAction> = {}) {
if (!optionOrReport) {
return false;
}

if (isArchivedRoom(getReport(option.parentReportID))) {
if (isArchivedRoom(optionOrReport) || isArchivedRoom(getReport(optionOrReport.parentReportID))) {
return false;
}

if (Boolean('isUnreadWithMention' in option && option.isUnreadWithMention) || isUnreadWithMention(option)) {
if (isUnreadWithMention(optionOrReport)) {
return true;
}

if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) {
if (isWaitingForAssigneeToCompleteTask(optionOrReport, parentReportAction)) {
return true;
}

// Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user
if (option.hasOutstandingChildRequest) {
if (optionOrReport.hasOutstandingChildRequest) {
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ function getOrderedReportIDs(
report.iouReportAmount = ReportUtils.getMoneyRequestReimbursableTotal(report, allReports);

const isPinned = report.isPinned ?? false;
if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report)) {
const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? '');
if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) {
pinnedAndGBRReports.push(report);
} else if (report.hasDraft) {
draftReports.push(report);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ describe('ReportUtils', () => {
...LHNTestUtils.getFakeReport(),
type: CONST.REPORT.TYPE.TASK,
managerID: currentUserAccountID,
isUnreadWithMention: false,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
};
Expand Down

0 comments on commit 6e533fa

Please sign in to comment.