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

Site Settings: Hide the delete site notice if the site is not loaded yet #2983

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Changes from all 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
34 changes: 23 additions & 11 deletions client/my-sites/site-settings/delete-site/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var HeaderCake = require( 'components/header-cake' ),
Button = require( 'components/button' ),
Dialog = require( 'components/dialog' ),
config = require( 'config' ),
Gridicon = require ( 'components/gridicon' ),
Gridicon = require( 'components/gridicon' ),
SiteListActions = require( 'lib/sites-list/actions' );

module.exports = React.createClass( {
Expand All @@ -45,6 +45,27 @@ module.exports = React.createClass( {
this.props.sites.off( 'change', this._updateSite );
},

renderNotice: function() {
var site = this.state.site;

if ( ! site ) {
return null;
}

return (
<Notice status="is-warning" showDismiss={ false }>
{ this.translate( '{{strong}}%(domain)s{{/strong}} will be unavailable in the future.', {
components: {
strong: <strong />
},
args: {
domain: site.domain
}
} ) }
</Notice>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could reduce the length of this function by doing the opposite - which I find more logic by the way:

renderNotice: function() {
  var site = this.state.site;

  if ( site ) {
    return (
      <Notice status="is-warning" showDismiss={ false }>
        { this.translate( '{{strong}}%(domain)s{{/strong}} will be unavailable in the future.', {
          components: {
            strong: <strong />
          },
          args: {
            domain: site.domain
          }
        } ) }
      </Notice>
    );
  }
},

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if there is a benefit either way, but if it is arbitrary, my preference is for the way @Tug implemented it, because:

  • It works with multiple conditions that bail out early (example from ManagePurchase):
if ( ! isRenewable( purchase ) && ! isRedeemable( purchase ) ) {
    return null;
}

if ( ! isExpired( purchase ) ) {
    return null;
}
  • It's easier (for me) to read JSX that isn't wrapped in an extra block/blocks.

},

render: function() {
var site = this.state.site,
adminURL = site.options && site.options.admin_url ? site.options.admin_url : '',
Expand Down Expand Up @@ -113,16 +134,7 @@ module.exports = React.createClass( {
<ActionPanel>
<ActionPanelTitle>{ strings.deleteSite }</ActionPanelTitle>
<ActionPanelBody>
<Notice status="is-warning" showDismiss={ false }>
{ this.translate( '{{strong}}%(domain)s{{/strong}} will be unavailable in the future.', {
components: {
strong: <strong />
},
args: {
domain: site.domain
}
} ) }
</Notice>
{ this.renderNotice() }
<ActionPanelFigure>
<h3 className="delete-site__content-list-header">{ this.translate( 'These items will be deleted' ) }</h3>
<ul className="delete-site__content-list">
Expand Down