-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Migrate reportAction.originalMessage to transactions #24345
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
2d0469d
create getTransaction
luacmartins 6c8ca4c
add jsdocs
luacmartins ad95fb0
refactor getFormattedAmount
luacmartins f5b5a01
update logic and rename to getMoneyRequestDetails
luacmartins 12fbdd7
replace usages of getMoneyRequestAction
luacmartins f595a75
replace missed instance
luacmartins ad49161
refactor logic to retrieve transaction
luacmartins 4bcd072
refactor SplitBillDetailsPage
luacmartins a1448ff
refactor getIOUReportActions
luacmartins 10dcaf2
refactor MoneyRequestAction
luacmartins acb4efb
refactor getTransactionReportName
luacmartins a6fd68a
fix comment bugs
luacmartins e067001
export getTransactionReportName
luacmartins b2f4406
update split case
luacmartins 8969b05
add transaction default
luacmartins 2fc39f2
Merge branch 'main' into cmartins-replaceOriginalMessage
luacmartins 00f61c2
rename method to getLinkedTransaction
luacmartins 29ed60b
add getAllReportTransactions
luacmartins d4cf7ef
resolve conflicts
luacmartins e7c2cac
fix style
luacmartins e910c83
resolve conflicts
luacmartins b6b9a8b
rm unused component
luacmartins 523d61b
use transactionUtils methods
luacmartins 901370e
rm getMoneyRequestDetails
luacmartins b31a098
refactor SplitBillDetailsPage
luacmartins e0f37f6
rm unused import
luacmartins cd0e7e4
update getTransactionReportName
luacmartins 94cba00
rm unused import
luacmartins 7bfd673
add default currency
luacmartins 7629ba0
use parentReport for transaction thread
luacmartins ba3b7df
rm getAllReportTransactions
luacmartins 946b907
rm allTransactions
luacmartins 63c8695
add getTransactionDetails
luacmartins 4930a80
refactor usages of transactionutils
luacmartins a1aef03
fix style
luacmartins e9b05e2
move getLinkedTransaction to TransactionUtils;
luacmartins 5356802
update comments
luacmartins 7c72468
create getAllReportTransactions, refactor isIOUReportPendingCurrencyC…
luacmartins c70f193
fix tests
luacmartins 98dc4a0
fix styles
luacmartins bc9413f
Merge branch 'main' into cmartins-replaceOriginalMessage
luacmartins 079a0e8
rm getIOUReportActions
luacmartins 66b0fac
rm unused import
luacmartins d7c8910
fix editMoneyRequest params
luacmartins 88b2b64
use getCreated
luacmartins add8d3c
update date default
luacmartins b629521
use onyx set
luacmartins fa20e6b
resolve conflicts
luacmartins 356ea9b
resolve conflicts
luacmartins 4d90f2c
use getters
luacmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1094,32 +1094,6 @@ function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantR | |
}); | ||
} | ||
|
||
/** | ||
* We get the amount, currency and comment money request value from the action.originalMessage. | ||
* But for the send money action, the above value is put in the IOUDetails object. | ||
* | ||
* @param {Object} reportAction | ||
* @param {Number} reportAction.amount | ||
* @param {String} reportAction.currency | ||
* @param {String} reportAction.comment | ||
* @param {Object} [reportAction.IOUDetails] | ||
* @returns {Object} | ||
*/ | ||
function getMoneyRequestAction(reportAction = {}) { | ||
const originalMessage = lodashGet(reportAction, 'originalMessage', {}); | ||
let amount = originalMessage.amount || 0; | ||
let currency = originalMessage.currency || CONST.CURRENCY.USD; | ||
let comment = originalMessage.comment || ''; | ||
|
||
if (_.has(originalMessage, 'IOUDetails')) { | ||
amount = lodashGet(originalMessage, 'IOUDetails.amount', 0); | ||
currency = lodashGet(originalMessage, 'IOUDetails.currency', CONST.CURRENCY.USD); | ||
comment = lodashGet(originalMessage, 'IOUDetails.comment', ''); | ||
} | ||
|
||
return {amount, currency, comment}; | ||
} | ||
|
||
/** | ||
* Determines if a report has an IOU that is waiting for an action from the current user (either Pay or Add a credit bank account) | ||
* | ||
|
@@ -1229,6 +1203,32 @@ function getMoneyRequestReportName(report, policy = undefined) { | |
return payerPaidAmountMesssage; | ||
} | ||
|
||
/** | ||
* Get the report given a reportID | ||
* | ||
* @param {String} reportID | ||
* @returns {Object} | ||
*/ | ||
function getReport(reportID) { | ||
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); | ||
} | ||
|
||
/** | ||
* Gets transaction created, amount, currency and comment | ||
* | ||
* @param {Object} transaction | ||
* @returns {Object} | ||
*/ | ||
function getTransactionDetails(transaction) { | ||
const report = getReport(transaction.reportID); | ||
return { | ||
created: TransactionUtils.getCreated(transaction), | ||
amount: TransactionUtils.getAmount(transaction, isExpenseReport(report)), | ||
currency: TransactionUtils.getCurrency(transaction), | ||
comment: TransactionUtils.getDescription(transaction), | ||
}; | ||
} | ||
|
||
/** | ||
* Given a parent IOU report action get report name for the LHN. | ||
* | ||
|
@@ -1240,9 +1240,12 @@ function getTransactionReportName(reportAction) { | |
return Localize.translateLocal('parentReportAction.deletedRequest'); | ||
} | ||
|
||
const transaction = TransactionUtils.getLinkedTransaction(reportAction); | ||
const {amount, currency, comment} = getTransactionDetails(transaction); | ||
|
||
return Localize.translateLocal(ReportActionsUtils.isSentMoneyReportAction(reportAction) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', { | ||
formattedAmount: ReportActionsUtils.getFormattedAmount(reportAction), | ||
comment: lodashGet(reportAction, 'originalMessage.comment'), | ||
formattedAmount: CurrencyUtils.convertToDisplayString(amount, currency), | ||
comment, | ||
}); | ||
} | ||
|
||
|
@@ -1368,6 +1371,19 @@ function getModifiedExpenseOriginalMessage(oldTransaction, transactionChanges, i | |
return originalMessage; | ||
} | ||
|
||
/** | ||
* Returns the parentReport if the given report is a thread. | ||
* | ||
* @param {Object} report | ||
* @returns {Object} | ||
*/ | ||
function getParentReport(report) { | ||
if (!report || !report.parentReportID) { | ||
return {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, {}); | ||
} | ||
|
||
/** | ||
* Get the title for a report. | ||
* | ||
|
@@ -1497,16 +1513,6 @@ function getParentNavigationSubtitle(report) { | |
return {}; | ||
} | ||
|
||
/** | ||
* Get the report for a reportID | ||
* | ||
* @param {String} reportID | ||
* @returns {Object} | ||
*/ | ||
function getReport(reportID) { | ||
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); | ||
} | ||
|
||
/** | ||
* Navigate to the details page of a given report | ||
* | ||
|
@@ -2904,19 +2910,6 @@ function isReportDataReady() { | |
return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); | ||
} | ||
|
||
/** | ||
* Returns the parentReport if the given report is a thread. | ||
* | ||
* @param {Object} report | ||
* @returns {Object} | ||
*/ | ||
function getParentReport(report) { | ||
if (!report || !report.parentReportID) { | ||
return {}; | ||
} | ||
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`, {}); | ||
} | ||
|
||
/** | ||
* Find the parent report action in assignee report for a task report | ||
* Returns an empty object if assignee report is the same as the share destination report | ||
|
@@ -3248,7 +3241,6 @@ export { | |
isReportDataReady, | ||
isSettled, | ||
isAllowedToComment, | ||
getMoneyRequestAction, | ||
getBankAccountRoute, | ||
getParentReport, | ||
getTaskParentReportActionIDInAssigneeReport, | ||
|
@@ -3264,5 +3256,7 @@ export { | |
shouldDisableSettings, | ||
shouldDisableRename, | ||
hasSingleParticipant, | ||
getTransactionReportName, | ||
getTransactionDetails, | ||
getTaskAssigneeChatOnyxData, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we returning {} for missing reports? 😬 wouldn't
null
orundefined
be better in these cases?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is much more intuitive for me to check if a report is missing with
report === null
thanObject.keys(report) === 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see that you just moved around this function and it was already like that 😿 , feel free to ignore me