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

SiteSettings: Add timezone section to general settings. #4226

Merged
merged 10 commits into from
Mar 29, 2016
1 change: 0 additions & 1 deletion client/components/select-dropdown/docs/example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var SelectDropdownDemo = React.createClass( {
<a className="design-assets__toggle button" onClick={ this.toggleButtons }>{ toggleButtonsText }</a>
</h2>


<h3>Items passed as options prop</h3>
<SelectDropdown
compact={ this.state.compactButtons }
Expand Down
9 changes: 8 additions & 1 deletion client/components/select-dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ class SelectDropdown extends Component {
} );
}

componentWillReceiveProps() {
componentWillReceiveProps( nextProps ) {
if ( this.state.isOpen ) {
this.closeDropdown();
}

if (
typeof this.state.selected !== 'undefined' &&
this.props.initialSelected !== nextProps.initialSelected
) {
this.setState( { selected: nextProps.initialSelected } );
}
}

componentWillUnmount() {
Expand Down
1 change: 1 addition & 0 deletions client/components/select-dropdown/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
font-size: 14px;
font-weight: 600;
line-height: 18px;
height: 18px;
Copy link
Contributor

Choose a reason for hiding this comment

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

What was happening that required us setting this style? I'm just curious.

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've set this height because before to get the timezones response the dropdown is empty it produces a visual bug like the the following:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yuck, makes sense, thanks.

color: $gray-dark;
transition: background-color 0.2s ease;
cursor: pointer;
Expand Down
8 changes: 4 additions & 4 deletions client/components/timezone-dropdown/docs/example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export default React.createClass( {

getInitialState() {
return {
timezone: 'Tokyo'
timezone: 'UTC+10'
};
},

onTimezoneSelect( zone ) {
console.log( 'timezone selected: %o', zone.value );
this.setState( { timezone: zone.label } );
onTimezoneSelect( timezone ) {
console.log( 'current zone: %o', timezone );
this.setState( { timezone: timezone.value } );
},

render() {
Expand Down
3 changes: 1 addition & 2 deletions client/components/timezone-dropdown/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* External Dependencies
*/
Expand Down Expand Up @@ -83,7 +82,7 @@ class TimezoneDropdown extends Component {
className="timezone-dropdown"
valueLink={ this.props.valueLink }
options={ this.state.timezones }
selectedText={ this.props.selectedZone }
initialSelected={ this.props.selectedZone }
onSelect={ this.onSelect }
/>
);
Expand Down
6 changes: 2 additions & 4 deletions client/lib/mixins/dirty-linked-state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ app.TodoItem = React.createClass( {
mixins: [ dirtyLinkedState ],
render() {
return (
<input type="text" valueLink={ this.linkState( 'blogname' ) } />
<input type="text" valueLink={ this.linkState( 'blogdescription' ) } />
<input type="text" valueLink={ this.linkState( 'blogname' ) } />
<input type="text" valueLink={ this.linkState( 'blogdescription' ) } />
);
}
```
Expand All @@ -42,5 +42,3 @@ After typing:
dirtyFields[ 'blogname' ]
}
```


3 changes: 3 additions & 0 deletions client/lib/wp/sync-handler/whitelist-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import debugFactory from 'debug';
const debug = debugFactory( 'calypso:sync-handler:whitelist' );

const whitelist = [
/^\/wpcom\/v\d\/timezones/,
/^\/me\/posts$/,
/^\/me\/settings/,
/^\/sites\/[\w.]+\/posts$/
Expand All @@ -26,5 +27,7 @@ export const isWhitelisted = params => {
}
}

debug( '%o is not whitelisted', path );

return false;
}
70 changes: 58 additions & 12 deletions client/my-sites/site-settings/form-general.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import FormLabel from 'components/forms/form-label';
import FormRadio from 'components/forms/form-radio';
import FormCheckbox from 'components/forms/form-checkbox';
import FormSettingExplanation from 'components/forms/form-setting-explanation';
import TimezoneDropdown from 'components/timezone-dropdown';

module.exports = React.createClass( {

Expand All @@ -33,9 +34,9 @@ module.exports = React.createClass( {
mixins: [ dirtyLinkedState, protectForm.mixin, formBase ],

getSettingsFromSite( site ) {
var settings;
site = site || this.props.site;
settings = {

const settings = {
blogname: site.name,
blogdescription: site.description,
fetchingSettings: site.fetchingSettings
Expand All @@ -45,6 +46,7 @@ module.exports = React.createClass( {
settings.lang_id = site.settings.lang_id;
settings.blog_public = site.settings.blog_public;
settings.admin_url = site.settings.admin_url;
settings.timezone_string = site.settings.timezone_string;
settings.jetpack_relatedposts_allowed = site.settings.jetpack_relatedposts_allowed;
settings.jetpack_sync_non_public_post_stati = site.settings.jetpack_sync_non_public_post_stati;

Expand All @@ -57,6 +59,19 @@ module.exports = React.createClass( {
if ( site.settings.holidaysnow ) {
settings.holidaysnow = site.settings.holidaysnow;
}

// handling `gmt_offset` and `timezone_string` values
let gmt_offset = site.settings.gmt_offset;

if (
! settings.timezone_string &&
typeof gmt_offset === 'string' &&
gmt_offset.length
) {
settings.timezone_string = 'UTC' +
( /\-/.test( gmt_offset ) ? '' : '+' ) +
gmt_offset;
}
}

return settings;
Expand All @@ -76,6 +91,7 @@ module.exports = React.createClass( {
blogname: '',
blogdescription: '',
lang_id: '',
timezone_string: '',
blog_public: '',
admin_url: '',
jetpack_relatedposts_allowed: false,
Expand All @@ -87,6 +103,18 @@ module.exports = React.createClass( {
} );
},

onTimezoneSelect( timezone ) {
this.setState( { timezone_string: timezone.value } );
},

onRecordEvent( eventAction ) {
return this.recordEvent.bind( this, eventAction );
},

onRecordEventOnce( key, eventAction ) {
return this.recordEventOnce.bind( this, key, eventAction );
},

siteOptions() {
return (
<div>
Expand All @@ -98,9 +126,10 @@ module.exports = React.createClass( {
type="text"
valueLink={ this.linkState( 'blogname' ) }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Site Title Field' ) }
onKeyPress={ this.recordEventOnce.bind( this, 'typedTitle', 'Typed in Site Title Field' ) } />
onClick={ this.onRecordEvent( 'Clicked Site Title Field' ) }
onKeyPress={ this.onRecordEventOnce( 'typedTitle', 'Typed in Site Title Field' ) } />
</FormFieldset>

<FormFieldset>
<FormLabel htmlFor="blogdescription">{ this.translate( 'Site Tagline' ) }</FormLabel>
<FormInput
Expand All @@ -109,12 +138,29 @@ module.exports = React.createClass( {
id="blogdescription"
valueLink={ this.linkState( 'blogdescription' ) }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Site Site Tagline Field' ) }
onKeyPress={ this.recordEventOnce.bind( this, 'typedTagline', 'Typed in Site Site Tagline Field' ) } />
onClick={ this.onRecordEvent( 'Clicked Site Site Tagline Field' ) }
onKeyPress={ this.onRecordEventOnce( 'typedTagline', 'Typed in Site Site Tagline Field' ) } />
<FormSettingExplanation>
{ this.translate( 'In a few words, explain what this site is about.' ) }
</FormSettingExplanation>
</FormFieldset>

<FormFieldset>
<FormLabel htmlFor="blogtimezone">
{ this.translate( 'Site Timezone' ) }
</FormLabel>

<TimezoneDropdown
valueLink={ this.linkState( 'timezone_string' ) }
selectedZone={ this.linkState( 'timezone_string' ).value }
disabled={ this.state.fetchingSettings }
onSelect={ this.onTimezoneSelect }
/>

<FormSettingExplanation>
{ this.translate( 'Choose a city in your timezone.' ) };
</FormSettingExplanation>
</FormFieldset>
</div>
);
},
Expand Down Expand Up @@ -183,7 +229,7 @@ module.exports = React.createClass( {
languages={ config( 'languages' ) }
valueLink={ this.linkState( 'lang_id' ) }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Language Field' ) } />
onClick={ this.onRecordEvent( 'Clicked Language Field' ) } />
<FormSettingExplanation>
{ this.translate( 'Language this blog is primarily written in.' ) }&nbsp;
<a href={ config.isEnabled( 'me/account' ) ? '/me/account' : '/settings/account/' }>
Expand All @@ -206,7 +252,7 @@ module.exports = React.createClass( {
checked={ 1 === parseInt( this.state.blog_public, 10 ) }
onChange={ this.handleRadio }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Site Visibility Radio Button' ) } />
onClick={ this.onRecordEvent( 'Clicked Site Visibility Radio Button' ) } />
<span>{ this.translate( 'Allow search engines to index this site' ) }</span>
</FormLabel>

Expand All @@ -217,7 +263,7 @@ module.exports = React.createClass( {
checked={ 0 === parseInt( this.state.blog_public, 10 ) }
onChange={ this.handleRadio }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Site Visibility Radio Button' ) } />
onClick={ this.onRecordEvent( 'Clicked Site Visibility Radio Button' ) } />
<span>{ this.translate( 'Discourage search engines from indexing this site' ) }</span>
<FormSettingExplanation className="inside-list is-indented">
{ this.translate( 'Note: This option does not block access to your site — it is up to search engines to honor your request.' ) }
Expand All @@ -232,7 +278,7 @@ module.exports = React.createClass( {
checked={ - 1 === parseInt( this.state.blog_public, 10 ) }
onChange={ this.handleRadio }
disabled={ this.state.fetchingSettings }
onClick={ this.recordEvent.bind( this, 'Clicked Site Visibility Radio Button' ) } />
onClick={ this.onRecordEvent( 'Clicked Site Visibility Radio Button' ) } />
<span>{ this.translate( 'I would like my site to be private, visible only to users I choose' ) }</span>
</FormLabel>
}
Expand All @@ -257,7 +303,7 @@ module.exports = React.createClass( {
className="tog"
checked={ 0 === parseInt( this.state.jetpack_relatedposts_enabled, 10 ) }
onChange={ this.handleRadio }
onClick={ this.recordEvent.bind( this, 'Clicked Related Posts Radio Button' ) } />
onClick={ this.onRecordEvent( 'Clicked Related Posts Radio Button' ) } />
<span>{ this.translate( 'Hide related content after posts' ) }</span>
</FormLabel>
</li>
Expand All @@ -269,7 +315,7 @@ module.exports = React.createClass( {
className="tog"
checked={ 1 === parseInt( this.state.jetpack_relatedposts_enabled, 10 ) }
onChange={ this.handleRadio }
onClick={ this.recordEvent.bind( this, 'Clicked Related Posts Radio Button' ) } />
onClick={ this.onRecordEvent( 'Clicked Related Posts Radio Button' ) } />
<span>{ this.translate( 'Show related content after posts' ) }</span>
</FormLabel>
<ul id="settings-reading-relatedposts-customize" className={ 1 === parseInt( this.state.jetpack_relatedposts_enabled, 10 ) ? null : 'disabled-block' }>
Expand Down