diff --git a/client/state/selectors/are-all-sites-single-user.js b/client/state/selectors/are-all-sites-single-user.js new file mode 100644 index 00000000000000..37bdff1b393614 --- /dev/null +++ b/client/state/selectors/are-all-sites-single-user.js @@ -0,0 +1,16 @@ +/** + * Internal dependencies + */ +import createSelector from 'lib/create-selector'; +import { isSingleUserSite } from 'state/sites/selectors'; + +/** + * Returns true if every site of the current user is a single user site + * + * @param {Object} state Global state tree + * @return {Boolean} True if all sites are single user sites + */ +export default createSelector( ( state ) => { + const siteIds = Object.keys( state.sites.items ); + return siteIds && siteIds.every( ( siteId ) => isSingleUserSite( state, siteId ) ); +}, ( state ) => ( state.sites.items ) ); diff --git a/client/state/selectors/index.js b/client/state/selectors/index.js index 585ced19df038e..bebe389d5f5f02 100644 --- a/client/state/selectors/index.js +++ b/client/state/selectors/index.js @@ -13,6 +13,7 @@ * to its individual file. */ +export areAllSitesSingleUser from './are-all-sites-single-user'; export areSitePermalinksEditable from './are-site-permalinks-editable'; export canCurrentUser from './can-current-user'; export countPostLikes from './count-post-likes'; diff --git a/client/state/selectors/test/are-all-sites-single-user.js b/client/state/selectors/test/are-all-sites-single-user.js new file mode 100644 index 00000000000000..959ab541e32b93 --- /dev/null +++ b/client/state/selectors/test/are-all-sites-single-user.js @@ -0,0 +1,51 @@ +/** + * External dependencies + */ +import { expect } from 'chai'; + +/** + * Internal dependencies + */ +import { areAllSitesSingleUser } from '../'; + +describe( 'areAllSitesSingleUser()', () => { + it( 'should return false if single_user_site isn\'t true for all sites', () => { + const state = { + sites: { + items: { + 2916284: { + ID: 2916284, + single_user_site: true + }, + 2916285: { + ID: 2916285, + single_user_site: false + } + } + } + }; + + const allAreSingleUser = areAllSitesSingleUser( state ); + expect( allAreSingleUser ).to.be.false; + } ); + + it( 'should return true if single_user_site is true for all sites', () => { + const state = { + sites: { + items: { + 2916284: { + ID: 2916284, + single_user_site: true + }, + 2916285: { + ID: 2916285, + single_user_site: true + } + } + } + }; + + const allAreSingleUser = areAllSitesSingleUser( state ); + expect( allAreSingleUser ).to.be.true; + } ); +} );