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

Me: Use SitesDropdown instead of SelectSite in /me/account #1837

Merged
merged 6 commits into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/components/sites-dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ render() {
* `onClose` (`function`) — called on site selection
* `onSiteSelect` (`function`) - called with the site `slug` on site selection
* `filter` (`function`) - If present, passed to `sites.filter()` to display a subset of sites. Return `true` to display a site.
* `isPlaceholder` (`bool`) - `true` to display as a placeholder


23 changes: 15 additions & 8 deletions client/components/sites-dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import noop from 'lodash/utility/noop';
* Internal dependencies
*/
import Site from 'my-sites/site';
import SitePlaceholder from 'my-sites/site/placeholder';
import SiteSelector from 'components/site-selector';
import sitesList from 'lib/sites-list';
import Gridicon from 'components/gridicon';
Expand All @@ -30,14 +31,16 @@ export default React.createClass( {
showAllSites: React.PropTypes.bool,
onClose: React.PropTypes.func,
onSiteSelect: React.PropTypes.func,
filter: React.PropTypes.func
filter: React.PropTypes.func,
isPlaceholder: React.PropTypes.bool
},

getDefaultProps() {
return {
showAllSites: false,
onClose: noop,
onSiteSelect: noop
onSiteSelect: noop,
isPlaceholder: false
};
},

Expand All @@ -60,18 +63,22 @@ export default React.createClass( {
} );
},

toggleOpen() {
this.setState( { open: ! this.state.open } );
},

render() {
return (
<div className={ classNames( 'sites-dropdown', { 'is-open': this.state.open } ) }>
<div className="sites-dropdown__wrapper">
<div
className="sites-dropdown__selected"
onClick={ () => this.setState( { open: ! this.state.open } ) }
>
<Site
site={ this.getSelectedSite() }
indicator={ false }
/>
onClick={ this.toggleOpen } >
{
this.props.isPlaceholder
? <SitePlaceholder />
: <Site site={ this.getSelectedSite() } indicator={ false } />
}
<Gridicon icon="chevron-down" />
</div>
{ this.state.open &&
Expand Down
10 changes: 7 additions & 3 deletions client/components/sites-dropdown/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
}

.gridicons-chevron-down {
align-self: center;
color: lighten( $gray, 10% );
position: absolute;
right: 16px;
top: 22px;
flex-grow: 0;
flex-shrink: 0;
margin-right: 16px;
transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.2s ease-in;
}
}
Expand All @@ -35,6 +36,7 @@

.sites-dropdown__selected {
cursor: pointer;
display: flex;

.is-open & {
border-bottom: 1px solid lighten( $gray, 30% );
Expand Down Expand Up @@ -73,6 +75,8 @@
}

.sites-dropdown .site-selector .site {
flex-grow: 1;

.notouch & {
&:hover {
background: $blue-medium;
Expand Down
24 changes: 16 additions & 8 deletions client/me/account/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import LanguageSelector from 'components/forms/language-selector';
import MeSidebarNavigation from 'me/sidebar-navigation';
import protectForm from 'lib/mixins/protect-form';
import formBase from 'me/form-base';
import SelectSite from 'me/select-site';
import config from 'config';
import Card from 'components/card';
import FormTextInput from 'components/forms/form-text-input';
Expand All @@ -41,6 +40,7 @@ import observe from 'lib/mixins/data-observe';
import eventRecorder from 'me/event-recorder';
import Main from 'components/main';
import SectionHeader from 'components/section-header';
import SitesDropdown from 'components/sites-dropdown';

import _sites from 'lib/sites-list';
import _user from 'lib/user';
Expand Down Expand Up @@ -210,6 +210,13 @@ module.exports = React.createClass( {
} );
},

onSiteSelect( siteSlug ) {
let selectedSite = sites.getSite( siteSlug );
if ( sites.getSite( siteSlug ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

is this a typo? should it be:

if ( selectedSite ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh... you're right 😄 I created the variable so I didn't have to get the site twice, and then I did it anyways 🐼

this.props.userSettings.updateSetting( 'primary_site_ID', 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.

Do we not have a Flux-y action to update the primary site? This looks dangerously entangled here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is specifically for the userSettings module which doesn't have flux. The way we handle data for user and userSettings could definitely use some work.

}
},

renderHolidaySnow() {
// Note that years and months below are zero indexed
const today = this.moment();
Expand Down Expand Up @@ -350,14 +357,15 @@ module.exports = React.createClass( {
);
}

let primarySiteId = this.props.userSettings.getSetting( 'primary_site_ID' );

return (
<SelectSite
disabled={ this.getDisabledState() }
id="primary_site_ID"
name="primary_site_ID"
onFocus={ this.recordFocusEvent( 'Primary Site Field' ) }
sites={ sites }
valueLink={ this.valueLink( 'primary_site_ID' ) } />
<SitesDropdown
key={ primarySiteId }
isPlaceholder={ ! primarySiteId }
selected={ this.props.userSettings.getSetting( 'primary_site_ID' ) }
onSiteSelect={ this.onSiteSelect }
/>
);
},

Expand Down
37 changes: 0 additions & 37 deletions client/me/select-site.jsx

This file was deleted.