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 displayName instead of primaryLogin on the ReportPreview message #20446

Merged
merged 34 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d2c07a2
Display displayName instead of primaryLogin in report preview
hoangzinh Jun 8, 2023
5e1b4c7
Show report preview action in LHN
hoangzinh Jun 8, 2023
4338186
Refactor code using existing util to display money request message
hoangzinh Jun 8, 2023
b58a8f8
Fix linter
hoangzinh Jun 8, 2023
3b8bb48
Fix linter
hoangzinh Jun 8, 2023
3788f8f
Merge branch 'main' into df/19301
hoangzinh Jun 14, 2023
9171962
Add a new utils to get money request message
hoangzinh Jun 14, 2023
0da6a76
remove redundant export
hoangzinh Jun 14, 2023
644d71f
Fix settled message is 0 amount in LHN
hoangzinh Jun 14, 2023
d58e95c
Merge branch 'main' into df/19301
hoangzinh Jun 14, 2023
1e1e34d
Fix amount is 0 after sign in
hoangzinh Jun 14, 2023
e329173
Fix linter
hoangzinh Jun 14, 2023
caa45ea
Fix checking isHavingOustandingIOU
hoangzinh Jun 15, 2023
b57b897
Correct the method name
hoangzinh Jun 15, 2023
9009632
Refactor as feedbacks
hoangzinh Jun 15, 2023
f4e1390
Update variable name
hoangzinh Jun 15, 2023
bad0519
Merge branch 'main' into df/19301
hoangzinh Jun 15, 2023
5bd7268
Correct typo
hoangzinh Jun 16, 2023
0320938
Merge branch 'main' into df/19301
hoangzinh Jun 21, 2023
20b7a1a
Show report review action message in LHN
hoangzinh Jun 21, 2023
e59d39f
Remove map action.message
hoangzinh Jun 21, 2023
d1c6412
Rename method to scope it only for reportAction preview
hoangzinh Jun 21, 2023
117c9f0
Fix eslint
hoangzinh Jun 21, 2023
a5d0633
Fix get payerName
hoangzinh Jun 21, 2023
e018913
Use last visible action instead of last action
hoangzinh Jun 21, 2023
8942536
Remove redundant empty line
hoangzinh Jun 21, 2023
ba57e73
Revert back to lastReportAction because new reportActionView is optim…
hoangzinh Jun 21, 2023
8142f02
If iouReport is not found locally then use BE message other parse BE …
hoangzinh Jun 25, 2023
d1e4aae
Use report action message instead report last message text
hoangzinh Jun 25, 2023
638fe01
Merge branch 'main' into df/19301
hoangzinh Jun 25, 2023
c9a25e5
Fix translate settled message to ES
hoangzinh Jun 26, 2023
0fc3ed0
Merge branch 'main' into df/19301
hoangzinh Jun 26, 2023
331cc43
Rename method to avoid confusing
hoangzinh Jun 26, 2023
0f106df
Merge branch 'main' into df/19301
hoangzinh Jun 28, 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
36 changes: 13 additions & 23 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ControlSelection from '../../libs/ControlSelection';
import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
import {showContextMenuForReport} from '../ShowContextMenuContext';
import * as StyleUtils from '../../styles/StyleUtils';
import * as CurrencyUtils from '../../libs/CurrencyUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
Expand Down Expand Up @@ -95,11 +94,10 @@ const defaultProps = {
};

