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

fix: fix lhn previews #31061

Merged
10 changes: 5 additions & 5 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,19 +557,19 @@ export default {
splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`,
didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `split ${formattedAmount}${comment ? ` for ${comment}` : ''}`,
amountEach: ({amount}: AmountEachParams) => `${amount} each`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} owes ${amount}`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer ? `${payer} ` : ''}owes ${amount}`,
payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} paid ${amount}`,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer ? `${payer} ` : ''}paid ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} paid: `,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} spent ${amount}`,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer ? `${payer} ` : ''}spent ${amount}`,
payerSpent: ({payer}: PayerPaidParams) => `${payer} spent: `,
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} approved:`,
payerSettled: ({amount}: PayerSettledParams) => `paid ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up, payment is held until ${submitterDisplayName} adds a bank account`,
settledAfterAddedBankAccount: ({submitterDisplayName, amount}: SettledAfterAddedBankAccountParams) =>
`${submitterDisplayName} added a bank account. The ${amount} payment has been made.`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer} paid ${amount} elsewhere`,
paidWithExpensifyWithAmount: ({payer, amount}: PaidWithExpensifyWithAmountParams) => `${payer} paid ${amount} using Expensify`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer ? `${payer} ` : ''}paid ${amount} elsewhere`,
paidWithExpensifyWithAmount: ({payer, amount}: PaidWithExpensifyWithAmountParams) => `${payer ? `${payer} ` : ''}paid ${amount} using Expensify`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
changedTheRequest: 'changed the request',
Expand Down
10 changes: 5 additions & 5 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,19 +549,19 @@ export default {
splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`,
didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
amountEach: ({amount}: AmountEachParams) => `${amount} cada uno`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} debe ${amount}`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer ? `${payer} ` : ''}debe ${amount}`,
payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams) => `${payer} pagó ${amount}`,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams) => `${payer ? `${payer} ` : ''}pagó ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} pagó: `,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer} gastó ${amount}`,
payerSpentAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer ? `${payer} ` : ''}gastó ${amount}`,
payerSpent: ({payer}: PayerPaidParams) => `${payer} gastó: `,
managerApproved: ({manager}: ManagerApprovedParams) => `${manager} aprobó:`,
payerSettled: ({amount}: PayerSettledParams) => `pagó ${amount}`,
waitingOnBankAccount: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inicio el pago, pero no se procesará hasta que ${submitterDisplayName} añada una cuenta bancaria`,
settledAfterAddedBankAccount: ({submitterDisplayName, amount}: SettledAfterAddedBankAccountParams) =>
`${submitterDisplayName} añadió una cuenta bancaria. El pago de ${amount} se ha realizado.`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer} pagó ${amount} de otra forma`,
paidWithExpensifyWithAmount: ({payer, amount}: PaidWithExpensifyWithAmountParams) => `${payer} pagó ${amount} con Expensify`,
paidElsewhereWithAmount: ({payer, amount}: PaidElsewhereWithAmountParams) => `${payer ? `${payer} ` : ''}pagó ${amount} de otra forma`,
paidWithExpensifyWithAmount: ({payer, amount}: PaidWithExpensifyWithAmountParams) => `${payer ? `${payer} ` : ''}pagó ${amount} con Expensify`,
noReimbursableExpenses: 'El importe de este informe no es válido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
changedTheRequest: 'cambió la solicitud',
Expand Down
44 changes: 41 additions & 3 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from 'underscore';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import * as CollectionUtils from './CollectionUtils';
import * as CurrencyUtils from './CurrencyUtils';
import * as ErrorUtils from './ErrorUtils';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
Expand Down Expand Up @@ -372,6 +373,40 @@ function getAllReportErrors(report, reportActions) {
return allReportErrors;
}

/**
* Get the preview message to be displayed in the option list.
* @param {Object} report
* @param {Object} reportAction
* @param {Boolean} isPreviewMessageForParentChatReport
* @returns {String}
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

function getReportPreviewMessageForOptionList(report, reportAction, isPreviewMessageForParentChatReport = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@luacmartins I think we can just set default value here:

Suggested change
function getReportPreviewMessageForOptionList(report, reportAction, isPreviewMessageForParentChatReport = false) {
function getReportPreviewMessageForOptionList(report, reportAction = {}, isPreviewMessageForParentChatReport = false) {

This was old code: https://github.com/Expensify/App/pull/31061/files#diff-65c096044d5f69b35bcdec14c99c4fda4580759df9b1a7c36650d58eea276f1dR1861

Copy link
Contributor

Choose a reason for hiding this comment

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

that will prevent the crash, yes, but why don't we have any reportActions for the given report? When I load the given report I do see reportActions

Copy link
Contributor

Choose a reason for hiding this comment

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

it may be that the reportActions are only missing for a brief moment while loading/updating onyx

// for the request action preview we want to show the requestor instead of the user who owes the money
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// for the request action preview we want to show the requestor instead of the user who owes the money
// For the request action preview we want to show the requestor instead of the user who owes the money

if (!isPreviewMessageForParentChatReport && reportAction.originalMessage && reportAction.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE) {
const amount = Math.abs(reportAction.originalMessage.amount);
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, report.currency);
const shouldShowActorName = currentUserAccountID !== reportAction.actorAccountID;
const actorDisplayName = shouldShowActorName ? `${ReportUtils.getDisplayNameForParticipant(reportAction.actorAccountID, true)}: ` : '';

return `${actorDisplayName}${Localize.translateLocal('iou.requestedAmount', {formattedAmount})}`;
}

const shouldShowWorkspaceName = ReportUtils.isExpenseReport(report) && isPreviewMessageForParentChatReport;
const actorID = report.managerID || reportAction.actorAccountID;
const actor = ReportUtils.getActorNameForPreviewMessage({
report,
shouldShowWorkspaceName,
actorID,
shouldUseShortForm: !isPreviewMessageForParentChatReport,
});
const shouldShowActorName = shouldShowWorkspaceName || isPreviewMessageForParentChatReport || currentUserAccountID !== actorID;
const actorDisplayName = shouldShowActorName && actor ? `${actor}${isPreviewMessageForParentChatReport ? ' ' : ': '}` : '';
const message = ReportUtils.getReportPreviewMessage(report, reportAction, true, isPreviewMessageForParentChatReport, true);

return `${actorDisplayName}${message}`;
}

/**
* Get the last message text from the report directly or from other sources for special cases.
* @param {Object} report
Expand All @@ -386,7 +421,7 @@ function getLastMessageTextForReport(report) {
const lastActionName = lodashGet(lastReportAction, 'actionName', '');

if (ReportActionUtils.isMoneyRequestAction(lastReportAction)) {
const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true);
const properSchemaForMoneyRequestMessage = getReportPreviewMessageForOptionList(report, lastReportAction, false);
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage);
} else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) {
const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));
Expand All @@ -397,7 +432,7 @@ function getLastMessageTextForReport(report) {
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
ReportActionUtils.isMoneyRequestAction(reportAction),
);
lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true, ReportUtils.isChatReport(report));
lastMessageTextFromReport = getReportPreviewMessageForOptionList(iouReport, lastIOUMoneyReport, ReportUtils.isChatReport(report));
} else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) {
lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report);
} else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) {
Expand All @@ -414,7 +449,10 @@ function getLastMessageTextForReport(report) {
) {
lastMessageTextFromReport = lodashGet(lastReportAction, 'message[0].text', '');
} else {
lastMessageTextFromReport = report ? report.lastMessageText || '' : '';
const shouldShowLastActor =
ReportUtils.isThread(report) && (ReportUtils.isExpenseReport(report) || ReportUtils.isIOUReport(report)) && currentUserAccountID !== report.lastActorAccountID;
const lastActorDisplayName = shouldShowLastActor ? `${ReportUtils.getDisplayNameForParticipant(report.lastActorAccountID, true)}: ` : '';
lastMessageTextFromReport = report ? `${lastActorDisplayName}${report.lastMessageText}` : '';

// Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove
// then set the last message text to the text of the latest visible action that is not a whisper or the report creation message.
Expand Down
39 changes: 35 additions & 4 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,16 +1785,31 @@ function getTransactionReportName(reportAction) {
});
}

/**
* Get actor name to display in the message preview
*
* @param {Object} report
* @param {Number} actorID
* @param {Boolean} shouldShowWorkspaceName
* @param {Boolean} shouldUseShortForm
* @returns {String}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @returns {String}
* @returns {String}

*/

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

function getActorNameForPreviewMessage({report, actorID, shouldShowWorkspaceName = false, shouldUseShortForm = false}) {
return shouldShowWorkspaceName ? getPolicyName(report) : getDisplayNameForParticipant(actorID, shouldUseShortForm);
}

/**
* Get money request message for an IOU report
*
* @param {Object} report
* @param {Object} [reportAction={}] This can be either a report preview action or the IOU action
* @param {Boolean} [shouldConsiderReceiptBeingScanned=false]
* @param {Boolean} isPreviewMessageForParentChatReport
* @param {Boolean} shouldHideParticipantName
* @returns {String}
*/
function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isPreviewMessageForParentChatReport = false) {
function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceiptBeingScanned = false, isPreviewMessageForParentChatReport = false, shouldHideParticipantName = false) {
const reportActionMessage = lodashGet(reportAction, 'message[0].html', '');

if (_.isEmpty(report) || !report.reportID) {
Expand All @@ -1818,7 +1833,13 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip
}

const totalAmount = getMoneyRequestReimbursableTotal(report);
const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerID, true);
const payerDisplayName = getActorNameForPreviewMessage({
report,
actorID: report.managerID,
shouldUseShortForm: true,
shouldShowWorkspaceName: isExpenseReport(report),
});
const payerName = shouldHideParticipantName ? '' : payerDisplayName;
const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency);

if (isReportApproved(report) && getPolicyType(report, allPolicies) === CONST.POLICY.TYPE.CORPORATE) {
Expand Down Expand Up @@ -1877,7 +1898,11 @@ function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName,
if (!newValue) {
return Localize.translateLocal('iou.removedTheRequest', {valueName: displayValueName, oldValueToDisplay});
}
return Localize.translateLocal('iou.updatedTheRequest', {valueName: displayValueName, newValueToDisplay, oldValueToDisplay});
return Localize.translateLocal('iou.updatedTheRequest', {
valueName: displayValueName,
newValueToDisplay,
oldValueToDisplay,
});
}

/**
Expand All @@ -1892,7 +1917,10 @@ function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName,

function getProperSchemaForModifiedDistanceMessage(newDistance, oldDistance, newAmount, oldAmount) {
if (!oldDistance) {
return Localize.translateLocal('iou.setTheDistance', {newDistanceToDisplay: newDistance, newAmountToDisplay: newAmount});
return Localize.translateLocal('iou.setTheDistance', {
newDistanceToDisplay: newDistance,
newAmountToDisplay: newAmount,
});
}
return Localize.translateLocal('iou.updatedTheDistance', {
newDistanceToDisplay: newDistance,
Expand Down Expand Up @@ -2629,6 +2657,7 @@ function buildOptimisticIOUReportAction(
whisperedToAccountIDs: _.contains([CONST.IOU.RECEIPT_STATE.SCANREADY, CONST.IOU.RECEIPT_STATE.SCANNING], receipt.state) ? [currentUserAccountID] : [],
};
}

/**
* Builds an optimistic APPROVED report action with a randomly generated reportActionID.
*
Expand Down Expand Up @@ -3267,6 +3296,7 @@ function canAccessReport(report, policies, betas, allReportActions) {

return true;
}

/**
* Check if the report is the parent report of the currently viewed report or at least one child report has report action
* @param {Object} report
Expand Down Expand Up @@ -4338,4 +4368,5 @@ export {
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getRoom,
getActorNameForPreviewMessage,
};