-
Notifications
You must be signed in to change notification settings - Fork 4k
Update all reports which have updated totals #71683
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
06c656b
Update all reports which have updated totals
ShridharGoel 9fd6a0c
Improve logic to handle Onyx data in a better way + test updates
ShridharGoel cef9ca7
Lint fixes
ShridharGoel 771e085
Lint fixes
ShridharGoel 52d2442
Pass ONYXKEYS.COLLECTION.NEXT_STEP data via components
ShridharGoel 6941744
Merge
ShridharGoel 05b6f56
Small fixes
ShridharGoel 0eaea12
Merge branch 'main' into nextSteps
ShridharGoel d3ef6df
Merge main
ShridharGoel 4776735
Merge branch 'nextSteps' of https://github.com/ShridharGoel/Expensify…
ShridharGoel 41ac480
Merge main
ShridharGoel 7365d3d
Update to remove extra condition
ShridharGoel e921fcf
Merge main
ShridharGoel c071505
Merge branch 'main' of https://github.com/Expensify/App into nextSteps
ShridharGoel e331c8f
Improve logic and handle approval scenario
ShridharGoel 3f3990f
Merge main
ShridharGoel f3656cb
Update tests
ShridharGoel 4e19411
Lint and type fixes
ShridharGoel a995cd0
Fix
ShridharGoel 1383ec6
Merge branch 'main' into nextSteps
ShridharGoel ecc0401
Merge main
ShridharGoel d6966f7
Merge main
ShridharGoel d3239fc
Update tests
ShridharGoel 469804a
Merge main
ShridharGoel df6bfb3
Use buildNextStepNew
ShridharGoel bf8cb1a
Merge branch 'main' of https://github.com/Expensify/App into nextSteps
ShridharGoel 06c841c
Merge main
ShridharGoel 2bb5b67
Update to use cleaner logic and follow backend behaviour
ShridharGoel 83cdbf9
Update to use cleaner logic and follow backend behaviour
ShridharGoel 306b997
Prettier fix
ShridharGoel 467adee
Lint fix
ShridharGoel 2cefc3e
Merge main
ShridharGoel 0732012
Improve logic and add new test
ShridharGoel 43d55a4
Merge branch 'main' into nextSteps
ShridharGoel 97aa338
Lint fixes
ShridharGoel 538bc88
Fix issue
ShridharGoel 3d1afe8
Lint fixes
ShridharGoel 28db791
Fix test
ShridharGoel 2038f2f
Lint fixes
ShridharGoel 6bc42a1
Fix test
ShridharGoel 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 hidden or 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 |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ | |
| import {getCurrentUserAccountID} from './Report'; | ||
|
|
||
| const allTransactions: Record<string, Transaction> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION, | ||
| callback: (transaction, key) => { | ||
| if (!key || !transaction) { | ||
|
|
@@ -65,7 +65,7 @@ | |
| }); | ||
|
|
||
| let allTransactionDrafts: OnyxCollection<Transaction> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -74,7 +74,7 @@ | |
| }); | ||
|
|
||
| let allReports: OnyxCollection<Report> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.REPORT, | ||
| waitForCollectionCallback: true, | ||
| callback: (value) => { | ||
|
|
@@ -86,7 +86,7 @@ | |
| }); | ||
|
|
||
| const allTransactionViolation: OnyxCollection<TransactionViolation[]> = {}; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
| callback: (transactionViolation, key) => { | ||
| if (!key || !transactionViolation) { | ||
|
|
@@ -98,7 +98,7 @@ | |
| }); | ||
|
|
||
| let allTransactionViolations: TransactionViolations = []; | ||
| Onyx.connect({ | ||
| key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, | ||
| callback: (val) => (allTransactionViolations = val ?? []), | ||
| }); | ||
|
|
@@ -1294,83 +1294,106 @@ | |
| } | ||
| } | ||
|
|
||
| // 9. Update next step for report | ||
| // 9. Update next steps for all affected reports | ||
| const destinationReportID = reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? (existingSelfDMReportID ?? selfDMReport?.reportID) : reportID; | ||
| const destinationReport = destinationReportID | ||
| ? (allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${destinationReportID}`] ?? | ||
| (destinationReportID === newReport?.reportID ? newReport : undefined) ?? | ||
| (destinationReportID === selfDMReport?.reportID ? selfDMReport : undefined)) | ||
| : undefined; | ||
| const destinationTotal = (destinationReportID ? updatedReportTotals[destinationReportID] : undefined) ?? destinationReport?.total ?? newReport?.total; | ||
| const nextStepReport = { | ||
| ...destinationReport, | ||
| reportID: destinationReport?.reportID ?? destinationReportID ?? reportID, | ||
| total: destinationTotal, | ||
| }; | ||
| const hasViolations = hasViolationsReportUtils(nextStepReport?.reportID, allTransactionViolation, accountID, email ?? ''); | ||
|
|
||
| // buildOptimisticNextStep is used in parallel | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| const optimisticNextStepDeprecated = buildNextStepNew({ | ||
| report: nextStepReport, | ||
| policy, | ||
| currentUserAccountIDParam: accountID, | ||
| currentUserEmailParam: email, | ||
| hasViolations, | ||
| isASAPSubmitBetaEnabled, | ||
| predictedNextStatus: nextStepReport.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN, | ||
| shouldFixViolations, | ||
| }); | ||
| const optimisticNextStep = buildOptimisticNextStep({ | ||
| report: nextStepReport, | ||
| policy, | ||
| currentUserAccountIDParam: accountID, | ||
| currentUserEmailParam: email, | ||
| hasViolations, | ||
| isASAPSubmitBetaEnabled, | ||
| predictedNextStatus: nextStepReport.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN, | ||
| shouldFixViolations, | ||
| }); | ||
| optimisticData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, | ||
| value: optimisticNextStepDeprecated, | ||
| }); | ||
| optimisticData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| nextStep: optimisticNextStep, | ||
| pendingFields: { | ||
| nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, | ||
| const affectedReportIDs = new Set<string>(); | ||
|
|
||
| for (const reportIDToUpdate of Object.keys(updatedReportTotals)) { | ||
| affectedReportIDs.add(reportIDToUpdate); | ||
| } | ||
|
|
||
| if (destinationReportID) { | ||
| affectedReportIDs.add(destinationReportID); | ||
| } | ||
|
|
||
| for (const affectedReportID of affectedReportIDs) { | ||
| const affectedReport = | ||
| allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${affectedReportID}`] ?? | ||
| (affectedReportID === newReport?.reportID ? newReport : undefined) ?? | ||
| (affectedReportID === selfDMReport?.reportID ? selfDMReport : undefined); | ||
|
|
||
| if (!affectedReport) { | ||
| return; | ||
| } | ||
|
Comment on lines
+1315
to
+1317
Member
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. I didn't understand this change. Why are we creating this? What does it give us? If we do not have the report data, we shouldn't update this report. |
||
|
|
||
| const updatedTotal = updatedReportTotals[affectedReportID] ?? affectedReport.total; | ||
| const updatedReport = { | ||
| ...affectedReport, | ||
| total: updatedTotal, | ||
| reportID: affectedReport.reportID ?? affectedReportID, | ||
| }; | ||
|
|
||
| const predictedNextStatus = updatedReport.statusNum ?? CONST.REPORT.STATUS_NUM.OPEN; | ||
|
|
||
| const hasViolations = hasViolationsReportUtils(updatedReport.reportID, allTransactionViolation, accountID, email ?? ''); | ||
| const isDestinationReport = affectedReportID === destinationReportID; | ||
| const shouldFixViolationsForReport = isDestinationReport ? shouldFixViolations : false; | ||
| const shouldUseUnreportedNextStepKey = reportID === CONST.REPORT.UNREPORTED_REPORT_ID && isDestinationReport; | ||
| const nextStepOnyxReportID = shouldUseUnreportedNextStepKey ? reportID : affectedReportID; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| const optimisticNextStepForCollection = buildNextStepNew({ | ||
| report: updatedReport, | ||
| policy, | ||
| currentUserAccountIDParam: accountID, | ||
| currentUserEmailParam: email, | ||
| hasViolations, | ||
| isASAPSubmitBetaEnabled, | ||
| predictedNextStatus, | ||
| shouldFixViolations: shouldFixViolationsForReport, | ||
| }); | ||
| const optimisticNextStepForReport = buildOptimisticNextStep({ | ||
| report: updatedReport, | ||
| policy, | ||
| currentUserAccountIDParam: accountID, | ||
| currentUserEmailParam: email, | ||
| hasViolations, | ||
| isASAPSubmitBetaEnabled, | ||
| predictedNextStatus, | ||
| shouldFixViolations: shouldFixViolationsForReport, | ||
| }); | ||
|
|
||
| optimisticData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${nextStepOnyxReportID}`, | ||
| value: optimisticNextStepForCollection, | ||
| }); | ||
| optimisticData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${affectedReportID}`, | ||
| value: { | ||
| nextStep: optimisticNextStepForReport, | ||
| pendingFields: { | ||
| nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| successData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| pendingFields: { | ||
| nextStep: null, | ||
| }); | ||
| successData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${affectedReportID}`, | ||
| value: { | ||
| pendingFields: { | ||
| nextStep: null, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 | ||
| failureData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, | ||
| value: reportNextStep, | ||
| }); | ||
| failureData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
| value: { | ||
| nextStep: nextStepReport.nextStep ?? null, | ||
| pendingFields: { | ||
| nextStep: null, | ||
| }); | ||
| // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 | ||
| failureData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${nextStepOnyxReportID}`, | ||
| value: nextStepOnyxReportID === reportID ? reportNextStep : (affectedReport.nextStep ?? null), | ||
| }); | ||
| failureData.push({ | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: `${ONYXKEYS.COLLECTION.REPORT}${affectedReportID}`, | ||
| value: { | ||
| nextStep: affectedReport.nextStep ?? null, | ||
| pendingFields: { | ||
| nextStep: null, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| const parameters: ChangeTransactionsReportParams = { | ||
| transactionList: transactionIDs.join(','), | ||
|
|
||
This file contains hidden or 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.
This part was a little different. I do not know the exact reason why we have fallbacks for
reportIDkey anddestinationtotal. Is there a reason why you changed this?To be safe, I would like to keep the logic same for destination report unless we have reason that we don't need to fallbacks.
To be clear.
You are not not falling back to
reportIDas indestinationReport?.reportID ?? destinationReportID ?? reportID,Here we were falling back to
newReport?.totalbut not in new code.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.
@ShridharGoel
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.
We already have the real report in hand before we set next steps, so we don’t need extra fallbacks. Bringing them back wouldn’t help, and could point updates to the wrong report (for example, using the outer reportID instead of
the source report ID). The total fallback also seems unnecessary because when the report is the new one, we already have its total.
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.
Do let me know what you think.
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.
OK, sounds good.