-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[PR 5 of 16] Remove global Onyx reference from getOriginalReportID #82864
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
Changes from all commits
188bae8
e31ea59
388d9a9
f1257f4
04cd555
7c5d0a1
22f435e
a4060a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,7 @@ Onyx.connect({ | |
| }, | ||
| }); | ||
|
|
||
| function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) { | ||
| const originalReportID = getOriginalReportID(reportID, reportAction, undefined); | ||
|
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 the call I was able to remove in this PR |
||
|
|
||
| function clearReportActionErrors(reportID: string, reportAction: ReportAction, originalReportID: string | undefined, keys?: string[]) { | ||
| if (!reportAction?.reportActionID) { | ||
| return; | ||
| } | ||
|
|
@@ -80,27 +78,36 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction, k | |
| ignore: `undefined` means we want to check both parent and children report actions | ||
| ignore: `parent` or `child` means we want to ignore checking parent or child report actions because they've been previously checked | ||
| */ | ||
| function clearAllRelatedReportActionErrors(reportID: string | undefined, reportAction: ReportAction | null | undefined, ignore?: IgnoreDirection, keys?: string[]) { | ||
| function clearAllRelatedReportActionErrors( | ||
| reportID: string | undefined, | ||
| reportAction: ReportAction | null | undefined, | ||
| originalReportID: string | undefined, | ||
| ignore?: IgnoreDirection, | ||
| keys?: string[], | ||
| ) { | ||
| const errorKeys = keys ?? Object.keys(reportAction?.errors ?? {}); | ||
| if (!reportAction || errorKeys.length === 0 || !reportID) { | ||
| return; | ||
| } | ||
|
|
||
| clearReportActionErrors(reportID, reportAction, keys); | ||
| clearReportActionErrors(reportID, reportAction, originalReportID, keys); | ||
|
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.
Useful? React with 👍 / 👎. |
||
|
|
||
| const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; | ||
| if (report?.parentReportID && report?.parentReportActionID && ignore !== 'parent') { | ||
| const parentReportAction = getReportAction(report.parentReportID, report.parentReportActionID); | ||
| const parentErrorKeys = Object.keys(parentReportAction?.errors ?? {}).filter((err) => errorKeys.includes(err)); | ||
| const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`] ?? {}; | ||
|
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. I know it stinks to have to add this (and the one a few lines below). I fully intend to pass these as params in the next PR. I felt it was just too much to do it in this same PR. |
||
| const parentOriginalReportID = getOriginalReportID(report.parentReportID, parentReportAction, parentReportActions); | ||
|
|
||
| clearAllRelatedReportActionErrors(report.parentReportID, parentReportAction, 'child', parentErrorKeys); | ||
| clearAllRelatedReportActionErrors(report.parentReportID, parentReportAction, parentOriginalReportID, 'child', parentErrorKeys); | ||
| } | ||
|
|
||
| if (reportAction.childReportID && ignore !== 'child') { | ||
| const childActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.childReportID}`] ?? {}; | ||
| for (const action of Object.values(childActions)) { | ||
| const childErrorKeys = Object.keys(action.errors ?? {}).filter((err) => errorKeys.includes(err)); | ||
| clearAllRelatedReportActionErrors(reportAction.childReportID, action, 'parent', childErrorKeys); | ||
| const childOriginalReportID = getOriginalReportID(reportAction.childReportID, action, childActions); | ||
| clearAllRelatedReportActionErrors(reportAction.childReportID, action, childOriginalReportID, 'parent', childErrorKeys); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -442,7 +442,13 @@ type PureReportActionItemProps = { | |
| clearError?: (transactionID: string) => void; | ||
|
|
||
| /** Function to clear all errors from a report action */ | ||
| clearAllRelatedReportActionErrors?: (reportID: string | undefined, reportAction: OnyxTypes.ReportAction | null | undefined, ignore?: IgnoreDirection, keys?: string[]) => void; | ||
| clearAllRelatedReportActionErrors?: ( | ||
| reportID: string | undefined, | ||
| reportAction: OnyxTypes.ReportAction | null | undefined, | ||
| originalReportID: string | undefined, | ||
| ignore?: IgnoreDirection, | ||
| keys?: string[], | ||
| ) => void; | ||
|
|
||
| /** Function to dismiss the actionable whisper for tracking expenses */ | ||
| dismissTrackExpenseActionableWhisper?: (reportID: string | undefined, reportAction: OnyxEntry<OnyxTypes.ReportAction>) => void; | ||
|
|
@@ -621,14 +627,14 @@ function PureReportActionItem({ | |
| const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : undefined; | ||
| if (isSendingMoney && transactionID && reportID) { | ||
| const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; | ||
| cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, true); | ||
| cleanUpMoneyRequest(transactionID, action, reportID, report, chatReport, undefined, originalReportID, true); | ||
| return; | ||
| } | ||
| if (transactionID) { | ||
| clearError(transactionID); | ||
| } | ||
| clearAllRelatedReportActionErrors(reportID, action); | ||
| }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError]); | ||
| clearAllRelatedReportActionErrors(reportID, action, originalReportID); | ||
|
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 call now forwards Useful? React with 👍 / 👎. 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.
Useful? React with 👍 / 👎.
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. Same as #82864 (comment) |
||
| }, [action, isSendingMoney, clearAllRelatedReportActionErrors, reportID, allReports, report, clearError, originalReportID]); | ||
|
|
||
| const showDismissReceiptErrorModal = useCallback(async () => { | ||
| const result = await showConfirmModal({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2552,7 +2552,7 @@ describe('actions/IOU', () => { | |
| () => | ||
| new Promise<void>((resolve) => { | ||
| if (iouReportID) { | ||
| clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null); | ||
| clearAllRelatedReportActionErrors(iouReportID, iouAction ?? null, iouReportID); | ||
|
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. @tgolen should this new arg be the same
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. Yep, it's the same value that |
||
| } | ||
| resolve(); | ||
| }), | ||
|
|
||
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.
Is the logic of this hook exactly same as
getOriginalReportIDfunction?It's possible that this hook might return
undefinedfor some reason, whilegetOriginalReportIDalways returnsreportIDas fallback.App/src/hooks/useOriginalReportID.ts
Lines 73 to 74 in 9a0afa0
The bot raised the same concern here.
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.
I had the exact same question! I found the original author of the hook, and we discussed that the logic in the hook is probably more accurate than the method. We discussed a plan to try to unify the method and hook more (by just having the server return the
reportAction.reportIDand being able to reference that directly without as much of the extra logic), but I don't know when we'll be able to do that.I'm not too worried about this returning
undefinedbecause I think it will only happen in theory and never in practice. If we are really worried about it, then I could add a log line so that we are at least aware if it is returningundefined.