-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Janitorial: Refactor site-redirect domain management component #16549
Conversation
aidvu
commented
Jul 25, 2017
- ES6ify
- Use Redux actions for tracking
- Remove unnecessary file
- Fix broken input and loading placeholders
- ES6ify - Use Redux actions for tracking - Remove unnecessary file - Fix broken input and loading placeholders
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.
A few minor nitpicks, but otherwise LGTM 👍 Thanks for all these refactor PRs 🙇
|
||
handleChange( event ) { | ||
handleChange = ( event ) => { | ||
let location = event.target.value; | ||
|
||
// Removes the protocol part | ||
location = location.replace( /.*:\/\//, '' ); |
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.
Seems like a good idea to also use withoutHttp
here, like it was done in https://github.com/Automattic/wp-calypso/pull/16193/files#diff-6564d86c047bc86c6f216e59c29aee42R79.
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.
My only problem is that in theory the redirect could be to any protocol. Gah, maybe we should make stripProtocol/withoutProtocol
?
}; | ||
|
||
state = { | ||
location: this.props.location.value |
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.
Wait, location
is both in the state and props? 🤦♂️ Maybe we could at least name them differently? The one in state could be something like locationValue
.
let classes = classNames( | ||
const { location, translate } = this.props; | ||
const { isUpdating, notice } = location; | ||
const isFetching = location.isFetching || this.state.location === null; |
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 an example where the props vs state location gets confusing - my initial reaction was "oh, he did not re-use the destructured location
he got from props
"... then I facepalmed ;)
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.
Agree.
|
||
<Main className="domain-management-site-redirect"> | ||
{ | ||
notice && |
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.
name="destination" | ||
noWrap | ||
onChange={ this.handleChange } | ||
onFocus={ this.handleFocus } | ||
prefix="http://" | ||
type="text" | ||
value={ this.state.location } /> | ||
value={ this.state.location || '' } /> |
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.
Maybe this logic should be moved to initializing state above?
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.
Problem is that then we loose the null
. :) Well, in theory, empty state should also be invalid. Will try.
</FormLabel> | ||
|
||
<FormTextInputWithAffixes | ||
disabled={ this.props.location.isFetching || this.props.location.isUpdating } | ||
disabled={ isFetching || isUpdating } |
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.
Nice 👍
onClick={ this.handleClick }> | ||
{ this.translate( 'Update Site Redirect' ) } | ||
{ translate( 'Update Site Redirect' ) } | ||
</FormButton> | ||
|
||
<FormButton |
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.
From an UX perspective, it might be good to disable the Cancel
button too, when we're updating - otherwise, it might seem to the user that it's the button to cancel the update, when in fact it will just navigate away.
Also: fixes #3148 🎉 |