Skip to content

Commit

Permalink
Sites: Don't bind selectors to state (#14030)
Browse files Browse the repository at this point in the history
* State: Add isSiteUpgradeable to Jetpack computed attributes

* Sites: Use isSiteUpgradeable computed attribute

* Sites: Consider sites without a determined upgradeable state

* Sites: Consider .com sites as upgradeable
  • Loading branch information
mcsf authored and tyxla committed May 24, 2017
1 parent 878d256 commit 789ac3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions client/my-sites/sites/sites.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Main from 'components/main';
import observe from 'lib/mixins/data-observe';
import SiteSelector from 'components/site-selector';
import { addSiteFragment } from 'lib/route';
import { getSites, isSiteUpgradeable } from 'state/selectors';
import { getSites } from 'state/selectors';
import { getSelectedSite } from 'state/ui/selectors';

export const Sites = React.createClass( {
Expand Down Expand Up @@ -47,7 +47,7 @@ export const Sites = React.createClass( {

// Filter out sites with no upgrades on particular routes
if ( /^\/domains/.test( path ) || /^\/plans/.test( this.props.sourcePath ) ) {
return this.props.isSiteUpgradeable( site.ID );
return ! site.isJetpack || site.isSiteUpgradable;
}

return site;
Expand Down Expand Up @@ -103,7 +103,6 @@ export default connect(
return {
selectedSite: getSelectedSite( state ),
sites: getSites( state ),
isSiteUpgradeable: isSiteUpgradeable.bind( null, state ),
};
}
)( Sites );
2 changes: 2 additions & 0 deletions client/state/sites/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { fromApi as seoTitleFromApi } from 'components/seo/meta-title-editor/map
import versionCompare from 'lib/version-compare';
import getComputedAttributes from 'lib/site/computed-attributes';
import { getCustomizerFocus } from 'my-sites/customize/panels';
import { isSiteUpgradeable } from 'state/selectors';

/**
* Returns a raw site object by its ID.
Expand Down Expand Up @@ -102,6 +103,7 @@ export function getJetpackComputedAttributes( state, siteId ) {
canManage: canJetpackSiteManage( state, siteId ),
isMainNetworkSite: isJetpackSiteMainNetworkSite( state, siteId ),
isSecondaryNetworkSite: isJetpackSiteSecondaryNetworkSite( state, siteId ),
isSiteUpgradeable: isSiteUpgradeable( state, siteId ),
};
}

Expand Down
18 changes: 18 additions & 0 deletions client/state/sites/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,14 @@ describe( 'selectors', () => {
describe( 'getJetpackComputedAttributes()', () => {
it( 'should return undefined attributes if a site is not Jetpack', () => {
const state = {
currentUser: {
id: 73705554,
capabilities: {
77203074: {
manage_options: false
}
}
},
sites: {
items: {
77203074: {
Expand All @@ -3293,10 +3301,19 @@ describe( 'selectors', () => {
expect( noNewAttributes.canManage ).to.equal( undefined );
expect( noNewAttributes.isMainNetworkSite ).to.equal( undefined );
expect( noNewAttributes.isSecondaryNetworkSite ).to.equal( undefined );
expect( noNewAttributes.isSiteUpgradeable ).to.equal( undefined );
} );

it( 'should return exists for attributes if a site is Jetpack', () => {
const state = {
currentUser: {
id: 73705554,
capabilities: {
77203074: {
manage_options: false
}
}
},
sites: {
items: {
77203074: {
Expand All @@ -3313,6 +3330,7 @@ describe( 'selectors', () => {
expect( noNewAttributes.canManage ).to.have.property;
expect( noNewAttributes.isMainNetworkSite ).to.have.property;
expect( noNewAttributes.isSecondaryNetworkSite ).to.have.property;
expect( noNewAttributes.isSiteUpgradeable ).to.have.property;
} );
} );
} );

0 comments on commit 789ac3e

Please sign in to comment.