Skip to content
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

Plans: check if selectedSite exists before checking for domain credit #5089

Merged
merged 1 commit into from
Apr 29, 2016

Conversation

gwwar
Copy link
Contributor

@gwwar gwwar commented Apr 28, 2016

Potential fix for #5084. This adds bulletproofing before we check if a site has domain credits.

I wasn't able to reproduce the original issue, but we should handle this case anyway.

cc @fabianapsimoes @stephanethomas @rralian

@gwwar gwwar self-assigned this Apr 28, 2016
@gwwar gwwar added [Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Apr 28, 2016
@gwwar gwwar added this to the Plans Iteration 1 milestone Apr 28, 2016
@@ -335,7 +335,7 @@ export const List = React.createClass( {

export default connect( ( state, ownProps ) => {
return {
hasDomainCredit: hasDomainCredit( state, ownProps.selectedSite.ID )
hasDomainCredit: ownProps.selectedSite && hasDomainCredit( state, ownProps.selectedSite.ID )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be done in current-site/notice.jsx as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes a similar check, or enforce an object being passed through in propTypes:

    propTypes: {
        site: React.PropTypes.object.isRequired
    },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the latter of an explicit prop, but I added the former in 48a7bd2 for a quick fix

@gwwar gwwar force-pushed the fix/site-deletion branch from 87dcd09 to 48a7bd2 Compare April 28, 2016 15:52
@@ -92,7 +92,7 @@ const SiteNotice = React.createClass( {

export default connect( ( state, ownProps ) => {
return {
hasDomainCredit: hasDomainCredit( state, ownProps.site.ID )
hasDomainCredit: !! ownProps.site && hasDomainCredit( state, ownProps.site.ID )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the convention to use Boolean() instead of !!?

FWIW, we usually just check only if it's falsy:

  hasDomainCredit: ownProps.site && hasDomainCredit( state, ownProps.site.ID )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a common js usage. I think its a bit more clear for !! to denote that we're testing for truthyness. The Boolean conversion can sometimes return unexpected things, like so:

Boolean("false"); // still returns true 

@stephanethomas
Copy link
Contributor

Thanks for fixing it Kerry! I think one way to reproduce it is to sandbox the API (or to make API calls very slow :)).

@gwwar gwwar merged commit 20e2c42 into master Apr 29, 2016
@gwwar gwwar deleted the fix/site-deletion branch April 29, 2016 15:30
@scruffian scruffian removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Plans & Upgrades All of the plans on WordPress.com and flow for upgrading plans.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants