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

[No QA] Implement the SubScript avatar for workspace money requests #18085

Merged
merged 15 commits into from
May 2, 2023
Merged
12 changes: 1 addition & 11 deletions src/components/ArchivedReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ const propTypes = {
/** Personal details of all users */
personalDetails: PropTypes.objectOf(personalDetailsPropType),

/** The list of policies the user has access to. */
policies: PropTypes.objectOf(PropTypes.shape({
/** The name of the policy */
name: PropTypes.string,
})),

...withLocalizePropTypes,
};

Expand All @@ -51,7 +45,6 @@ const defaultProps = {
},
},
personalDetails: {},
policies: {},
};

const ArchivedReportFooter = (props) => {
Expand All @@ -72,7 +65,7 @@ const ArchivedReportFooter = (props) => {
text={props.translate(`reportArchiveReasons.${archiveReason}`, {
displayName: `<strong>${displayName}</strong>`,
oldDisplayName: `<strong>${oldDisplayName}</strong>`,
policyName: `<strong>${ReportUtils.getPolicyName(props.report, props.policies)}</strong>`,
policyName: `<strong>${ReportUtils.getPolicyName(props.report)}</strong>`,
})}
shouldRenderHTML={archiveReason !== CONST.REPORT.ARCHIVE_REASON.DEFAULT}
shouldShowIcon
Expand All @@ -90,9 +83,6 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
reportClosedAction: {
key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
canEvict: false,
Expand Down
16 changes: 3 additions & 13 deletions src/components/ReportWelcomeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const propTypes = {
/** All of the personal details for everyone */
personalDetails: PropTypes.objectOf(personalDetailsPropTypes),

/** The policies which the user has access to and which the report could be tied to */
policies: PropTypes.shape({
/** The policy name */
name: PropTypes.string,
}),

/** List of betas available to current user */
betas: PropTypes.arrayOf(PropTypes.string),

Expand All @@ -52,7 +46,6 @@ const propTypes = {

const defaultProps = {
report: {},
policies: {},
personalDetails: {},
betas: [],
};
Expand All @@ -67,7 +60,7 @@ const ReportWelcomeText = (props) => {
OptionsListUtils.getPersonalDetailsForLogins(participants, props.personalDetails),
isMultipleParticipant,
);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(props.report, props.policies);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(props.report);
const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(props.report, participants, props.betas);
return (
<>
Expand All @@ -90,7 +83,7 @@ const ReportWelcomeText = (props) => {
{props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')}
</Text>
<Text style={[styles.textStrong]}>
{ReportUtils.getPolicyName(props.report, props.policies)}
{ReportUtils.getPolicyName(props.report)}
</Text>
<Text>
{props.translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree')}
Expand All @@ -103,7 +96,7 @@ const ReportWelcomeText = (props) => {
{roomWelcomeMessage.phrase1}
</Text>
<Text style={[styles.textStrong]} onPress={() => Navigation.navigate(ROUTES.getReportDetailsRoute(props.report.reportID))}>
{ReportUtils.getReportName(props.report, props.policies)}
{ReportUtils.getReportName(props.report)}
</Text>
<Text>
{roomWelcomeMessage.phrase2}
Expand Down Expand Up @@ -156,8 +149,5 @@ export default compose(
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
}),
)(ReportWelcomeText);
10 changes: 5 additions & 5 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic
Array.prototype.push.apply(searchTerms, reportName.split(/[,\s]/));

if (isChatRoomOrPolicyExpenseChat) {
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(report, policies);
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(report);

Array.prototype.push.apply(searchTerms, chatRoomSubtitle.split(/[,\s]/));
} else {
Expand Down Expand Up @@ -401,7 +401,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
result.hasOutstandingIOU = report.hasOutstandingIOU;

hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
subtitle = ReportUtils.getChatRoomSubtitle(report, policies);
subtitle = ReportUtils.getChatRoomSubtitle(report);

let lastMessageTextFromReport = '';
if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) {
Expand All @@ -421,7 +421,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
|| CONST.REPORT.ARCHIVE_REASON.DEFAULT;
lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, {
displayName: archiveReason.displayName || report.lastActorEmail,
policyName: ReportUtils.getPolicyName(report, policies),
policyName: ReportUtils.getPolicyName(report),
});
}

Expand All @@ -434,7 +434,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, {
? lastMessageText
: LocalePhoneNumber.formatPhoneNumber(personalDetail.login);
}
reportName = ReportUtils.getReportName(report, policies);
reportName = ReportUtils.getReportName(report);
} else {
const login = logins[0];
reportName = ReportUtils.getDisplayNameForParticipant(login);
Expand All @@ -453,7 +453,7 @@ function createOption(logins, personalDetails, report, reportActions = {}, {

result.text = reportName;
result.searchText = getSearchText(report, reportName, personalDetailList, result.isChatRoom || result.isPolicyExpenseChat);
result.icons = ReportUtils.getIcons(report, personalDetails, policies, ReportUtils.getAvatar(personalDetail.avatar, personalDetail.login));
result.icons = ReportUtils.getIcons(report, personalDetails, ReportUtils.getAvatar(personalDetail.avatar, personalDetail.login));
result.subtitle = subtitle;

return result;
Expand Down
45 changes: 23 additions & 22 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Onyx.connect({
callback: val => doesDomainHaveApprovedAccountant = lodashGet(val, 'doesDomainHaveApprovedAccountant', false),
});

let allPolicies;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: val => allPolicies = val,
});

function getChatType(report) {
return report ? report.chatType : '';
}
Expand Down Expand Up @@ -358,21 +365,20 @@ function isArchivedRoom(report) {
* @param {String} report.policyID
* @param {String} report.oldPolicyName
* @param {String} report.policyName
* @param {Object} policies must have Onyxkey prefix (i.e 'policy_') for keys
* @returns {String}
*/
function getPolicyName(report, policies) {
function getPolicyName(report) {
// Public rooms send back the policy name with the reportSummary,
// since they can also be accessed by people who aren't in the workspace
if (report.policyName) {
return report.policyName;
}

if (_.isEmpty(policies)) {
if (!allPolicies || _.size(allPolicies) === 0) {
return Localize.translateLocal('workspace.common.unavailable');
}

const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
if (!policy) {
return report.oldPolicyName || Localize.translateLocal('workspace.common.unavailable');
}
Expand Down Expand Up @@ -404,10 +410,9 @@ function isPolicyExpenseChatAdmin(report, policies) {
/**
* Get either the policyName or domainName the chat is tied to
* @param {Object} report
* @param {Object} policiesMap must have onyxkey prefix (i.e 'policy_') for keys
* @returns {String}
*/
function getChatRoomSubtitle(report, policiesMap) {
function getChatRoomSubtitle(report) {
if (!isDefaultRoom(report) && !isUserCreatedPolicyRoom(report) && !isPolicyExpenseChat(report)) {
return '';
}
Expand All @@ -421,19 +426,18 @@ function getChatRoomSubtitle(report, policiesMap) {
if (isArchivedRoom(report)) {
return report.oldPolicyName || '';
}
return getPolicyName(report, policiesMap);
return getPolicyName(report);
}

/**
* Get welcome message based on room type
* @param {Object} report
* @param {Object} policiesMap must have Onyxkey prefix (i.e 'policy_') for keys
* @returns {Object}
*/

function getRoomWelcomeMessage(report, policiesMap) {
function getRoomWelcomeMessage(report) {
const welcomeMessage = {};
const workspaceName = getPolicyName(report, policiesMap);
const workspaceName = getPolicyName(report);

if (isArchivedRoom(report)) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne');
Expand Down Expand Up @@ -663,11 +667,10 @@ function getSmallSizeAvatar(avatarURL, login) {
*
* @param {Object} report
* @param {Object} personalDetails
* @param {Object} policies
* @param {*} [defaultIcon]
* @returns {Array<*>}
*/
function getIcons(report, personalDetails, policies, defaultIcon = null) {
function getIcons(report, personalDetails, defaultIcon = null) {
const result = {
source: '',
type: CONST.ICON_TYPE_AVATAR,
Expand Down Expand Up @@ -703,11 +706,11 @@ function getIcons(report, personalDetails, policies, defaultIcon = null) {
return [result];
}
if (isPolicyExpenseChat(report)) {
const workspaceName = lodashGet(policies, [
const workspaceName = lodashGet(allPolicies, [
`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name',
]);

const policyExpenseChatAvatarSource = lodashGet(policies, [
const policyExpenseChatAvatarSource = lodashGet(allPolicies, [
`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'avatar',
]) || getDefaultWorkspaceAvatar(workspaceName);

Expand Down Expand Up @@ -837,18 +840,17 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport)
* Get the title for a policy expense chat which depends on the role of the policy member seeing this report
*
* @param {Object} report
* @param {Object} [policies]
* @returns {String}
*/
function getPolicyExpenseChatName(report, policies = {}) {
function getPolicyExpenseChatName(report) {
const reportOwnerDisplayName = getDisplayNameForParticipant(report.ownerEmail) || report.ownerEmail || report.reportName;

// If the policy expense chat is owned by this user, use the name of the policy as the report name.
if (report.isOwnPolicyExpenseChat) {
return getPolicyName(report, policies);
return getPolicyName(report);
}

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

Expand All @@ -858,7 +860,7 @@ function getPolicyExpenseChatName(report, policies = {}) {
const lastAction = ReportActionsUtils.getLastVisibleAction(report.reportID);
const archiveReason = (lastAction && lastAction.originalMessage && lastAction.originalMessage.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
if (archiveReason === CONST.REPORT.ARCHIVE_REASON.ACCOUNT_MERGED && policyExpenseChatRole !== CONST.POLICY.ROLE.ADMIN) {
return getPolicyName(report, policies);
return getPolicyName(report);
}
}

Expand All @@ -870,17 +872,16 @@ function getPolicyExpenseChatName(report, policies = {}) {
* Get the title for a report.
*
* @param {Object} report
* @param {Object} [policies]
* @returns {String}
*/
function getReportName(report, policies = {}) {
function getReportName(report) {
let formattedName;
if (isChatRoom(report)) {
formattedName = report.reportName;
}

if (isPolicyExpenseChat(report)) {
formattedName = getPolicyExpenseChatName(report, policies);
formattedName = getPolicyExpenseChatName(report);
}

if (isArchivedRoom(report)) {
Expand Down
8 changes: 4 additions & 4 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function getOrderedReportIDs(reportIDFromRoute) {
// However, this code needs to be very performant to handle thousands of reports, so in the interest of speed, we're just going to disable this lint rule and add
// the reportDisplayName property to the report object directly.
// eslint-disable-next-line no-param-reassign
report.displayName = ReportUtils.getReportName(report, policies);
report.displayName = ReportUtils.getReportName(report);

// eslint-disable-next-line no-param-reassign
report.iouReportAmount = ReportUtils.getIOUTotal(report, iouReports);
Expand Down Expand Up @@ -252,7 +252,7 @@ function getOptionData(reportID) {
result.hasOutstandingIOU = report.hasOutstandingIOU;

const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
const subtitle = ReportUtils.getChatRoomSubtitle(report, policies);
const subtitle = ReportUtils.getChatRoomSubtitle(report);

const login = Str.removeSMSDomain(lodashGet(personalDetail, 'login', ''));
const formattedLogin = Str.isSMSLogin(login) ? LocalePhoneNumber.formatPhoneNumber(login) : login;
Expand Down Expand Up @@ -288,7 +288,7 @@ function getOptionData(reportID) {
|| CONST.REPORT.ARCHIVE_REASON.DEFAULT;
lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, {
displayName: archiveReason.displayName || report.lastActorEmail,
policyName: ReportUtils.getPolicyName(report, policies),
policyName: ReportUtils.getPolicyName(report),
});
}

Expand Down Expand Up @@ -320,7 +320,7 @@ function getOptionData(reportID) {
result.payPalMeAddress = personalDetail.payPalMeAddress;
}

const reportName = ReportUtils.getReportName(report, policies);
const reportName = ReportUtils.getReportName(report);
result.text = reportName;
result.subtitle = subtitle;
result.participantsList = participantPersonalDetailList;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ReportDetailsPage extends Component {
render() {
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(this.props.report);
const isChatRoom = ReportUtils.isChatRoom(this.props.report);
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(this.props.report, this.props.policies);
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(this.props.report);
const participants = lodashGet(this.props.report, 'participants', []);
const isMultipleParticipant = participants.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(
Expand Down Expand Up @@ -127,7 +127,7 @@ class ReportDetailsPage extends Component {
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
<View style={[styles.alignSelfCenter, styles.w100]}>
<DisplayNames
fullTitle={ReportUtils.getReportName(this.props.report, this.props.policies)}
fullTitle={ReportUtils.getReportName(this.props.report)}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
Expand Down
13 changes: 3 additions & 10 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ const propTypes = {
/** The report currently being looked at */
report: reportPropTypes,

/** The policies which the user has access to and which the report could be tied to */
policies: PropTypes.shape({
/** Name of the policy */
name: PropTypes.string,
}),

/** Personal details of all the users */
personalDetails: PropTypes.objectOf(participantPropTypes),

Expand All @@ -57,7 +51,6 @@ const propTypes = {

const defaultProps = {
personalDetails: {},
policies: {},
report: null,
account: {
guideCalendarLink: null,
Expand All @@ -71,9 +64,9 @@ const HeaderView = (props) => {
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant);
const isChatRoom = ReportUtils.isChatRoom(props.report);
const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(props.report);
const title = ReportUtils.getReportName(props.report, props.policies);
const title = ReportUtils.getReportName(props.report);

const subtitle = ReportUtils.getChatRoomSubtitle(props.report, props.policies);
const subtitle = ReportUtils.getChatRoomSubtitle(props.report);
const isConcierge = participants.length === 1 && _.contains(participants, CONST.EMAIL.CONCIERGE);
const isAutomatedExpensifyAccount = (participants.length === 1 && ReportUtils.hasAutomatedExpensifyEmails(participants));
const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink');
Expand All @@ -83,7 +76,7 @@ const HeaderView = (props) => {
const shouldShowCallButton = (isConcierge && guideCalendarLink) || !isAutomatedExpensifyAccount;
const avatarTooltip = isChatRoom ? undefined : _.pluck(displayNamesWithTooltips, 'tooltip');
const shouldShowSubscript = isPolicyExpenseChat && !props.report.isOwnPolicyExpenseChat && !ReportUtils.isArchivedRoom(props.report);
const icons = ReportUtils.getIcons(props.report, props.personalDetails, props.policies);
const icons = ReportUtils.getIcons(props.report, props.personalDetails);
const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
return (
<View style={[styles.appContentHeader]} nativeID="drag-area">
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class ReportScreen extends React.Component {
onNavigationMenuButtonClicked={() => Navigation.navigate(ROUTES.HOME)}
personalDetails={this.props.personalDetails}
report={this.props.report}
policies={this.props.policies}
/>
</OfflineWithFeedback>
{Boolean(this.props.accountManagerReportID) && ReportUtils.isConciergeChatReport(this.props.report) && this.state.isBannerVisible && (
Expand Down
Loading