-
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
fix: Set childReportID of the optimistic IOU report action #37232
Merged
cead22
merged 11 commits into
Expensify:main
from
paultsimura:fix/33114-optimistic-threads
Mar 11, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b6c83c
Set childReportID of the optimistic IOU report action
paultsimura 0d862fb
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura ab66870
Fix unavailable workspace for optimistic thread reports
paultsimura 1b8e9b5
Fix unavailable workspace for optimistic thread reports
paultsimura 47d6411
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura e894c66
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura 1d286ae
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura fd7af59
Unify the logic for building optimistic Money Request entities
paultsimura 0f96b28
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura 72a6325
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura f57d723
Merge branch 'main' into fix/33114-optimistic-threads
paultsimura 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,7 @@ type OptimisticIOUReportAction = Pick< | |
| 'pendingAction' | ||
| 'receipt' | ||
| 'whisperedToAccountIDs' | ||
| 'childReportID' | ||
>; | ||
|
||
type ReportRouteParams = { | ||
|
@@ -3160,7 +3161,6 @@ function getIOUReportActionMessage(iouReportID: string, type: string, total: num | |
* @param [receipt] | ||
* @param [isOwnPolicyExpenseChat] - Whether this is an expense report create from the current user's policy expense chat | ||
*/ | ||
|
||
function buildOptimisticIOUReportAction( | ||
type: ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>, | ||
amount: number, | ||
|
@@ -3925,27 +3925,79 @@ function buildOptimisticTaskReport( | |
* A helper method to create transaction thread | ||
* | ||
* @param reportAction - the parent IOU report action from which to create the thread | ||
* | ||
* @param moneyRequestReportID - the reportID which the report action belong to | ||
* @param moneyRequestReport - the report which the report action belongs to | ||
*/ | ||
function buildTransactionThread(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>, moneyRequestReportID: string): OptimisticChatReport { | ||
function buildTransactionThread(reportAction: OnyxEntry<ReportAction | OptimisticIOUReportAction>, moneyRequestReport: Report): OptimisticChatReport { | ||
const participantAccountIDs = [...new Set([currentUserAccountID, Number(reportAction?.actorAccountID)])].filter(Boolean) as number[]; | ||
return buildOptimisticChatReport( | ||
participantAccountIDs, | ||
getTransactionReportName(reportAction), | ||
undefined, | ||
getReport(moneyRequestReportID)?.policyID ?? CONST.POLICY.OWNER_EMAIL_FAKE, | ||
moneyRequestReport.policyID, | ||
CONST.POLICY.OWNER_ACCOUNT_ID_FAKE, | ||
false, | ||
'', | ||
undefined, | ||
undefined, | ||
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, | ||
reportAction?.reportActionID, | ||
moneyRequestReportID, | ||
moneyRequestReport.reportID, | ||
); | ||
} | ||
|
||
/** | ||
* Build optimistic money request entities: | ||
* | ||
* 1. CREATED action for the iouReport | ||
* 2. IOU action for the iouReport linked to the transaction thread via `childReportID` | ||
* 3. Transaction Thread linked to the IOU action via `parentReportActionID` | ||
* 4. CREATED action for the Transaction Thread | ||
*/ | ||
function buildOptimisticMoneyRequestEntities( | ||
iouReport: Report, | ||
type: ValueOf<typeof CONST.IOU.REPORT_ACTION_TYPE>, | ||
amount: number, | ||
currency: string, | ||
comment: string, | ||
payeeEmail: string, | ||
participants: Participant[], | ||
transactionID: string, | ||
paymentType?: PaymentMethodType, | ||
isSettlingUp = false, | ||
isSendMoneyFlow = false, | ||
receipt: Receipt = {}, | ||
isOwnPolicyExpenseChat = false, | ||
): [OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction] { | ||
const iouActionCreationTime = DateUtils.getDBTime(); | ||
|
||
// The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat. | ||
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. 💚 great comment |
||
const createdActionForIOUReport = buildOptimisticCreatedReportAction(payeeEmail, DateUtils.subtractMillisecondsFromDateTime(iouActionCreationTime, 1)); | ||
const iouAction = buildOptimisticIOUReportAction( | ||
type, | ||
amount, | ||
currency, | ||
comment, | ||
participants, | ||
transactionID, | ||
paymentType, | ||
iouReport.reportID, | ||
isSettlingUp, | ||
isSendMoneyFlow, | ||
receipt, | ||
isOwnPolicyExpenseChat, | ||
iouActionCreationTime, | ||
); | ||
|
||
// Create optimistic transactionThread and the `CREATED` action for it | ||
const transactionThread = buildTransactionThread(iouAction, iouReport); | ||
const createdActionForTransactionThread = buildOptimisticCreatedReportAction(payeeEmail); | ||
|
||
// The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together | ||
iouAction.childReportID = transactionThread.reportID; | ||
|
||
return [createdActionForIOUReport, iouAction, transactionThread, createdActionForTransactionThread]; | ||
} | ||
|
||
function isUnread(report: OnyxEntry<Report>): boolean { | ||
if (!report) { | ||
return false; | ||
|
@@ -5279,6 +5331,7 @@ export { | |
buildOptimisticSubmittedReportAction, | ||
buildOptimisticExpenseReport, | ||
buildOptimisticIOUReportAction, | ||
buildOptimisticMoneyRequestEntities, | ||
buildOptimisticReportPreview, | ||
buildOptimisticModifiedExpenseReportAction, | ||
buildOptimisticCancelPaymentReportAction, | ||
|
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
Oops, something went wrong.
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.
Are we removing this because we're always creating transaction threads in the backend, and
action?.childReportID
will be set to the ID of that transaction thread?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.
Yes. We've discussed it briefly here: #37232 (comment)