-
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
Refactor the componentDidUpdate method for ReportActionCompose #4768
Conversation
@marcaaron My theory based on what I have observed when testing it is that the Isn't it that the |
Yes that makes sense to me. It should be like 1 tick behind because Onyx is asynchronous. Is that what you're asking? |
this.textInput.setNativeProps({text: this.props.comment}); | ||
// If we switch the reports, make sure to update the composer comment | ||
const reportChanged = this.props.report.reportID !== prevProps.report.reportID; | ||
if (reportChanged) { |
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 should use an early return like
if (!reportChanged) {
return;
}
this.updateComment(this.props.comment);
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.
Also reportChanged
does not need a variable just put the comparison into the if case?
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.
Updated the componentDidUpdate
accordingly. Since the same logic is also used in ReportScreen
, I have updated it there too to follow the same pattern or early return for consistency :)
Sorry for the ping, Bondy, that was some bug, I have not assigned PullerBear again :/
@marcaaron Yes, that is what I meant. The Onyx report change is always a bit behind the route change. |
// so we need to update the comment manually. | ||
if (prevProps.comment !== this.props.comment) { | ||
this.textInput.setNativeProps({text: this.props.comment}); | ||
// If we switch the reports, make sure to update the composer comment; otherwise return early |
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.
NAB comments should explain why not what we are doing in the code. so I would suggest removing the otherwise return early
and instead a because...
explaining why we need to update the composer comment:
// If we switch the reports, make sure to update the composer comment; otherwise return early | |
// If we switch the reports, make sure to update the composer comment because [we don't want to leave old data around] [we shouldn't copy what a user had types in one place to another] |
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.
Gotcha, I was not sure about that comment actually, thank you for bringing it up! I will update it just now.
this.storeCurrentlyViewedReport(); | ||
// If we do not switch between reports, return early | ||
if (this.props.route.params.reportID === prevProps.route.params.reportID) { | ||
return; |
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.
NAB, I know this was probably added since you noticed that the style doesn't match what I asked for in another comment. But since this change doesn't have anything to do with the current change I wonder if a better way to handle this would be to:
- Create a new issue calling out there there are places where early returns are not used
- Follow up to audit existing
if
blocks to see which are not using early returns and fix them
I'm not asking you to do it since we don't really have any rules or conventions about this. Some feel like it's fine to fix things that are wrong when you see them and others (like me) prefer to keep only material changes in PRs so that context is preserved and no one needs to ask why something was done. I don't think there is a "right way", so mostly just sharing this perspective.
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 really appreciate you sharing this with me. This helps me a lot 🙇 I do agree it is not ideal to add changes and fixes to PR where it might be unrelated and uncalled for. I haven't realized it now, but I will definitely try to keep this on mind for future! It will make for clearer and easier to follow issues and PR for sure 🙌
I agree with you on the proposed process how to handle such a change, although as you stated, I think before creating such an investigation issue, we should make sure we update the Styling guidelines accordingly. That way if we fix this bad smell throughout the codebase we will have lesser chances of introducing it again.
Do you think this is work of being added to the styling guide, or it is too nitty-gritty 👀 ?
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.
FWIW how I view "adjacent style changes" (completely just made that up) like this are to weigh the "pros vs cons" of how bad it might be to have to revert or quickly fix if this breaks something unexpectedly.
I agree this seems like a pretty low risk change so probably fine to leave. But this mean you should be on the look out for any messages in #api-errors, #qa, or new GHs from Success that mention anything about weirdness about the report pages.
If you're not willing to be on "high alert" and fix something like that then I'd say only make the change you intended to make and leave the "adjacent style change" alone and spin up a new GH to fix it so that it's properly tested in it's own PR.
I don't think there is a need for a style guide rule or anything since there will be nuances to every PR where sometimes it makes sense to change all "adjacent style changes" and other times it might not make the most sense.
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.
@bondydaa Thank you very much for your 2 cents here! Glad to have another perspective on this 💯
I will keep an eye on those channels! Thanks for the heads up. I think in this case there should not be high risk 🤞 since the logic stays the same, but I totally see what you mean. Even with minor styling changes, we should make sure all the flows are working and no edge case has been omitted 👍
Regarding the styling guide, I see your point. Eventually, informing more and more engineers about this style approach, we might get more of them using it in their code and PR reviews consequently making it standard the organic way.
src/pages/home/ReportScreen.js
Outdated
if (reportChanged) { | ||
this.prepareTransition(); | ||
this.storeCurrentlyViewedReport(); | ||
// If we do not switch between reports, return early |
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.
Similar comment to @bondydaa but if a comment ends up just describing what the code is doing (or is very obvious) then we probably don't need the comment at all.
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.
Good point, in this case it is actually bit clearer why we check if the reports have changed. I will omit the comment here 👍
@bondydaa @marcaaron Thank you very much for your tips, advice and best practices on this matter. I have pushed some updates, I tried to give a better yet short description of why we update the comment if Thank you for your reviews 🙌 |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @marcaaron in version: 1.0.89-0 🚀
|
@mountiny @marcaaron Are we good to check this PR off the list? (I'm guessing it's NoQA but wanted to double check) |
@isagoico I filled in the QA steps here. Can you please perform QA on this? |
Just tested it and it was a pass 🎉 checking it off. |
🚀 Deployed to production by @roryabraham in version: 1.0.90-2 🚀
|
Details
To resolve a StagingDeployBlocker, we have introduced some changes which need some refactoring. How to refactor has been discussed and decided in this thread here. Look there for more details.
Fixed Issues
❌
Tests
Just repeat the
action performed
steps from this issue #4756 and make sure it all works as expected.QA Steps
Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android