-
Notifications
You must be signed in to change notification settings - Fork 4k
Refactor title handling #5168
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 title handling #5168
Conversation
cwillisf
left a 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.
I feel a bit out of my depth but this seems to make sense to me. Thanks for working on this!
src/containers/gui.jsx
Outdated
| isLoading: PropTypes.bool, | ||
| isScratchDesktop: PropTypes.bool, | ||
| isShowingProject: PropTypes.bool, | ||
| isShowingWithoutId: PropTypes.bool, |
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 this added intentionally? It looks unrelated.
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.
Removing...
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.
Done
src/lib/titled-hoc.jsx
Outdated
| this.props.onUpdateProjectTitle(defaultProjectTitle); | ||
| } | ||
| } | ||
| titleWithDefault (title) { |
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.
Why is this a function that takes a title argument? It looks like it's only called in one place, without an argument.
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 think I meant to refactor setReduxTitle further... doing this now
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.
Done
src/lib/titled-hoc.jsx
Outdated
| <WrappedComponent | ||
| canEditTitle | ||
| projectTitle={this.state.projectTitle} | ||
| onUpdateProjectTitle={this.handleUpdateProjectTitle} |
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.
If we expect children to receive the title from redux, I think we should we also expect them to set it through redux.
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 made this change, now testing it...
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.
Tested well
117b940 to
76b4c6f
Compare
76b4c6f to
ced7ee7
Compare
| if (this.props.projectTitle !== prevProps.projectTitle) { | ||
| this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle)); | ||
| } | ||
| // if the projectTitle hasn't changed, but the reduxProjectTitle |
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.
Note this addition... here is where the change to redux title gets echoed up to the enclosing context (i.e., www)
ced7ee7 to
68780ae
Compare
| } | ||
| }); | ||
|
|
||
| class ProjectTitleInput extends React.Component { |
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 should change this back to how it was before
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 think this is fine to do since your handler is coming from Redux now. I just think the name of the prop should change.
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.
Doing this...
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.
Done
src/lib/titled-hoc.jsx
Outdated
| projectTitle: null | ||
| }; | ||
| componentDidMount () { | ||
| this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle)); |
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.
can combine these calls
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.
Changing...
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.
Done
rschamp
left a 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.
I have a few nits, but I think this is looking good overall. Especially that we don't need to consider projectId as a part of this.
|
|
||
| ProjectTitleInput.propTypes = { | ||
| className: PropTypes.string, | ||
| handleUpdateReduxProjectTitle: PropTypes.func, |
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'm surprised the linter didn't catch this, because I think it used to. Prop names for events should be onX like onUpdateReduxProjectTitle. The name of the event handler itself should be handleX. The distinction is that the prop describes that the component might receive an event. The name of the handler describes that something should happen when that event is received.
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.
What I'm used to the linter insisting on is that this form be followed:
onXXXX={this.handleXXXX}
In my experience it doesn't like
onXXXX={this.onXXXX}
but it's ok with
onXXXX={this.props.whateverNameIsOK}
src/containers/sb-file-uploader.jsx
Outdated
| onUpdateProjectTitle: PropTypes.func, | ||
| projectChanged: PropTypes.bool, | ||
| requestProjectUpload: PropTypes.func, | ||
| updateReduxProjectTitle: PropTypes.func, |
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.
Same comment here about event props. onUpdateReduxProjectTitle would be more consistent.
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.
Changing...
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.
Done
| } | ||
| }); | ||
|
|
||
| class ProjectTitleInput extends React.Component { |
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 think this is fine to do since your handler is coming from Redux now. I just think the name of the prop should change.
rschamp
left a 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.
Thanks for all your work on this!
Resolves
Should resolve #3433 and scratchfoundation/scratch-desktop#71 ;
Note that it does not seem to resolve the related #4759 .
Proposed Changes
Repurpose TitledHOC so that it:
canEditTitleto true on childrenisShowingWithoutId, uses the translated default project name to set the redux projectTitle, and also calls the parent'sonUpdateProjectTitleprop functionGUI's playground/standalone versions previously used TitledHOC, so they need to explicitly pass
canEditTitleto children.scratch-desktop will need to no longer wrap itself with TitledHOC, and instead maintain its own projectTitle state.
Related
If this is merged, we will need to merge scratchfoundation/scratch-desktop#74 as well so that scratch-desktop is in line with these changes.
Reason for Changes