-
Notifications
You must be signed in to change notification settings - Fork 3k
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: IOU-Error message remains on IOU report even same error message is dismissed from 1:1 #37875
Changes from all commits
b4d4e1e
5ff118c
9d8885a
0a7462c
c072564
581464c
e2a9c26
4606d18
d201dea
ae7b13e
d48692e
db0453a
130b6df
439ffc9
82bb67f
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import * as ReportActionUtils from '@libs/ReportActionsUtils'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type ReportAction from '@src/types/onyx/ReportAction'; | ||
import * as Report from './Report'; | ||
|
||
function clearReportActionErrors(reportID: string, reportAction: OnyxEntry<ReportAction>) { | ||
type IgnoreDirection = 'parent' | 'child'; | ||
|
||
function clearReportActionErrors(reportID: string, reportAction: ReportAction, keys?: string[]) { | ||
const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); | ||
|
||
if (!reportAction?.reportActionID) { | ||
|
@@ -34,14 +35,58 @@ function clearReportActionErrors(reportID: string, reportAction: OnyxEntry<Repor | |
return; | ||
} | ||
|
||
if (keys) { | ||
const errors: Record<string, null> = {}; | ||
|
||
keys.forEach((key) => { | ||
errors[key] = null; | ||
}); | ||
|
||
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, { | ||
[reportAction.reportActionID]: { | ||
errors, | ||
}, | ||
}); | ||
return; | ||
} | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, { | ||
[reportAction.reportActionID]: { | ||
errors: null, | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
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, reportAction: ReportAction | null, ignore?: IgnoreDirection, keys?: string[]) { | ||
const errorKeys = keys ?? Object.keys(reportAction?.errors ?? {}); | ||
if (!reportAction || errorKeys.length === 0) { | ||
return; | ||
} | ||
|
||
clearReportActionErrors(reportID, reportAction, keys); | ||
|
||
const report = ReportUtils.getReport(reportID); | ||
if (report?.parentReportID && report?.parentReportActionID && ignore !== 'parent') { | ||
const parentReportAction = ReportActionUtils.getReportAction(report.parentReportID, report.parentReportActionID); | ||
const parentErrorKeys = Object.keys(parentReportAction?.errors ?? {}).filter((err) => errorKeys.includes(err)); | ||
|
||
clearAllRelatedReportActionErrors(report.parentReportID, parentReportAction, 'child', parentErrorKeys); | ||
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. Please point out 1 case where we need to call 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 already used it in Pls correct me if I misunderstand sth |
||
} | ||
|
||
if (reportAction.childReportID && ignore !== 'child') { | ||
const childActions = ReportActionUtils.getAllReportActions(reportAction.childReportID); | ||
Object.values(childActions).forEach((action) => { | ||
const childErrorKeys = Object.keys(action.errors ?? {}).filter((err) => errorKeys.includes(err)); | ||
clearAllRelatedReportActionErrors(reportAction.childReportID ?? '', action, 'parent', childErrorKeys); | ||
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.
@tienifr For this point, I mean that in here 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. Well, we need to use |
||
}); | ||
} | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
clearReportActionErrors, | ||
clearAllRelatedReportActionErrors, | ||
}; |
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 is to handle cases with multiple errors in the same report action, right?
It may be a good improvement but It is not mentioned in the issue. Why do you think It is our expectation? Do you confirm with the design team or any internal engineer about that?
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
When users click x button, we'll clear all errors of that action, so the related action can share some same errors and we need to clear all of them. I believe it's the expectation in the OP
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 agree that's the expectation