From 071db619ab8063b42490765c1425e46832c190d8 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Tue, 28 Nov 2023 17:54:56 +0100 Subject: [PATCH 1/5] refactor requiresAttentionFromCurrentUserfunction --- src/libs/ReportUtils.ts | 25 ++++++++++++++----------- tests/unit/ReportUtilsTest.js | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d93661778b83..60177682b873 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1519,7 +1519,12 @@ function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { // lastMentionedTime and lastReadTime are both datetime strings and can be compared directly const lastMentionedTime = report.lastMentionedTime ?? ''; const lastReadTime = report.lastReadTime ?? ''; - return lastReadTime < lastMentionedTime; + return Boolean('isUnreadWithMention' in report && report.isUnreadWithMention) || lastReadTime < lastMentionedTime; +} + +// Type guard to check the type of an object and it's an option +function isOption(option: OnyxEntry | OptionData): option is OptionData { + return (option as OptionData).isUnreadWithMention !== undefined; } /** @@ -1536,20 +1541,18 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData return false; } - if (isArchivedRoom(option)) { - return false; - } - - if (isArchivedRoom(getReport(option.parentReportID))) { + if (isArchivedRoom(option) || isArchivedRoom(getReport(option.parentReportID))) { return false; } - if (Boolean('isUnreadWithMention' in option && option.isUnreadWithMention) || isUnreadWithMention(option)) { - return true; - } + if (isOption(option)) { + if (isUnreadWithMention(option)) { + return true; + } - if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { - return true; + if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { + return true; + } } // Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index e0c98b1793f1..0e3e144b5571 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -305,11 +305,12 @@ describe('ReportUtils', () => { }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true); }); - it('returns true when the report is an outstanding task', () => { + it.only('returns true when the report is an outstanding task', () => { const report = { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, managerID: currentUserAccountID, + isUnreadWithMention: false, stateNum: CONST.REPORT.STATE_NUM.OPEN, statusNum: CONST.REPORT.STATUS.OPEN, }; From 14c7e9b3d37e88cce11fc7a9ae7e28c5492134b0 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Wed, 29 Nov 2023 14:28:58 +0100 Subject: [PATCH 2/5] fix --- tests/unit/ReportUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index 0e3e144b5571..e6b06e2aff5b 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -305,7 +305,7 @@ describe('ReportUtils', () => { }; expect(ReportUtils.requiresAttentionFromCurrentUser(report)).toBe(true); }); - it.only('returns true when the report is an outstanding task', () => { + it('returns true when the report is an outstanding task', () => { const report = { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.TASK, From ffe819adff52d61e5aa069cdc19df5bd0914bdf5 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Mon, 4 Dec 2023 15:04:02 +0100 Subject: [PATCH 3/5] change --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 60177682b873..0608e1072f7f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1545,11 +1545,11 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData return false; } - if (isOption(option)) { - if (isUnreadWithMention(option)) { - return true; - } + if (isUnreadWithMention(option)) { + return true; + } + if (isOption(option)) { if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { return true; } From 88bee57213f3f88e45ad12b3b2919762e258bbc0 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Wed, 6 Dec 2023 22:02:21 +0100 Subject: [PATCH 4/5] updates --- src/libs/ReportUtils.ts | 11 ++--------- src/libs/SidebarUtils.ts | 3 ++- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1fdaa69b9a05..a2549e76d505 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1541,11 +1541,6 @@ function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { return Boolean('isUnreadWithMention' in report && report.isUnreadWithMention) || lastReadTime < lastMentionedTime; } -// Type guard to check the type of an object and it's an option -function isOption(option: OnyxEntry | OptionData): option is OptionData { - return (option as OptionData).isUnreadWithMention !== undefined; -} - /** * Determines if the option requires action from the current user. This can happen when it: - is unread and the user was mentioned in one of the unread comments @@ -1568,10 +1563,8 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData return true; } - if (isOption(option)) { - if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { - return true; - } + if (isWaitingForAssigneeToCompleteTask(option, parentReportAction)) { + return true; } // Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index bace29e06d28..3e4d27fa9704 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -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); From a4dcc97d577b80ac9e2d6b36ea140e433eea1941 Mon Sep 17 00:00:00 2001 From: Artem Makushov Date: Mon, 11 Dec 2023 19:24:12 +0100 Subject: [PATCH 5/5] updated --- src/libs/ReportUtils.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a2549e76d505..f6fe4ce8c661 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1531,14 +1531,14 @@ function isWaitingForAssigneeToCompleteTask(report: OnyxEntry, parentRep return isTaskReport(report) && isReportManager(report) && isOpenTaskReport(report, parentReportAction); } -function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { - if (!report) { +function isUnreadWithMention(reportOrOption: OnyxEntry | 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 Boolean('isUnreadWithMention' in report && report.isUnreadWithMention) || lastReadTime < lastMentionedTime; + const lastMentionedTime = reportOrOption.lastMentionedTime ?? ''; + const lastReadTime = reportOrOption.lastReadTime ?? ''; + return Boolean('isUnreadWithMention' in reportOrOption && reportOrOption.isUnreadWithMention) || lastReadTime < lastMentionedTime; } /** @@ -1550,25 +1550,25 @@ function isUnreadWithMention(report: OnyxEntry | OptionData): boolean { * @param option (report or optionItem) * @param parentReportAction (the report action the current report is a thread of) */ -function requiresAttentionFromCurrentUser(option: OnyxEntry | OptionData, parentReportAction: EmptyObject | OnyxEntry = {}) { - if (!option) { +function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry | OptionData, parentReportAction: EmptyObject | OnyxEntry = {}) { + if (!optionOrReport) { return false; } - if (isArchivedRoom(option) || isArchivedRoom(getReport(option.parentReportID))) { + if (isArchivedRoom(optionOrReport) || isArchivedRoom(getReport(optionOrReport.parentReportID))) { return false; } - if (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; }