Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6cbf8ad
display iou or expense in LHN
mollfpr May 7, 2023
40064fe
update sidebar test to display IOU reports
mollfpr May 9, 2023
8a9dacb
update translation key
mollfpr May 9, 2023
31fdc00
move the payer name to own variable
mollfpr May 9, 2023
efff2bb
new method to determine should show the subscript on the report
mollfpr May 9, 2023
d9c12b2
shouldn't show the subscript if it's archived report
mollfpr May 9, 2023
aa166fd
Merge branch 'main' of https://github.com/mollfpr/App into mollfpr-18475
mollfpr May 10, 2023
f990a55
check if is not IOU or expense report
mollfpr May 10, 2023
eb2fc8e
use convertToDisplayString instead native number format method
mollfpr May 10, 2023
ecf8949
Merge branch 'mollfpr-18475' of https://github.com/mollfpr/App into m…
mollfpr May 10, 2023
5668136
fix typo method name
mollfpr May 10, 2023
29ca3b9
use full title name for money request report
mollfpr May 10, 2023
4707a88
rename iouReports to moneyRequestReports and use isMoneyRequestReport…
mollfpr May 10, 2023
bfbde91
Merge branch 'main' of https://github.com/mollfpr/App into mollfpr-18475
mollfpr May 10, 2023
d9faeb1
show icons for expense reports
mollfpr May 10, 2023
e16f206
Merge branch 'main' of https://github.com/mollfpr/App into mollfpr-18475
mollfpr May 10, 2023
391be49
Merge branch 'main' of https://github.com/mollfpr/App into mollfpr-18475
mollfpr May 11, 2023
6f1c13f
add fallback value for report total
mollfpr May 11, 2023
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/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const OptionRowLHN = (props) => {
tooltipEnabled
numberOfLines={1}
textStyles={displayNameStyle}
shouldUseFullTitle={optionItem.isChatRoom || optionItem.isPolicyExpenseChat || optionItem.isTaskReport}
shouldUseFullTitle={optionItem.isChatRoom || optionItem.isPolicyExpenseChat || optionItem.isTaskReport || optionItem.isMoneyRequestReport}
/>
{optionItem.isChatRoom && (
<TextPill
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export default {
settlePaypalMe: 'Pay with PayPal.me',
requestAmount: ({amount}) => `request ${amount}`,
splitAmount: ({amount}) => `split ${amount}`,
payerOwesAmount: ({payer, amount}) => `${payer} owes ${amount}`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
error: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export default {
settlePaypalMe: 'Pagar con PayPal.me',
requestAmount: ({amount}) => `solicitar ${amount}`,
splitAmount: ({amount}) => `dividir ${amount}`,
payerOwesAmount: ({payer, amount}) => `${payer} debe ${amount}`,
noReimbursableExpenses: 'El monto de este informe es inválido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
error: {
Expand Down
39 changes: 37 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ function getIcons(report, personalDetails, defaultIcon = null) {
result.source = Expensicons.ActiveRoomAvatar;
return [result];
}
if (isPolicyExpenseChat(report)) {
if (isPolicyExpenseChat(report) || isExpenseReport(report)) {
const workspaceName = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'name']);

const policyExpenseChatAvatarSource = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'avatar']) || getDefaultWorkspaceAvatar(workspaceName);
Expand Down Expand Up @@ -885,6 +885,19 @@ function getPolicyExpenseChatName(report) {
return reportOwnerDisplayName;
}

/**
* Get the title for a IOU or expense chat which will be showing the payer and the amount
*
* @param {Object} report
* @returns {String}
*/
function getMoneyRequestReportName(report) {
const formattedAmount = CurrencyUtils.convertToDisplayString(report.total || 0, report.currency);
const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail);

return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount});
}

/**
* Get the title for a report.
*
Expand All @@ -901,6 +914,10 @@ function getReportName(report) {
formattedName = getPolicyExpenseChatName(report);
}

if (isMoneyRequestReport(report)) {
formattedName = getMoneyRequestReportName(report);
}
Comment on lines +917 to +919

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luacmartins @Julesssss Aren't we going to be updating the reportName with the correct name to show here anytime the report is updated?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I'm following. Are you suggesting that we need to change this logic?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dotn have to do this now, but I thought we would be changing these things in the backend and just serve the finished name


if (isArchivedRoom(report)) {
formattedName += ` (${Localize.translateLocal('common.archived')})`;
}
Expand Down Expand Up @@ -1596,7 +1613,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr
// Exclude reports that have no data because there wouldn't be anything to show in the option item.
// This can happen if data is currently loading from the server or a report is in various stages of being created.
// This can also happen for anyone accessing a public room or archived room for which they don't have access to the underlying policy.
if (!report || !report.reportID || !report.participants || (_.isEmpty(report.participants) && !isPublicRoom(report) && !isArchivedRoom(report)) || isIOUReport(report)) {
if (!report || !report.reportID || (_.isEmpty(report.participants) && !isPublicRoom(report) && !isArchivedRoom(report) && !isMoneyRequestReport(report))) {
return false;
}

Expand Down Expand Up @@ -1877,6 +1894,23 @@ function getWhisperDisplayNames(participants) {
return _.map(participants, (login) => getDisplayNameForParticipant(login, !isWhisperOnlyVisibleToCurrentUSer)).join(', ');
}

/**
* Show subscript on IOU or expense report
* @param {Object} report
* @returns {Boolean}
*/
function shouldReportShowSubscript(report) {
if (isArchivedRoom(report)) {
return false;
}
Comment thread
mollfpr marked this conversation as resolved.

if (isPolicyExpenseChat(report) && !report.isOwnPolicyExpenseChat) {
return true;
}

return isExpenseReport(report);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -1956,4 +1990,5 @@ export {
canRequestMoney,
getWhisperDisplayNames,
getWorkspaceAvatar,
shouldReportShowSubscript,
};
27 changes: 16 additions & 11 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import * as LocalePhoneNumber from './LocalePhoneNumber';
// data anyway and cause SidebarLinks to rerender.

const chatReports = {};
const iouReports = {};
const moneyRequestReports = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (report, key) => {
if (!report) {
delete iouReports[key];
delete moneyRequestReports[key];
delete chatReports[key];
} else if (ReportUtils.isIOUReport(report)) {
iouReports[key] = report;
} else if (ReportUtils.isMoneyRequestReport(report)) {
moneyRequestReports[key] = report;
} else {
chatReports[key] = report;
}
Expand Down Expand Up @@ -108,7 +108,9 @@ function getOrderedReportIDs(reportIDFromRoute) {
const isInDefaultMode = !isInGSDMode;

// Filter out all the reports that shouldn't be displayed
const reportsToDisplay = _.filter(chatReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, iouReports, betas, policies));
const reportsToDisplay = _.filter({...chatReports, ...moneyRequestReports}, (report) =>
ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, moneyRequestReports, betas, policies),
);

// There are a few properties that need to be calculated for the report which are used when sorting reports.
_.each(reportsToDisplay, (report) => {
Expand All @@ -119,7 +121,7 @@ function getOrderedReportIDs(reportIDFromRoute) {
report.displayName = ReportUtils.getReportName(report);

// eslint-disable-next-line no-param-reassign
report.iouReportAmount = ReportUtils.getIOUTotal(report, iouReports);
report.iouReportAmount = ReportUtils.getIOUTotal(report, moneyRequestReports);
});

// The LHN is split into five distinct groups, and each group is sorted a little differently. The groups will ALWAYS be in this order:
Expand All @@ -144,7 +146,7 @@ function getOrderedReportIDs(reportIDFromRoute) {
return;
}

if (report.hasOutstandingIOU && !ReportUtils.isIOUOwnedByCurrentUser(report, iouReports)) {
if (report.hasOutstandingIOU && !ReportUtils.isIOUOwnedByCurrentUser(report, moneyRequestReports)) {
outstandingIOUReports.push(report);
return;
}
Expand Down Expand Up @@ -192,7 +194,8 @@ function getOrderedReportIDs(reportIDFromRoute) {
* @returns {Object}
*/
function getOptionData(reportID) {
const report = chatReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`;
const report = chatReports[reportKey] || moneyRequestReports[reportKey];

// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for
// this method to be called after the Onyx data has been cleared out. In that case, it's fine to do
Expand Down Expand Up @@ -229,6 +232,7 @@ function getOptionData(reportID) {
isArchivedRoom: false,
shouldShowSubscript: false,
isPolicyExpenseChat: false,
isMoneyRequestReport: false,
};

const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForLogins(report.participants, personalDetails));
Expand All @@ -238,7 +242,8 @@ function getOptionData(reportID) {
result.isTaskReport = ReportUtils.isTaskReport(report);
result.isArchivedRoom = ReportUtils.isArchivedRoom(report);
result.isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
result.shouldShowSubscript = result.isPolicyExpenseChat && !report.isOwnPolicyExpenseChat && !result.isArchivedRoom;
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
result.shouldShowSubscript = ReportUtils.shouldReportShowSubscript(report);
result.pendingAction = report.pendingFields ? report.pendingFields.addWorkspaceRoom || report.pendingFields.createChat : null;
result.allReportErrors = OptionsListUtils.getAllReportErrors(report, reportActions);
result.brickRoadIndicator = !_.isEmpty(result.allReportErrors) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
Expand Down Expand Up @@ -325,8 +330,8 @@ function getOptionData(reportID) {
result.alternateText = lastMessageText || formattedLogin;
}

result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result, iouReports);
result.iouReportAmount = ReportUtils.getIOUTotal(result, iouReports);
result.isIOUReportOwner = ReportUtils.isIOUOwnedByCurrentUser(result, moneyRequestReports);
result.iouReportAmount = ReportUtils.getIOUTotal(result, moneyRequestReports);

if (!hasMultipleParticipants) {
result.login = personalDetail.login;
Expand Down
13 changes: 10 additions & 3 deletions tests/unit/SidebarOrderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ describe('Sidebar', () => {
...LHNTestUtils.getFakeReport(['email7@test.com', 'email8@test.com']),
type: CONST.REPORT.TYPE.IOU,
ownerEmail: 'email2@test.com',
managerEmail: 'email2@test.com',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
Expand Down Expand Up @@ -391,12 +392,13 @@ describe('Sidebar', () => {
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(displayNames).toHaveLength(4);
expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1);
expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Email Two owes $100.00');
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Three, Four');
})
);
});
Expand Down Expand Up @@ -676,6 +678,7 @@ describe('Sidebar', () => {
...LHNTestUtils.getFakeReport(['email7@test.com', 'email8@test.com']),
type: CONST.REPORT.TYPE.IOU,
ownerEmail: 'email2@test.com',
managerEmail: 'email2@test.com',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
Expand All @@ -685,6 +688,7 @@ describe('Sidebar', () => {
...LHNTestUtils.getFakeReport(['email9@test.com', 'email10@test.com']),
type: CONST.REPORT.TYPE.IOU,
ownerEmail: 'email2@test.com',
managerEmail: 'email2@test.com',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
Expand All @@ -694,6 +698,7 @@ describe('Sidebar', () => {
...LHNTestUtils.getFakeReport(['email11@test.com', 'email12@test.com']),
type: CONST.REPORT.TYPE.IOU,
ownerEmail: 'email2@test.com',
managerEmail: 'email2@test.com',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
Expand Down Expand Up @@ -727,10 +732,12 @@ describe('Sidebar', () => {
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(displayNames).toHaveLength(5);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Email Two owes $100.00');
expect(lodashGet(displayNames, [4, 'props', 'children'])).toBe('Email Two owes $100.00');
})
);
});
Expand Down