Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ function ReportPreview(props) {
const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3);
const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction));
let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null;
if (TransactionUtils.isPartialMerchant(formattedMerchant)) {
formattedMerchant = null;
}
const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null));
if (hasPendingWaypoints) {
formattedMerchant = formattedMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd'));
Expand Down Expand Up @@ -305,7 +308,7 @@ function ReportPreview(props) {
)}
</View>
</View>
{!isScanning && (numberOfRequests > 1 || hasReceipts) && (
{!isScanning && (numberOfRequests > 1 || (hasReceipts && numberOfRequests === 1 && formattedMerchant)) && (
<View style={styles.flexRow}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.textLabelSupporting, styles.textNormal, styles.mb1, styles.lh20]}>{previewSubtitle || moneyRequestComment}</Text>
Expand Down
8 changes: 8 additions & 0 deletions src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ function isMerchantMissing(transaction: Transaction) {
return isMerchantEmpty && isModifiedMerchantEmpty;
}

/**
* Check if the merchant is partial i.e. `(none)`
*/
function isPartialMerchant(merchant: string): boolean {

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.

Mobile now but is there really no method like this yet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not yet. What we do though everywhere is to use the equality operator and check for partial merchant text.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mountiny in a follow-up, I could send a PR that replaces all usages with this function.
I'm on the fence if we really need a function for an equality check. but ok

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm on the fence if we really need a function for an equality check

I had thought about this, but a helper method seemed better from the perspective of code readability. Further, having a central place to handle partial merchant text seems better if any additional text needs to be considered as partial merchant text.
And I like the idea of replacing the existing usage with this method. We may also want to add a helper method for isEmptyMerchant that is duplicated in three places. A follow-up refactor PR seems a good idea.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you! will create one after this

return merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
}

function isAmountMissing(transaction: Transaction) {
return transaction.amount === 0 && (!transaction.modifiedAmount || transaction.modifiedAmount === 0);
}
Expand Down Expand Up @@ -573,6 +580,7 @@ export {
getWaypoints,
isAmountMissing,
isMerchantMissing,
isPartialMerchant,
isCreatedMissing,
areRequiredFieldsEmpty,
hasMissingSmartscanFields,
Expand Down