-
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
Changes from 3 commits
01d5c3d
56dfcf0
57ec194
9eb84c0
a27e869
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 |
---|---|---|
|
@@ -99,11 +99,13 @@ class ReportScreen extends React.Component { | |
} | ||
|
||
componentDidUpdate(prevProps) { | ||
const reportChanged = this.props.route.params.reportID !== prevProps.route.params.reportID; | ||
if (reportChanged) { | ||
this.prepareTransition(); | ||
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 commentThe 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:
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 commentThe 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 commentThe 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 commentThe 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. |
||
} | ||
|
||
this.prepareTransition(); | ||
this.storeCurrentlyViewedReport(); | ||
} | ||
|
||
componentWillUnmount() { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -189,11 +189,12 @@ class ReportActionCompose extends React.Component { | |||||
this.focus(); | ||||||
} | ||||||
|
||||||
// If we switch from a sidebar, the component does not mount again | ||||||
// 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 commentThe 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
Suggested change
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. Gotcha, I was not sure about that comment actually, thank you for bringing it up! I will update it just now. |
||||||
if (this.props.report.reportID === prevProps.report.reportID) { | ||||||
return; | ||||||
} | ||||||
|
||||||
this.updateComment(this.props.comment); | ||||||
} | ||||||
|
||||||
componentWillUnmount() { | ||||||
|
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 👍