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

fix: show workspace name in search preview for policy expense chats #16554

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
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 @@ -1665,6 +1684,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