function ReportPreview(props) {
const reportAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.iouReport), props.iouReport.currency);
const managerEmail = props.iouReport.managerEmail || '';
const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerEmail, true);
const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null);
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const displayingMessage = ReportUtils.getMoneyRequestReportActionMessage(props.iouReport, props.action);
return (
<View style={[styles.chatItemMessage]}>
{_.map(props.action.message, (message, index) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

The message is not used here anymore

Suggested change
{_.map(props.action.message, (message, index) => (
{_.map(props.action.message, (message, index) => (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should keep message here even thought it's not used. Because according to the underscore doc https://underscorejs.org/#map, the fist param is value, and 2nd is index and we would like to use index when build list key

key={`ReportPreview-${props.action.reportActionID}-${index}`}

Btw, I guess we can remove _.map here. It seems all the follow-up messages has been moved into iouReport.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I think we can remove the map altogether

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mountiny do you agree we can remove the map altogether?

Copy link
Contributor

Choose a reason for hiding this comment

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

@hoangzinh Yep lets try removing it

Copy link
Contributor Author

@hoangzinh hoangzinh Jun 21, 2023

Choose a reason for hiding this comment

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

I removed the map. Feel free to review the PR again. Thanks

Expand All @@ -115,26 +113,18 @@ function ReportPreview(props) {
focusable
>
<View style={[styles.flexShrink1]}>
{props.iouReport.hasOutstandingIOU ? (
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>
{lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))}
</Text>
) : (
<View style={[styles.flexRow]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>
{lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))}
</Text>
{!props.iouReport.hasOutstandingIOU && (
<View style={styles.iouPreviewBoxCheckmark}>
<Icon
style={[styles.ml10]}
src={Expensicons.Checkmark}
fill={themeColors.iconSuccessFill}
/>
</View>
)}
</View>
)}
<View style={[styles.flexRow]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>{displayingMessage}</Text>
{!props.iouReport.hasOutstandingIOU && (
<View style={styles.iouPreviewBoxCheckmark}>
<Icon
style={[styles.ml10]}
src={Expensicons.Checkmark}
fill={themeColors.iconSuccessFill}
/>
</View>
)}
</View>
</View>
<Icon
src={Expensicons.ArrowRight}
Expand Down
20 changes: 20 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function isMoneyRequestAction(reportAction) {
return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.IOU;
}

/**
* @param {Object} reportAction
* @returns {Boolean}
*/
function isReportPreviewAction(reportAction) {
return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW;
}

/**
* @param {Object} reportAction
* @returns {Boolean}
Expand Down Expand Up @@ -417,6 +425,16 @@ function getReportPreviewAction(chatReportID, iouReportID) {
);
}

/**
* Get the iouReportID for a given report action.
*
* @param {Object} reportAction
* @returns {String}
*/
function getIOUReportID(reportAction) {
return lodashGet(reportAction, 'originalMessage.linkedReportID', '');
}

function isCreatedTaskReportAction(reportAction) {
return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID');
}
Expand Down Expand Up @@ -453,5 +471,7 @@ export {
isTransactionThread,
getFormattedAmount,
isSentMoneyReportAction,
isReportPreviewAction,
getIOUReportID,
isMessageDeleted,
};
32 changes: 32 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,37 @@ function getTransactionReportName(reportAction) {
});
}

/**
* Get money request message for a IOU report
*
* @param {Object} report
* @param {Object} reportAction
* @returns {String}
*/
function getMoneyRequestReportActionMessage(report, reportAction) {
let formattedAmount = null;
let reportHasOutstandingIOU = null;
const totalAmount = getMoneyRequestTotal(report);
const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerEmail, true);

if (totalAmount > 0) {
formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency);
reportHasOutstandingIOU = report.hasOutstandingIOU;
} else {
const reportActionMessage = lodashGet(reportAction, 'message[0].html', '');

// The totalAmount is 0 after Sign in because OpenApp API won't return iouReports if it's paid, so we need to retrieve it from the reportActionMessage
// reportActionMessage is in the format of either "payer@mail.com owes $1.00" or "paid $1.00"
formattedAmount = _.last(reportActionMessage.split(' '));
reportHasOutstandingIOU = Boolean(reportActionMessage.match(/ owes /));
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems very brittle. Can we check for the report action type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, I think we don't really need it if we only use this utils for ReportPreview action type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, this would break if we changed the message, no? I think we should check for action = IOU, type = 'create' instead

Copy link
Contributor Author

@hoangzinh hoangzinh Jun 16, 2023

Choose a reason for hiding this comment

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

sorry @luacmartins we're fixing for ReportPreview action type. so could you explain how action = IOU, type = 'create' can tell us whether the report has outstanding IOU or not? (because action = IOU won't never be true in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah in that case, we should use ReportUtils.isSettled

Copy link
Contributor

Choose a reason for hiding this comment

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

honestly not sure what would be prefered here

Copy link
Member

Choose a reason for hiding this comment

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

cc: @mountiny for thoughts on #20446 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could:

  • parses the message from the iou/ expense report and translate it
  • if the iou report is not found locally then just use the message in English which is in the preview action

That will work for this PR and then we can address if we need to start adding more info to the preview action. we usually dont want any duplication of data in the databse so we would have to think how to solve this the best

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @mountiny

If we agree with above ^. I will try to update this PR during weekend and it will be ready to review again next week 🚀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just in case we all agree with above. Sorry this is first time I work on a task that need some translation. As @luacmartins mentioned above #20446 (comment). BE returns the settled message either "paid {amount} elsewhere" or "paid {amount} using PayPal.me" (before only "paid {amount}") => How can I get those messages in Spain? Thanks

}

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

/**
* Get the title for a report.
*
Expand Down Expand Up @@ -2317,4 +2348,5 @@ export {
getMoneyRequestAction,
getBankAccountRoute,
getParentReport,
getMoneyRequestReportActionMessage,
};
4 changes: 4 additions & 0 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,17 @@ function getOptionData(reportID) {

const login = Str.removeSMSDomain(lodashGet(personalDetail, 'login', ''));
const formattedLogin = Str.isSMSLogin(login) ? LocalePhoneNumber.formatPhoneNumber(login) : login;
const lastReportAction = lastReportActions[report.reportID];

// We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants);

let lastMessageTextFromReport = '';
if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) {
lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`;
} else if (ReportActionsUtils.isReportPreviewAction(lastReportAction)) {
const iouReport = ReportUtils.getReport(ReportActionsUtils.getIOUReportID(lastReportAction));
lastMessageTextFromReport = ReportUtils.getMoneyRequestReportActionMessage(iouReport, lastReportAction);
} else {
lastMessageTextFromReport = report ? report.lastMessageText || '' : '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function ReportActionItem(props) {
} else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) {
children = (
<ReportPreview
iouReportID={props.action.originalMessage.linkedReportID}
iouReportID={ReportActionsUtils.getIOUReportID(props.action)}
chatReportID={props.report.reportID}
action={props.action}
isHovered={hovered}
Expand Down