Skip to content

Commit

Permalink
Merge pull request #16554 from BeeMargarida/fix/16463-policy_expense_…
Browse files Browse the repository at this point in the history
…chat_admin_search

fix: show workspace name in search preview for policy expense chats
  • Loading branch information
mountiny authored Mar 30, 2023
2 parents f327eb0 + fe8671a commit fd13bf2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,16 @@ function getOptions(reports, personalDetails, {
reportMapForLogins[logins[0]] = report;
}
const isSearchingSomeonesPolicyExpenseChat = !report.isOwnPolicyExpenseChat && searchValue !== '';

// Checks to see if the current user is the admin of the policy, if so the policy
// name preview will be shown.
const isPolicyChatAdmin = ReportUtils.isPolicyExpenseChatAdmin(report, policies);

allReportOptions.push(createOption(logins, personalDetails, report, reportActions, {
showChatPreviewLine,
forcePolicyNamePreview: isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat : forcePolicyNamePreview,
forcePolicyNamePreview: isPolicyExpenseChat
? (isSearchingSomeonesPolicyExpenseChat || isPolicyChatAdmin)
: forcePolicyNamePreview,
}));
});

Expand Down
20 changes: 20 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,25 @@ function getPolicyName(report, policies) {
|| Localize.translateLocal('workspace.common.unavailable');
}

/**
* Checks if the current user is the admin of the policy given the policy expense chat.
* @param {Object} report
* @param {String} report.policyID
* @param {Object} policies must have OnyxKey prefix (i.e 'policy_') for keys
* @returns {Boolean}
*/
function isPolicyExpenseChatAdmin(report, policies) {
if (!isPolicyExpenseChat(report)) {
return false;
}

const policyRole = lodashGet(policies, [
`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role',
]);

return policyRole === CONST.POLICY.ROLE.ADMIN;
}

/**
* Get either the policyName or domainName the chat is tied to
* @param {Object} report
Expand Down Expand Up @@ -1676,6 +1695,7 @@ export {
getPolicyName,
getPolicyType,
isArchivedRoom,
isPolicyExpenseChatAdmin,
isPublicRoom,
isConciergeChatReport,
hasAutomatedExpensifyEmails,
Expand Down
5 changes: 4 additions & 1 deletion src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ function getOptionData(reportID) {
}

if (result.isChatRoom || result.isPolicyExpenseChat) {
result.alternateText = lastMessageText || Localize.translate(preferredLocale, 'report.noActivityYet');
// Checks to see if the current user is the admin of the policy tied to the policy expense chat,
// if so the policy name preview will be shown.
const isPolicyChatAdmin = result.isPolicyExpenseChat && ReportUtils.isPolicyExpenseChatAdmin(report, policies);
result.alternateText = isPolicyChatAdmin ? subtitle : (lastMessageText || Localize.translate(preferredLocale, 'report.noActivityYet'));
} else {
if (!lastMessageText) {
// Here we get the beginning of chat history message and append the display name for each user, adding pronouns if there are any.
Expand Down

0 comments on commit fd13bf2

Please sign in to comment.