Skip to content

Commit

Permalink
Merge pull request #27547 from lukemorawski/27393-displayName_fallbac…
Browse files Browse the repository at this point in the history
…k_to_hidden

Update LHN/chat header to handle displayName not being set
  • Loading branch information
puneetlath authored Oct 19, 2023
2 parents e726c62 + 20d20dc commit fd169e2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, {
}
reportName = ReportUtils.getReportName(report);
} else {
reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0]);
reportName = ReportUtils.getDisplayNameForParticipant(accountIDs[0], false);
result.keyForList = String(accountIDs[0]);
result.alternateText = LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetails, [accountIDs[0], 'login'], ''));
}
Expand Down
18 changes: 15 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ function getPersonalDetailsForAccountID(accountID) {
return (
(allPersonalDetails && allPersonalDetails[accountID]) || {
avatar: UserUtils.getDefaultAvatar(accountID),
isOptimisticPersonalDetail: true,
}
);
}
Expand All @@ -1173,27 +1174,38 @@ function getPersonalDetailsForAccountID(accountID) {
*
* @param {Number} accountID
* @param {Boolean} [shouldUseShortForm]
* @param {Boolean} shouldFallbackToHidden
* @returns {String}
*/
function getDisplayNameForParticipant(accountID, shouldUseShortForm = false) {
function getDisplayNameForParticipant(accountID, shouldUseShortForm = false, shouldFallbackToHidden = true) {
if (!accountID) {
return '';
}
const personalDetails = getPersonalDetailsForAccountID(accountID);
// this is to check if account is an invite/optimistically created one
// and prevent from falling back to 'Hidden', so a correct value is shown
// when searching for a new user
if (lodashGet(personalDetails, 'isOptimisticPersonalDetail') === true) {
return personalDetails.login || '';
}
const longName = personalDetails.displayName;
const shortName = personalDetails.firstName || longName;
if (!longName && !personalDetails.login && shouldFallbackToHidden) {
return Localize.translateLocal('common.hidden');
}
return shouldUseShortForm ? shortName : longName;
}

/**
* @param {Object} personalDetailsList
* @param {Boolean} isMultipleParticipantReport
* @param {Boolean} shouldFallbackToHidden
* @returns {Array}
*/
function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantReport) {
function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantReport, shouldFallbackToHidden) {
return _.map(personalDetailsList, (user) => {
const accountID = Number(user.accountID);
const displayName = getDisplayNameForParticipant(accountID, isMultipleParticipantReport) || user.login || '';
const displayName = getDisplayNameForParticipant(accountID, isMultipleParticipantReport, shouldFallbackToHidden) || user.login || '';
const avatar = UserUtils.getDefaultAvatar(accountID);

let pronouns = user.pronouns;
Expand Down
4 changes: 4 additions & 0 deletions src/pages/home/report/ParticipantLocalTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function ParticipantLocalTime(props) {

const reportRecipientDisplayName = lodashGet(props, 'participant.firstName') || lodashGet(props, 'participant.displayName');

if (!reportRecipientDisplayName) {
return null;
}

return (
<View style={[styles.chatItemComposeSecondaryRow]}>
<Text
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionItemSingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ function ReportActionItemSingle(props) {

// If this is a report preview, display names and avatars of both people involved
let secondaryAvatar = {};
const primaryDisplayName = displayName;
const primaryDisplayName = ReportUtils.getDisplayNameForParticipant(actorAccountID);
if (displayAllActors) {
// The ownerAccountID and actorAccountID can be the same if the a user requests money back from the IOU's original creator, in that case we need to use managerID to avoid displaying the same user twice
const secondaryAccountId = props.iouReport.ownerAccountID === actorAccountID ? props.iouReport.managerID : props.iouReport.ownerAccountID;
const secondaryUserDetails = props.personalDetailsList[secondaryAccountId] || {};
const secondaryDisplayName = lodashGet(secondaryUserDetails, 'displayName', '');
const secondaryDisplayName = ReportUtils.getDisplayNameForParticipant(secondaryAccountId);
displayName = `${primaryDisplayName} & ${secondaryDisplayName}`;
secondaryAvatar = {
source: UserUtils.getAvatar(secondaryUserDetails.avatar, secondaryAccountId),
Expand Down
11 changes: 7 additions & 4 deletions src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ function MoneyRequestConfirmPage(props) {
const [receiptFile, setReceiptFile] = useState();
const participants = useMemo(
() =>
_.map(props.iou.participants, (participant) => {
const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false);
return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, props.personalDetails);
}),
_.chain(props.iou.participants)
.map((participant) => {
const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false);
return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, props.personalDetails);
})
.filter((participant) => !!participant.login)
.value(),
[props.iou.participants, props.personalDetails],
);
const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(props.report)), [props.report]);
Expand Down

0 comments on commit fd169e2

Please sign in to comment.