Repository navigation
Refactor fetchIOUReportByID #13556
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
Refactor fetchIOUReportByID #13556
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2be5d34
rename fetchIOUReportByID to openIOUPreview
luacmartins 3c60858
rm setLocalIOUReportData
luacmartins f7bd614
rm unused imports
luacmartins dc49401
rm fetchIOUReport
luacmartins 78ebc79
convert ioupreview to class component
luacmartins a945e87
rm export of getSimplifiedIOUReport
luacmartins 934749e
rm openIOUPreview
luacmartins a263501
revert class component
luacmartins 8081c50
rm iouReportID prop
luacmartins e8a0e51
rm isLoadingReport
luacmartins dca62bd
rm unused import
luacmartins 25660d0
revert prop removal and suppress lint error
luacmartins 4ba1852
rm unused iou prop
luacmartins 2623480
resolve conflicts
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 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
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 |
|---|---|---|
|
|
@@ -12,15 +12,12 @@ import Navigation from '../Navigation/Navigation'; | |
| import * as ActiveClientManager from '../ActiveClientManager'; | ||
| import Visibility from '../Visibility'; | ||
| import ROUTES from '../../ROUTES'; | ||
| import * as DeprecatedAPI from '../deprecatedAPI'; | ||
| import * as API from '../API'; | ||
| import CONFIG from '../../CONFIG'; | ||
| import CONST from '../../CONST'; | ||
| import Log from '../Log'; | ||
| import * as LoginUtils from '../LoginUtils'; | ||
| import * as ReportUtils from '../ReportUtils'; | ||
| import Growl from '../Growl'; | ||
| import * as Localize from '../Localize'; | ||
| import DateUtils from '../DateUtils'; | ||
| import * as ReportActionsUtils from '../ReportActionsUtils'; | ||
| import * as OptionsListUtils from '../OptionsListUtils'; | ||
|
|
@@ -181,76 +178,6 @@ function getSimplifiedIOUReport(reportData, chatReportID) { | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Given IOU and chat report ID fetches most recent IOU data from DeprecatedAPI. | ||
| * | ||
| * @param {Number} iouReportID | ||
| * @param {Number} chatReportID | ||
| * @returns {Promise} | ||
| */ | ||
| function fetchIOUReport(iouReportID, chatReportID) { | ||
| return DeprecatedAPI.Get({ | ||
| returnValueList: 'reportStuff', | ||
| reportIDList: iouReportID, | ||
| shouldLoadOptionalKeys: true, | ||
| includePinnedReports: true, | ||
| }).then((response) => { | ||
| if (!response) { | ||
| return; | ||
| } | ||
| if (response.jsonCode !== 200) { | ||
| console.error(response.message); | ||
| return; | ||
| } | ||
| const iouReportData = response.reports[iouReportID]; | ||
| if (!iouReportData) { | ||
| // IOU data for a report will be missing when the IOU report has already been paid. | ||
| // This is expected and we return early as no further processing can be done. | ||
| return; | ||
| } | ||
| return getSimplifiedIOUReport(iouReportData, chatReportID); | ||
|
Contributor
Author
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. This is still used in syncChatAndIOUReports. We can remove it once
Contributor
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. 🎉 |
||
| }).catch((error) => { | ||
| Log.hmmm('[Report] Failed to populate IOU Collection:', error.message); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Given IOU object, save the data to Onyx. | ||
| * | ||
| * @param {Object} iouReportObject | ||
| * @param {Number} iouReportObject.stateNum | ||
| * @param {Number} iouReportObject.total | ||
| * @param {Number} iouReportObject.reportID | ||
| */ | ||
| function setLocalIOUReportData(iouReportObject) { | ||
| const iouReportKey = `${ONYXKEYS.COLLECTION.REPORT}${iouReportObject.reportID}`; | ||
| Onyx.merge(iouReportKey, iouReportObject); | ||
| } | ||
|
|
||
| /** | ||
| * Fetch the iouReport and persist the data to Onyx. | ||
| * | ||
| * @param {Number} iouReportID - ID of the report we are fetching | ||
| * @param {Number} chatReportID - associated chatReportID, set as an iouReport field | ||
| * @param {Boolean} [shouldRedirectIfEmpty=false] - Whether to redirect to Active Report Screen if IOUReport is empty | ||
| * @returns {Promise} | ||
| */ | ||
| function fetchIOUReportByID(iouReportID, chatReportID, shouldRedirectIfEmpty = false) { | ||
| return fetchIOUReport(iouReportID, chatReportID) | ||
| .then((iouReportObject) => { | ||
| if (!iouReportObject && shouldRedirectIfEmpty) { | ||
| Growl.error(Localize.translateLocal('notFound.iouReportNotFound')); | ||
| Navigation.navigate(ROUTES.REPORT); | ||
| return; | ||
| } | ||
| if (!iouReportObject) { | ||
| return; | ||
| } | ||
| setLocalIOUReportData(iouReportObject); | ||
| return iouReportObject; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get the private pusher channel name for a Report. | ||
| * | ||
|
|
@@ -1416,7 +1343,6 @@ Onyx.connect({ | |
| }); | ||
|
|
||
| export { | ||
| fetchIOUReportByID, | ||
| addComment, | ||
| addAttachment, | ||
| reconnect, | ||
|
|
@@ -1431,7 +1357,6 @@ export { | |
| handleUserDeletedLinks, | ||
| saveReportActionDraft, | ||
| deleteReportComment, | ||
| getSimplifiedIOUReport, | ||
| syncChatAndIOUReports, | ||
| navigateToConciergeChat, | ||
| setReportWithDraft, | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.