Remove the side-loading of data in Task action from the ReportActionUtils#37340
Remove the side-loading of data in Task action from the ReportActionUtils#37340
Conversation
|
@youssef-lr Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Reviewer Checklist
Screenshots/VideosAndroid: Nativeandroid-native-2024-02-28_16.11.40.mp4Android: mWeb Chromeandroid-chrome-2024-02-28_16.16.53.mp4iOS: Nativeios-native-2024-02-28_16.04.54.mp4iOS: mWeb Safariios-safari-2024-02-28_16.06.39.mp4MacOS: Chrome / Safaridesktop-chrome-2024-02-28_15.57.23.mp4MacOS: Desktopdesktop-app-2024-02-28_16.01.58.mp4 |
src/libs/actions/Task.ts
Outdated
| /** | ||
| * Returns the parentReportAction if the given report is a thread/task. | ||
| * | ||
| * @deprecated Use Onyx.connect() or withOnyx() instead |
There was a problem hiding this comment.
Why is this deprecated if it's new?
There was a problem hiding this comment.
Oops, this is copy/paste. I'll remove it.
| * @deprecated Use Onyx.connect() or withOnyx() instead | ||
| */ | ||
| function getParentReportAction(report: OnyxEntry<OnyxTypes.Report>): ReportAction | Record<string, never> { | ||
| if (!report?.parentReportID || !report.parentReportActionID) { |
There was a problem hiding this comment.
Why do we need to check for parentReportID? Can you explain in a comment?
There was a problem hiding this comment.
Comment added (but it's kind of self-explanatory too when you look at the next line and see how those properties are used).
| * | ||
| * @deprecated Use Onyx.connect() or withOnyx() instead | ||
| */ | ||
| function getParentReportAction(report: OnyxEntry<OnyxTypes.Report>): ReportAction | Record<string, never> { |
There was a problem hiding this comment.
Would it be possible and make sense to pass Report here and to deleteTask instead of OnyxEntry<OnyxTypes.Report>, so that we don't have to check report?? It looks like we only call deleteTask in one place
It looks like before we were using props.report.reportName and not props.report?.reportName
There was a problem hiding this comment.
I could revert the changes in deleteTask to go back to using const taskReport = ReportUtils.getReport(taskReportID); which returns a Report and not a OnyxEntry<OnyxTypes.Report>, but here is why I removed it.
- The view already has the full report object from Onyx
- The view was passing 4 properties of the report object to
deleteTaskand then getting the full report object fromReportUtils.getReport() - This is inefficient and leads to really bad code and possibly stale data
- By using the same report reference in all the methods, it's assured that the report object will always be correct
There was a problem hiding this comment.
Oh yeah I think the change you made was an improvement, so I wasn't suggesting reverting back to the old version, just to go from getParentReportAction(report: OnyxEntry<OnyxTypes.Report>): to getParentReportAction(report: Report):, and remove a lot of ? that would be unnecessary. Is that doable?
There was a problem hiding this comment.
You can't simply cast one type to another like that, but I asked about it in Slack and I at least found a way to remove all the optional chaining by adding an early return at the beginning of the method.
There was a problem hiding this comment.
That works. I was thinking not just updating the param type --that was to illustrate what I meant, but also the function call Session.checkIfActionIsAllowed(Task.deleteTask(props.report));, with something like Session.checkIfActionIsAllowed(Task.deleteTask(props.report as Report)); or whatever TS magic helps with that.
I like checking before and returning early tho 👍
|
@cead22 I merged |
|
👍 I was leaving it for Youssef |
|
🚀 Deployed to staging by https://github.com/cead22 in version: 1.4.47-0 🚀
|
|
🚀 Deployed to production by https://github.com/roryabraham in version: 1.4.47-10 🚀
|
Details
This will ensure that the Task action is using data that it is directly connected to.
Fixed Issues
Part of #27262
Tests
Offline tests
Same as the tests.
QA Steps
Same as the tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel so the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
2024-02-27_11-57-28.mp4
Android: mWeb Chrome
iOS: Native
2024-02-27_11-35-33.mp4
iOS: mWeb Safari
2024-02-27_11-31-01.mp4
MacOS: Chrome / Safari
2024-02-27_11-24-56.mp4
MacOS: Desktop
2024-02-27_11-29-15.mp4