Skip to content

Commit

Permalink
Rename selectedSiteSlug to locallySelectedSiteId.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed May 26, 2017
1 parent 9e0a105 commit 578e1e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
36 changes: 19 additions & 17 deletions client/components/sites-dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React, { PropTypes, PureComponent } from 'react';
import { connect } from 'react-redux';
import classNames from 'classnames';
import { flow, get, noop } from 'lodash';
import { flow, get, identity, noop } from 'lodash';
import Gridicon from 'gridicons';

/**
Expand All @@ -27,16 +27,18 @@ export class SitesDropdown extends PureComponent {
filter: PropTypes.func,
isPlaceholder: PropTypes.bool,

// Redux-provided
// connected props
initialSiteId: PropTypes.number.isRequired,
selectedSite: PropTypes.object,
setLocallySelectedSiteId: PropTypes.func,
}

static defaultProps = {
showAllSites: false,
onClose: noop,
onSiteSelect: noop,
isPlaceholder: false
isPlaceholder: false,
setLocallySelectedSiteId: identity,
}

constructor( props ) {
Expand All @@ -51,13 +53,13 @@ export class SitesDropdown extends PureComponent {
state = { open: false }

componentDidMount() {
const { initialSiteId, setSelectedSiteSlug } = this.props;
setSelectedSiteSlug( initialSiteId );
const { initialSiteId, setLocallySelectedSiteId } = this.props;
setLocallySelectedSiteId( initialSiteId );
}

selectSite( siteSlug ) {
this.props.onSiteSelect( siteSlug );
this.props.setSelectedSiteSlug( siteSlug );
this.props.setLocallySelectedSiteId( siteSlug );
this.setState( {
open: false
} );
Expand Down Expand Up @@ -104,12 +106,12 @@ export class SitesDropdown extends PureComponent {
}
}

const mapState = ( state, { selectedSiteId, selectedSiteSlug } ) => {
const mapState = ( state, { selectedSiteId, locallySelectedSiteId } ) => {
const initialSiteId = selectedSiteId ||
getPrimarySiteId( state );

const selectedSite = selectedSiteSlug
? getSite( state, selectedSiteSlug )
const selectedSite = locallySelectedSiteId
? getSite( state, locallySelectedSiteId )
: undefined;

return {
Expand All @@ -122,25 +124,25 @@ const mapState = ( state, { selectedSiteId, selectedSiteSlug } ) => {
* A container for component state that can then be passed to SitesDropdown's
* Redux-connected counterpart.
*/
const withSelectedSiteSlug = ( Wrapped ) => class extends PureComponent {
static displayName = `WithSelectedSiteSlug(${
const withSelectedSiteId = ( Wrapped ) => class extends PureComponent {
static displayName = `WithSelectedSiteId(${
Wrapped.displayName || Wrapped.name } )`

state = { selectedSiteSlug: null }
state = { locallySelectedSiteId: null }

setSelectedSiteSlug = ( slug ) => {
this.setState( { selectedSiteSlug: slug } );
setLocallySelectedSiteId = ( slug ) => {
this.setState( { locallySelectedSiteId: slug } );
}

render() {
return <Wrapped
selectedSiteSlug={ this.state.selectedSiteSlug }
setSelectedSiteSlug={ this.setSelectedSiteSlug }
locallySelectedSiteId={ this.state.locallySelectedSiteId }
setLocallySelectedSiteId={ this.setLocallySelectedSiteId }
{ ...this.props } />;
}
};

export default flow(
connect( mapState ),
withSelectedSiteSlug
withSelectedSiteId
)( SitesDropdown );
8 changes: 4 additions & 4 deletions client/components/sites-dropdown/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ describe( 'index', function() {
describe( 'selectSite', function() {
it( 'should update the `selectedSiteSlug`, and `open` state properties', function() {
const setStateSpy = sinon.spy();
const setSelectedSiteSlugSpy = sinon.spy();
const setLocallySelectedSiteIdSpy = sinon.spy();
const siteSelectedSpy = sinon.spy();
const fakeContext = {
setState: setStateSpy,
props: {
onSiteSelect: siteSelectedSpy,
setSelectedSiteSlug: setSelectedSiteSlugSpy,
setLocallySelectedSiteId: setLocallySelectedSiteIdSpy,
}
};

Expand All @@ -79,8 +79,8 @@ describe( 'index', function() {
sinon.assert.calledOnce( siteSelectedSpy );
sinon.assert.calledWith( siteSelectedSpy, 'foobar' );

sinon.assert.calledOnce( setSelectedSiteSlugSpy );
sinon.assert.calledWith( setSelectedSiteSlugSpy, 'foobar' );
sinon.assert.calledOnce( setLocallySelectedSiteIdSpy );
sinon.assert.calledWith( setLocallySelectedSiteIdSpy, 'foobar' );

sinon.assert.calledOnce( setStateSpy );
sinon.assert.calledWith( setStateSpy, { open: false } );
Expand Down

0 comments on commit 578e1e8

Please sign in to comment.