diff --git a/src/components/ReportWelcomeText.js b/src/components/ReportWelcomeText.js index 4db3eaa6b205..72cf9bc3ad60 100644 --- a/src/components/ReportWelcomeText.js +++ b/src/components/ReportWelcomeText.js @@ -96,7 +96,7 @@ const ReportWelcomeText = (props) => { {roomWelcomeMessage.phrase1} Navigation.navigate(ROUTES.getReportDetailsRoute(props.report.reportID))}> - {props.report.reportName} + {ReportUtils.getReportName(props.report, props.personalDetails, props.policies)} {roomWelcomeMessage.phrase2} diff --git a/src/languages/en.js b/src/languages/en.js index f3c028c8a5d8..99166fdca0fa 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -37,7 +37,6 @@ export default { privacy: 'Privacy', privacyPolicy: 'Privacy policy', delete: 'Delete', - deleted: 'deleted', archived: 'archived', contacts: 'Contacts', recents: 'Recents', diff --git a/src/languages/es.js b/src/languages/es.js index f968c28ac221..2c3ba17d6975 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -37,7 +37,6 @@ export default { privacy: 'Privacidad', privacyPolicy: 'PolĂ­tica de privacidad', delete: 'Eliminar', - deleted: 'eliminado', archived: 'archivado', contacts: 'Contactos', recents: 'Recientes', diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 339dd2c6e259..e5766032250e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -163,11 +163,12 @@ function getParticipantNames(personalDetailList) { * Default should be serachable by policy/domain name but not by participants. * * @param {Object} report + * @param {String} reportName * @param {Array} personalDetailList * @param {Boolean} isChatRoomOrPolicyExpenseChat * @return {String} */ -function getSearchText(report, personalDetailList, isChatRoomOrPolicyExpenseChat) { +function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolicyExpenseChat) { const searchTerms = []; if (!isChatRoomOrPolicyExpenseChat) { @@ -177,8 +178,8 @@ function getSearchText(report, personalDetailList, isChatRoomOrPolicyExpenseChat }); } if (report) { - searchTerms.push(...report.reportName); - searchTerms.push(..._.map(report.reportName.split(','), name => name.trim())); + searchTerms.push(...reportName); + searchTerms.push(..._.map(reportName.split(','), name => name.trim())); if (isChatRoomOrPolicyExpenseChat) { const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(report, policies); @@ -220,7 +221,8 @@ function createOption(logins, personalDetails, report, { }) { const isChatRoom = ReportUtils.isChatRoom(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); - const personalDetailList = _.values(getPersonalDetailsForLogins(logins, personalDetails)); + const personalDetailMap = getPersonalDetailsForLogins(logins, personalDetails); + const personalDetailList = _.values(personalDetailMap); const isArchivedRoom = ReportUtils.isArchivedRoom(report); const hasMultipleParticipants = personalDetailList.length > 1 || isChatRoom || isPolicyExpenseChat; const personalDetail = personalDetailList[0]; @@ -249,25 +251,19 @@ function createOption(logins, personalDetails, report, { const tooltipText = ReportUtils.getReportParticipantsTitle(lodashGet(report, ['participants'], [])); const subtitle = ReportUtils.getChatRoomSubtitle(report, policies); - let text; + const reportName = ReportUtils.getReportName(report, personalDetailMap, policies); let alternateText; if (isChatRoom || isPolicyExpenseChat) { - text = lodashGet(report, 'reportName') - || lodashGet(report, 'oldPolicyName', ''); alternateText = (showChatPreviewLine && !forcePolicyNamePreview && lastMessageText) ? lastMessageText : subtitle; } else { - text = hasMultipleParticipants - ? _.map(personalDetailList, ({firstName, login}) => firstName || Str.removeSMSDomain(login)) - .join(', ') - : lodashGet(report, ['reportName'], personalDetail.displayName); alternateText = (showChatPreviewLine && lastMessageText) ? lastMessageText : Str.removeSMSDomain(personalDetail.login); } return { - text, + text: reportName, alternateText, icons: ReportUtils.getIcons(report, personalDetails, policies, lodashGet(personalDetail, ['avatar'])), tooltipText, @@ -284,7 +280,7 @@ function createOption(logins, personalDetails, report, { isUnread: report ? report.unreadActionCount > 0 : null, hasDraftComment, keyForList: report ? String(report.reportID) : personalDetail.login, - searchText: getSearchText(report, personalDetailList, isChatRoom || isPolicyExpenseChat), + searchText: getSearchText(report, reportName, personalDetailList, isChatRoom || isPolicyExpenseChat), isPinned: lodashGet(report, 'isPinned', false), hasOutstandingIOU, iouReportID: lodashGet(report, 'iouReportID'), diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 4a50afedf598..3add040e848a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -452,15 +452,15 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport) * @returns {String} */ function getReportName(report, personalDetailsForParticipants = {}, policies = {}) { - if (lodashGet(report, 'reportNameValuePairs.type') !== 'chat') { - return lodashGet(report, 'reportName', ''); - } - let formattedName; - if (isChatRoom(report)) { + if (isDefaultRoom(report)) { formattedName = `#${report.reportName}`; } + if (isUserCreatedPolicyRoom(report)) { + formattedName = report.reportName; + } + if (isPolicyExpenseChat(report)) { const reportOwnerPersonalDetails = lodashGet(personalDetailsForParticipants, report.ownerEmail); const reportOwnerDisplayName = getDisplayNameForParticipant(reportOwnerPersonalDetails) || report.reportName; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 1dd7a21b4685..8008289cfb8f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -137,46 +137,6 @@ function getParticipantEmailsFromReport({sharedReportList, reportNameValuePairs, return _.without(emailArray, currentUserEmail); } -/** - * Returns the title for a default room, a policy room or generates one based on the participants - * - * @param {Object} fullReport - * @param {String} chatType - * @param {String} oldPolicyName - * @return {String} - */ -function getChatReportName(fullReport, chatType, oldPolicyName) { - const isArchivedRoom = ReportUtils.isArchivedRoom({ - chatType, - stateNum: fullReport.state, - statusNum: fullReport.status, - }); - - if (ReportUtils.isDefaultRoom({chatType})) { - return `#${fullReport.reportName}${isArchivedRoom ? ` (${Localize.translateLocal('common.deleted')})` : ''}`; - } - - // For a basic policy room, return its original name - if (ReportUtils.isUserCreatedPolicyRoom({chatType})) { - return LoginUtils.getEmailWithoutMergedAccountPrefix(fullReport.reportName); - } - - if (ReportUtils.isPolicyExpenseChat({chatType})) { - const name = (isArchivedRoom && fullReport.isOwnPolicyExpenseChat) - ? oldPolicyName - : LoginUtils.getEmailWithoutMergedAccountPrefix(lodashGet(fullReport, ['reportName'], '')); - return `${name}${isArchivedRoom ? ` (${Localize.translateLocal('common.archived')})` : ''}`; - } - - const {sharedReportList} = fullReport; - return _.chain(sharedReportList) - .map(participant => participant.email) - .filter(participant => participant !== currentUserEmail) - .map(participant => PersonalDetails.getDisplayName(participant)) - .value() - .join(', '); -} - /** * Only store the minimal amount of data in Onyx that needs to be stored * because space is limited @@ -208,9 +168,6 @@ function getSimplifiedReportObject(report) { // Used for archived rooms, will store the policy name that the room used to belong to. const oldPolicyName = lodashGet(report, ['reportNameValuePairs', 'oldPolicyName'], ''); - const reportName = lodashGet(report, ['reportNameValuePairs', 'type']) === 'chat' - ? getChatReportName(report, chatType, oldPolicyName) - : report.reportName; const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); const notificationPreference = ReportUtils.isChatRoom({chatType}) ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily') @@ -221,7 +178,7 @@ function getSimplifiedReportObject(report) { return { reportID: report.reportID, - reportName, + reportName: report.reportName, chatType, ownerEmail: LoginUtils.getEmailWithoutMergedAccountPrefix(lodashGet(report, ['ownerEmail'], '')), policyID: lodashGet(report, ['reportNameValuePairs', 'expensify_policyID'], ''), diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index e6b171c03329..6a1ca6f60899 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -132,7 +132,7 @@ class ReportDetailsPage extends Component { { )} - {Boolean(props.report && props.report.reportName) && ( + {Boolean(props.report && title) && ( { lastMessageTimestamp: 1, reportID: 10, isPinned: false, - participants: ['captain_britain@expensify.com', 'captain_america@expensify.com'], + participants: ['tonystark@expensify.com', 'steverogers@expensify.com'], reportName: '', oldPolicyName: "SHIELD's workspace", chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, }, }; @@ -259,6 +260,11 @@ describe('OptionsListUtils', () => { }, }; + const POLICY = { + policyID: 'ABC123', + name: 'Hero Policy', + }; + // Set the currently logged in user, report data, and personal details beforeAll(() => { Onyx.init({ @@ -269,6 +275,7 @@ describe('OptionsListUtils', () => { ownerEmail: 'mistersinister@marauders.com', total: '1000', }, + [`${ONYXKEYS.COLLECTION.POLICY}${POLICY.policyID}`]: POLICY, }, }); Onyx.registerLogger(() => {}); @@ -613,13 +620,20 @@ describe('OptionsListUtils', () => { reportName: 'Captain Britain', }, }; + const personalDetailsWithNewParticipant = { + ...PERSONAL_DETAILS, + 'captain_britain@expensify.com': { + displayName: 'Captain Britain', + login: 'captain_britain@expensify.com', + }, + }; return Report.setReportWithDraft(1, true) .then(() => { // When we call getSidebarOptions() with no search value and default priority mode const results = OptionsListUtils.getSidebarOptions( reportsWithAddedPinnedMessagelessReport, - PERSONAL_DETAILS, + personalDetailsWithNewParticipant, 0, CONST.PRIORITY_MODE.DEFAULT, ); @@ -636,6 +650,7 @@ describe('OptionsListUtils', () => { // And the most recent pinned report is first in the list of reports let index = 0; + expect(results.recentReports[index].text).toBe('Captain Britain'); expect(results.recentReports[index].login).toBe('captain_britain@expensify.com'); // And the third report is the report with an IOU debt @@ -643,7 +658,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports[index].login).toBe('mistersinister@marauders.com'); // And the fourth report is the report with a draft comment - expect(results.recentReports[++index].text).toBe('tonystark@expensify.com, reedrichards@expensify.com'); + expect(results.recentReports[++index].text).toBe('Iron Man, Mister Fantastic'); // And the fifth report is the report with the lastMessage timestamp expect(results.recentReports[++index].login).toBe('steverogers@expensify.com'); @@ -666,15 +681,18 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); // Pinned reports are always on the top in alphabetical order regardless of whether they are unread or have IOU debt. - // D report name (Alphabetically first among pinned reports) + // Mister Fantastic report name (Alphabetically first among pinned reports) let index = 0; - expect(results.recentReports[index].login).toBe('d_email@email.com'); + expect(results.recentReports[index].text).toBe('Mister Fantastic'); + expect(results.recentReports[index].login).toBe('reedrichards@expensify.com'); - // Mister Fantastic report name (Alphabetically second among pinned reports) - expect(results.recentReports[++index].login).toBe('reedrichards@expensify.com'); + // d_email@email.com report name (Alphabetically second among pinned reports because of lowercase name) + expect(results.recentReports[++index].text).toBe('d_email@email.com'); + expect(results.recentReports[index].login).toBe('d_email@email.com'); - // Z report name (Alphabetically third among pinned reports) - expect(results.recentReports[++index].login).toBe('z_email@email.com'); + // z_email@email.com (Alphabetically third among pinned reports) + expect(results.recentReports[++index].text).toBe('z_email@email.com'); + expect(results.recentReports[index].login).toBe('z_email@email.com'); // Unpinned report name ordered alphabetically after pinned reports // Black Panther report name has unread message @@ -700,32 +718,32 @@ describe('OptionsListUtils', () => { const reportsWithEmptyChatRooms = { // This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) 10: { - chatType: 'policyExpenseChat', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, hasOutstandingIOU: false, isOwnPolicyExpenseChat: true, isPinned: false, lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', + policyID: 'ABC123', reportID: 10, - reportName: "Someone's workspace", + reportName: '', unreadActionCount: 0, visibility: undefined, }, // This is an archived version of the above policyExpenseChat 11: { - chatType: 'policyExpenseChat', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, hasOutstandingIOU: false, isOwnPolicyExpenseChat: true, isPinned: false, lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', + policyID: 'ABC123', reportID: 11, - reportName: "Someone's workspace", + reportName: '', unreadActionCount: 0, visibility: undefined, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, @@ -740,9 +758,9 @@ describe('OptionsListUtils', () => { lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', + policyID: 'ABC123', reportID: 12, - reportName: '#admins', + reportName: 'admins', unreadActionCount: 0, visibility: undefined, }, @@ -755,9 +773,9 @@ describe('OptionsListUtils', () => { lastMessageTimestamp: 0, lastVisitedTimestamp: 1610666739302, participants: ['test3@instantworkspace.com'], - policyID: 'Whatever', + policyID: 'ABC123', reportID: 13, - reportName: '#admins', + reportName: 'admins', unreadActionCount: 0, visibility: undefined, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, @@ -777,7 +795,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 2); expect(results.recentReports[0].isPolicyExpenseChat).toBe(true); - expect(results.recentReports[0].text).toBe("Someone's workspace"); + expect(results.recentReports[0].text).toBe('Hero Policy'); expect(results.recentReports[1].isChatRoom).toBe(true); expect(results.recentReports[1].text).toBe('#admins'); diff --git a/tests/unit/ReportUtilsTest.js b/tests/unit/ReportUtilsTest.js index e2f9fefbda52..7f872a012b6a 100644 --- a/tests/unit/ReportUtilsTest.js +++ b/tests/unit/ReportUtilsTest.js @@ -5,12 +5,6 @@ import ONYXKEYS from '../../src/ONYXKEYS'; import * as ReportUtils from '../../src/libs/ReportUtils'; import waitForPromisesToResolve from '../utils/waitForPromisesToResolve'; -const REPORT_TYPE_CHAT = { - reportNameValuePairs: { - type: CONST.REPORT.TYPE.CHAT, - }, -}; - const currentUserEmail = 'bjorn@vikings.net'; const participantsPersonalDetails = { 'ragnar@vikings.net': { @@ -101,21 +95,18 @@ describe('ReportUtils', () => { describe('1:1 DM', () => { test('with displayName', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, participants: [currentUserEmail, 'ragnar@vikings.net'], }, _.pick(participantsPersonalDetails, 'ragnar@vikings.net'))).toBe('Ragnar Lothbrok'); }); test('no displayName', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, participants: [currentUserEmail, 'floki@vikings.net'], }, _.pick(participantsPersonalDetails, 'floki@vikings.net'))).toBe('floki@vikings.net'); }); test('SMS', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, participants: [currentUserEmail, '+12223334444@expensify.sms'], }, _.pick(participantsPersonalDetails, '+12223334444@expensify.sms'))).toBe('2223334444'); }); @@ -123,14 +114,12 @@ describe('ReportUtils', () => { test('Group DM', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, participants: [currentUserEmail, 'ragnar@vikings.net', 'floki@vikings.net', 'lagertha@vikings.net', '+12223334444@expensify.sms'], }, participantsPersonalDetails)).toBe('Ragnar, floki@vikings.net, Lagertha, 2223334444'); }); describe('Default Policy Room', () => { const baseAdminsRoom = { - ...REPORT_TYPE_CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, reportName: 'admins', }; @@ -155,9 +144,8 @@ describe('ReportUtils', () => { describe('User-Created Policy Room', () => { const baseUserCreatedRoom = { - ...REPORT_TYPE_CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, - reportName: 'VikingsChat', + reportName: '#VikingsChat', }; test('Active', () => { @@ -182,16 +170,15 @@ describe('ReportUtils', () => { describe('Active', () => { test('as member', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID: policy.policyID, isOwnPolicyExpenseChat: true, - }, {}, policies)).toBe(policy.name); + ownerEmail: 'ragnar@vikings.net', + }, participantsPersonalDetails, policies)).toBe('Vikings Policy'); }); test('as admin', () => { expect(ReportUtils.getReportName({ - ...REPORT_TYPE_CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, policyID: policy.policyID, isOwnPolicyExpenseChat: false, @@ -202,7 +189,6 @@ describe('ReportUtils', () => { describe('Archived', () => { const baseArchivedPolicyExpenseChat = { - ...REPORT_TYPE_CHAT, chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, ownerEmail: 'ragnar@vikings.net', policyID: policy.policyID,