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

Display latest reportName in all front end views with ReportUtils.getReportName #8569

Merged
merged 35 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
edfc7e6
Use latest name from Onyx in policyExpenseChats
Apr 8, 2022
2c273c3
Use policyExpenseChat title in HeaderView
Apr 14, 2022
ce6996b
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
Apr 14, 2022
0c5ecbe
Move function to avoid cyclic dependency
Apr 14, 2022
f79a573
Fix policyExpenseChat name in LHN
Apr 14, 2022
5038ade
Style fixes for whitespace and returntype
Apr 14, 2022
99a3f04
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
May 18, 2022
3579468
Fix import casing
May 18, 2022
9094517
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
May 18, 2022
e15c888
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
May 26, 2022
a7a15e1
Remove reportnamevaluepair check since reports in onyx don't have them
May 26, 2022
4730c25
Fix double #'ed chat room names
May 26, 2022
04e2db4
Fix blank report header view
May 26, 2022
1fa3974
Remove unused code
May 26, 2022
b3fa99a
Remove unecessary getPolicyExpenseChatTitle
May 27, 2022
1b89044
Use getReportName when building options
May 27, 2022
91e7646
Use getReportName in ReportDetailsPage
May 27, 2022
918a137
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
May 27, 2022
8920903
Use getReportName in ReportWelcomeText
May 27, 2022
9ab4d8d
Make tests accomodate Onyx Reports created from Report.getChatReportName
May 27, 2022
e5112f8
Remove redundant getChatReportName and put logic in getReportName
May 27, 2022
706be32
Update OptionListUtils test to use standard reportName in Onyx and po…
May 27, 2022
be133b7
Clean up tests slightly
May 27, 2022
850e647
Make function only relevant for chat reports
May 28, 2022
5442735
lint fixes
May 28, 2022
b953660
Use getReportName for all chat titles instead of doing double work
May 31, 2022
716dca0
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
May 31, 2022
3e495a2
Fix tests to work with name alphabetizing
Jun 1, 2022
aaefdf1
Fix tests for Captain Britain using personal detail
Jun 1, 2022
5493a37
Fix searching for options using reportName
Jun 1, 2022
9fd17a1
Lint fixes
Jun 1, 2022
150dfeb
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
Jun 1, 2022
e15edaa
Remove deleted translation which is no longer used
Jun 1, 2022
004b6d0
Fix policyExpenseChat tests
Jun 3, 2022
010ca12
Merge branch 'main' of github.com:Expensify/App into amal-policyExpen…
Jun 3, 2022
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
2 changes: 1 addition & 1 deletion src/components/ReportWelcomeText.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const ReportWelcomeText = (props) => {
{roomWelcomeMessage.phrase1}
</Text>
<Text style={[styles.textStrong]} onPress={() => Navigation.navigate(ROUTES.getReportDetailsRoute(props.report.reportID))}>
{props.report.reportName}
{ReportUtils.getReportName(props.report, props.personalDetails, props.policies)}
</Text>
<Text>
{roomWelcomeMessage.phrase2}
Expand Down
1 change: 0 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default {
privacy: 'Privacy',
privacyPolicy: 'Privacy policy',
delete: 'Delete',
deleted: 'deleted',
archived: 'archived',
contacts: 'Contacts',
recents: 'Recents',
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default {
privacy: 'Privacidad',
privacyPolicy: 'Política de privacidad',
delete: 'Eliminar',
deleted: 'eliminado',
archived: 'archivado',
contacts: 'Contactos',
recents: 'Recientes',
Expand Down
22 changes: 9 additions & 13 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand All @@ -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'),
Expand Down
10 changes: 5 additions & 5 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
}

roryabraham marked this conversation as resolved.
Show resolved Hide resolved
let formattedName;
if (isChatRoom(report)) {
if (isDefaultRoom(report)) {
formattedName = `#${report.reportName}`;
TomatoToaster marked this conversation as resolved.
Show resolved Hide resolved
}

if (isUserCreatedPolicyRoom(report)) {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
formattedName = report.reportName;
}

if (isPolicyExpenseChat(report)) {
const reportOwnerPersonalDetails = lodashGet(personalDetailsForParticipants, report.ownerEmail);
const reportOwnerDisplayName = getDisplayNameForParticipant(reportOwnerPersonalDetails) || report.reportName;
Expand Down
45 changes: 1 addition & 44 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')})` : ''}`;
TomatoToaster marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
Expand Down Expand Up @@ -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')
Expand All @@ -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'], ''),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ReportDetailsPage extends Component {
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
<View style={[styles.alignSelfCenter, styles.w100]}>
<DisplayNames
fullTitle={this.props.report.reportName}
fullTitle={ReportUtils.getReportName(this.props.report, this.props.personalDetails, this.props.policies)}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const HeaderView = (props) => {
</Pressable>
</Tooltip>
)}
{Boolean(props.report && props.report.reportName) && (
{Boolean(props.report && title) && (
<View
style={[
styles.flex1,
Expand Down
58 changes: 38 additions & 20 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ describe('OptionsListUtils', () => {
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,
},
};

Expand Down Expand Up @@ -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({
Expand All @@ -269,6 +275,7 @@ describe('OptionsListUtils', () => {
ownerEmail: 'mistersinister@marauders.com',
total: '1000',
},
[`${ONYXKEYS.COLLECTION.POLICY}${POLICY.policyID}`]: POLICY,
},
});
Onyx.registerLogger(() => {});
Expand Down Expand Up @@ -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,
);
Expand All @@ -636,14 +650,15 @@ 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
index += 2;
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');
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -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');
Expand Down
Loading