Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: refactor requiresAttentionFromCurrentUser function #32140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,14 +1531,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 @@ -1550,29 +1550,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 @@ -187,7 +187,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