From e288859a2c79ecfdc56faaea21012325f11c4f7c Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Thu, 12 Oct 2023 19:01:46 +0800 Subject: [PATCH 1/6] add checkPolicyOwner parameter --- src/libs/OptionsListUtils.js | 12 +++++++++--- src/libs/ReportUtils.js | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 4467746475aa..89231ad84903 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -414,7 +414,7 @@ function getLastMessageTextForReport(report) { * @param {Boolean} [options.forcePolicyNamePreview] * @returns {Object} */ -function createOption(accountIDs, personalDetails, report, reportActions = {}, {showChatPreviewLine = false, forcePolicyNamePreview = false}) { +function createOption(accountIDs, personalDetails, report, reportActions = {}, {showChatPreviewLine = false, forcePolicyNamePreview = false, checkPolicyOwner = true}) { const result = { text: null, alternateText: null, @@ -485,7 +485,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { result.policyID = report.policyID; hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; - subtitle = ReportUtils.getChatRoomSubtitle(report); + subtitle = ReportUtils.getChatRoomSubtitle(report, checkPolicyOwner); const lastMessageTextFromReport = getLastMessageTextForReport(report); const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; @@ -511,7 +511,12 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } else { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageText : LocalePhoneNumber.formatPhoneNumber(personalDetail.login); } - reportName = ReportUtils.getReportName(report); + + if (result.isPolicyExpenseChat && !checkPolicyOwner) { + reportName = ReportUtils.getPolicyName(report); + } else { + reportName = ReportUtils.getReportName(report); + } } else { reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]); result.keyForList = String(accountIDs[0]); @@ -551,6 +556,7 @@ function getPolicyExpenseReportOption(report) { { showChatPreviewLine: false, forcePolicyNamePreview: false, + checkPolicyOwner: false, }, ); option.selected = report.selected; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8bb67d639486..38f2b798c89d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1861,7 +1861,7 @@ function getRootReportAndWorkspaceName(report) { * @param {Object} report * @returns {String} */ -function getChatRoomSubtitle(report) { +function getChatRoomSubtitle(report, checkPolicyOwner = true) { if (isChatThread(report)) { return ''; } @@ -1872,7 +1872,7 @@ function getChatRoomSubtitle(report) { // The domainAll rooms are just #domainName, so we ignore the prefix '#' to get the domainName return report.reportName.substring(1); } - if ((isPolicyExpenseChat(report) && report.isOwnPolicyExpenseChat) || isExpenseReport(report)) { + if ((isPolicyExpenseChat(report) && (!checkPolicyOwner || report.isOwnPolicyExpenseChat)) || isExpenseReport(report)) { return Localize.translateLocal('workspace.common.workspace'); } if (isArchivedRoom(report)) { From 83be645e84ed14582f19a61ea48ec71f23754712 Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Thu, 12 Oct 2023 21:04:30 +0800 Subject: [PATCH 2/6] add jsdoc --- src/libs/OptionsListUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 89231ad84903..5bf53a507b4a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -412,6 +412,7 @@ function getLastMessageTextForReport(report) { * @param {Object} options * @param {Boolean} [options.showChatPreviewLine] * @param {Boolean} [options.forcePolicyNamePreview] + * @param {Boolean} [options.checkPolicyOwner] * @returns {Object} */ function createOption(accountIDs, personalDetails, report, reportActions = {}, {showChatPreviewLine = false, forcePolicyNamePreview = false, checkPolicyOwner = true}) { From 1b84d3c9cbdf06581d5f6adc1f5532a187e41a25 Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Thu, 12 Oct 2023 21:21:17 +0800 Subject: [PATCH 3/6] fix lint error --- src/libs/ReportUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 38f2b798c89d..0e53200db486 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1859,6 +1859,7 @@ function getRootReportAndWorkspaceName(report) { /** * Get either the policyName or domainName the chat is tied to * @param {Object} report + * @param {Boolean} checkPolicyOwner * @returns {String} */ function getChatRoomSubtitle(report, checkPolicyOwner = true) { From fdca0ecd2485a586fb575ccbc3fc6d2c3f8906b5 Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Fri, 13 Oct 2023 02:48:12 +0800 Subject: [PATCH 4/6] set text and alternate text --- src/libs/OptionsListUtils.js | 15 +++++---------- src/libs/ReportUtils.js | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 5bf53a507b4a..0677da5b5fc5 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -412,10 +412,9 @@ function getLastMessageTextForReport(report) { * @param {Object} options * @param {Boolean} [options.showChatPreviewLine] * @param {Boolean} [options.forcePolicyNamePreview] - * @param {Boolean} [options.checkPolicyOwner] * @returns {Object} */ -function createOption(accountIDs, personalDetails, report, reportActions = {}, {showChatPreviewLine = false, forcePolicyNamePreview = false, checkPolicyOwner = true}) { +function createOption(accountIDs, personalDetails, report, reportActions = {}, {showChatPreviewLine = false, forcePolicyNamePreview = false}) { const result = { text: null, alternateText: null, @@ -486,7 +485,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { result.policyID = report.policyID; hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; - subtitle = ReportUtils.getChatRoomSubtitle(report, checkPolicyOwner); + subtitle = ReportUtils.getChatRoomSubtitle(report); const lastMessageTextFromReport = getLastMessageTextForReport(report); const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; @@ -512,12 +511,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } else { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageText : LocalePhoneNumber.formatPhoneNumber(personalDetail.login); } - - if (result.isPolicyExpenseChat && !checkPolicyOwner) { - reportName = ReportUtils.getPolicyName(report); - } else { - reportName = ReportUtils.getReportName(report); - } + reportName = ReportUtils.getReportName(report); } else { reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]); result.keyForList = String(accountIDs[0]); @@ -557,9 +551,10 @@ function getPolicyExpenseReportOption(report) { { showChatPreviewLine: false, forcePolicyNamePreview: false, - checkPolicyOwner: false, }, ); + option.text = ReportUtils.getPolicyName(report); + option.alternateText = Localize.translateLocal('workspace.common.workspace'); option.selected = report.selected; return option; } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0e53200db486..8bb67d639486 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1859,10 +1859,9 @@ function getRootReportAndWorkspaceName(report) { /** * Get either the policyName or domainName the chat is tied to * @param {Object} report - * @param {Boolean} checkPolicyOwner * @returns {String} */ -function getChatRoomSubtitle(report, checkPolicyOwner = true) { +function getChatRoomSubtitle(report) { if (isChatThread(report)) { return ''; } @@ -1873,7 +1872,7 @@ function getChatRoomSubtitle(report, checkPolicyOwner = true) { // The domainAll rooms are just #domainName, so we ignore the prefix '#' to get the domainName return report.reportName.substring(1); } - if ((isPolicyExpenseChat(report) && (!checkPolicyOwner || report.isOwnPolicyExpenseChat)) || isExpenseReport(report)) { + if ((isPolicyExpenseChat(report) && report.isOwnPolicyExpenseChat) || isExpenseReport(report)) { return Localize.translateLocal('workspace.common.workspace'); } if (isArchivedRoom(report)) { From 7bc1fcb92aa2c5b473517180d2045b8150710eed Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Fri, 13 Oct 2023 02:54:21 +0800 Subject: [PATCH 5/6] add comment --- src/libs/OptionsListUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0677da5b5fc5..dc64619b4b9e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -553,6 +553,8 @@ function getPolicyExpenseReportOption(report) { forcePolicyNamePreview: false, }, ); + + // Update text & alternateText because createOption returns workspace name only if report is owned by the user option.text = ReportUtils.getPolicyName(report); option.alternateText = Localize.translateLocal('workspace.common.workspace'); option.selected = report.selected; From 1ef281157c20c96e935f8013fdadc2f3f28b64b5 Mon Sep 17 00:00:00 2001 From: akamefi202 Date: Fri, 13 Oct 2023 03:10:55 +0800 Subject: [PATCH 6/6] resolve suggestion --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index dc64619b4b9e..8f8668cf9fd7 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -555,7 +555,7 @@ function getPolicyExpenseReportOption(report) { ); // Update text & alternateText because createOption returns workspace name only if report is owned by the user - option.text = ReportUtils.getPolicyName(report); + option.text = ReportUtils.getPolicyName(expenseReport); option.alternateText = Localize.translateLocal('workspace.common.workspace'); option.selected = report.selected; return option;