Skip to content

Commit

Permalink
Merge pull request #1554 from Automattic/update/plugin-item-selectabl…
Browse files Browse the repository at this point in the history
…e-layout

Plugins: Include action buttons and icon in the plugin-item edit mode
  • Loading branch information
johnHackworth committed Dec 21, 2015
2 parents 05dc334 + 8252efc commit b3b71d3
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 71 deletions.
12 changes: 9 additions & 3 deletions client/components/forms/form-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
}
&:hover {
background: lighten( $gray, 20% );


}
.accessible-focus &:focus{
box-shadow: 0 0 0 2px $blue-medium;
Expand All @@ -47,6 +49,10 @@

.form-toggle__label {
cursor: pointer;

.is-disabled & {
cursor: default;
}
}

.form-toggle {
Expand All @@ -72,9 +78,9 @@
background: $blue-light;
}
}
&:disabled,
&:disabled:hover {
+ .form-toggle__label .form-toggle__switch {
&:disabled {
+ label.form-toggle__label span.form-toggle__switch:hover,
+ label.form-toggle__label span.form-toggle__switch {
background: lighten( $gray, 30% );
cursor: default;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default React.createClass( {
id: `disconnect-jetpack-${ site.ID }`,
className: buttonClasses,
compact: true,
disabled: this.props.disabled,
scary: true,
onClick: ( event ) => {
event.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/plugins/plugin-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ render: function() {
* `inProgress`: (bool) whether the action is in the middle of being performed.
* `htmlFor`: (string) htmlFor is used for creating the for attribute on the label.
* `disabledInfo`: ( string ) text that gets displayed in a infoPopover explaining why the action is disabled.
* `disabled`: ( bool ) whether the toggle is disabled (grayed out and non interactive) or not

2 changes: 1 addition & 1 deletion client/my-sites/plugins/plugin-action/plugin-action.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = React.createClass( {

render: function() {
return (
<div className={ classNames( 'plugin-action', this.props.className ) }>
<div className={ classNames( 'plugin-action', { 'is-disabled': this.props.disabled, 'has-disabled-info': !! this.props.disabledInfo }, this.props.className ) }>
{ this.renderInner() }
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions client/my-sites/plugins/plugin-action/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
vertical-align: top;
text-transform: uppercase;
cursor: pointer;

.is-disabled & {
color: lighten( $gray, 30% );
cursor: default;
}

.has-disabled-info & {
cursor: pointer;
}
}

.plugin-action .form-toggle__label .form-toggle__switch {
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/plugins/plugin-activate-toggle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ render: function() {
* `site`: a site object.
* `notices`: a notices object.
* `isMock`: a boolean indicating if the toggle should not launch any real action when interacted
* `disabled`: a boolean indicating whether the toggle is disabled (grayed out and non interactive) or not
5 changes: 3 additions & 2 deletions client/my-sites/plugins/plugin-activate-toggle/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = React.createClass( {
},

toggleActivation: function() {
if ( this.props.isMock ) {
if ( this.props.isMock || this.props.disabled ) {
return;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = React.createClass( {
htmlFor={ 'disconnect-jetpack-' + this.props.site.ID }
>
<DisconnectJetpackButton
disabled={ ! this.props.plugin }
disabled={ this.props.disabled || ! this.props.plugin }
site={ this.props.site }
redirect="/plugins/jetpack"
/>
Expand All @@ -73,6 +73,7 @@ module.exports = React.createClass( {
}
return (
<PluginAction
disabled={ this.props.disabled }
className="plugin-activate-toggle"
label={ this.translate( 'Active', { context: 'plugin status' } ) }
inProgress={ inProgress }
Expand Down
6 changes: 6 additions & 0 deletions client/my-sites/plugins/plugin-activate-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
font-size: 11px;
color: $alert-red;
text-transform: uppercase;

&:disabled,
&:disabled:hover {
color: lighten( $gray, 30% );
cursor: default;
}
}

.plugin-activate-toggle .plugin-action__children {
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/plugins/plugin-autoupdate-toggle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ render: function() {
* `notices`: a notices object.
* `wporg`: whether the plugin is from .org or not
* `isMock`: a boolean indicating if the toggle should not launch any real action when interacted
* `disabled`: a boolean indicating whether the toggle is disabled (grayed out and non interactive) or not
3 changes: 2 additions & 1 deletion client/my-sites/plugins/plugin-autoupdate-toggle/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = React.createClass( {
},

toggleAutoupdates: function() {
if ( this.props.isMock ) {
if ( this.props.isMock || this.props.disabled ) {
return;
}

Expand Down Expand Up @@ -131,6 +131,7 @@ module.exports = React.createClass( {

return (
<PluginAction
disabled={ this.props.disabled }
label={ label }
status={ this.props.plugin.autoupdate }
action={ this.toggleAutoupdates }
Expand Down
111 changes: 48 additions & 63 deletions client/my-sites/plugins/plugin-item/plugin-item.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
var React = require( 'react/addons' ),
var React = require( 'react' ),
classNames = require( 'classnames' ),
uniq = require( 'lodash/array/uniq' ),
i18n = require( 'lib/mixins/i18n' );
Expand Down Expand Up @@ -141,11 +141,13 @@ module.exports = React.createClass( {
<PluginActivateToggle
isMock={ this.props.isMock }
plugin={ this.props.plugin }
disabled={ this.props.isSelectable }
site={ this.props.selectedSite }
notices={ this.props.notices } />
<PluginAutoupdateToggle
isMock={ this.props.isMock }
plugin={ this.props.plugin }
disabled={ this.props.isSelectable }
site={ this.props.selectedSite }
notices={ this.props.notices }
wporg={ !! this.props.plugin.wporg } />
Expand Down Expand Up @@ -175,19 +177,40 @@ module.exports = React.createClass( {
);
},

onItemClick: function( event ) {
if ( this.props.isSelectable ) {
event.preventDefault();
this.props.onClick( this );
}
},

render: function() {
var pluginTitle,
plugin = this.props.plugin,
errors = this.props.errors ? this.props.errors : [],
numberOfWarningIcons = 0,
errorNotices = [],
errorCounter = 0;
const pluginItemClasses = classNames( 'plugin-item', { disabled: this.props.hasAllNoManageSites } );

if ( ! this.props.plugin ) {
return this.renderPlaceholder();
}

errors.forEach( function( error ) {
errorNotices.push(
<Notice
type='message'
status='is-error'
text={ PluginNotices.getMessage( [ error ], PluginNotices.errorMessage.bind( PluginNotices ) ) }
button={ PluginNotices.getErrorButton( error ) }
href={ PluginNotices.getErrorHref( error ) }
raw={ { onRemoveCallback: PluginsActions.removePluginsNotices.bind( this, [ error ] ) } }
inline={ true }
key={ 'notice-' + errorCounter } />
);
errorCounter++;
}, this );

if ( this.props.hasNoManageSite ) {
numberOfWarningIcons++;
}
Expand All @@ -202,60 +225,10 @@ module.exports = React.createClass( {
</div>
);

if ( this.props.isSelectable ) {
errors.forEach( function( error ) {
let action = null;

if ( PluginNotices.getErrorButton( error ) ) {
action = (
<NoticeAction href={ PluginNotices.getErrorHref( error ) }>
{ PluginNotices.getErrorButton( error ) }
</NoticeAction>
);
}

errorNotices.push(
<Notice
type='message'
status='is-error'
showDismiss={ false }
text={ PluginNotices.getMessage( [ error ], PluginNotices.errorMessage.bind( PluginNotices ) ) }
inline={ true }
key={ 'notice-' + errorCounter }
>
{ action }
</Notice>
);
errorCounter++;
}, this );
return (
<div>
<CompactCard className={ pluginItemClasses }>
<input
className="plugin-item__checkbox"
id={ plugin.slug }
type="checkbox"
onClick={ this.props.onClick }
checked={ this.props.isSelected }
readOnly={ true }
/>
<label className="plugin-item__label" htmlFor={ plugin.slug }>
<span className="screen-reader-text">
{ this.translate( 'Toggle selection of %(plugin)s', { args: { plugin: plugin.name } } ) }
</span>
</label>
<div className="plugin-item__info">
{ pluginTitle }
{ this.pluginMeta( plugin ) }
</div>
</CompactCard>
<div className="plugin-item__error-notices">
{ errorNotices }
</div>
</div>
);
}
if ( this.props.hasAllNoManageSites ) {
const pluginItemClasses = classNames( 'plugin-item', {
disabled: this.props.hasAllNoManageSites,
} );
return (
<div className="plugin-item__wrapper">
<CompactCard className={ pluginItemClasses }
Expand All @@ -275,14 +248,26 @@ module.exports = React.createClass( {
);
}
return (
<CompactCard className="plugin-item">
<a href={ this.props.pluginLink } className="plugin-item__link">
<PluginIcon image={ plugin.icon }/>
{ pluginTitle }
{ this.pluginMeta( plugin ) }
</a>
{ this.props.selectedSite ? this.renderActions() : this.renderCount() }
</CompactCard>
<div>
<CompactCard className="plugin-item">
{ ! this.props.isSelectable
? null
: <input className="plugin-item__checkbox"
id={ plugin.slug }
type="checkbox"
onClick={ this.props.onClick }
checked={ this.props.isSelected }
readOnly={ true } />
}
<a href={ this.props.pluginLink } onClick={ this.onItemClick } className="plugin-item__link">
<PluginIcon image={ plugin.icon }/>
{ pluginTitle }
{ this.pluginMeta( plugin ) }
</a>
{ this.props.selectedSite ? this.renderActions() : this.renderCount() }
</CompactCard>
{ errorNotices }
</div>
);
}

Expand Down
24 changes: 23 additions & 1 deletion client/my-sites/plugins/plugin-item/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
.plugin-item.card {
padding: 0;

.is-bulk-editing & {
padding-left: 24px;
}

& ~ .notice.is-error {
margin-bottom: 0;
}

input {
margin-right: 8px;
}

@include breakpoint( '>660px' ) {
padding: 0;
}
Expand Down Expand Up @@ -37,7 +49,6 @@

.plugin-item__link,
.plugin-item__disabled,
.is-bulk-editing .plugin-item,
.plugin-item.is-placeholder {
display: block;
flex-grow: 1;
Expand All @@ -53,6 +64,17 @@
}
}

.plugin-item__link {
.is-bulk-editing & {
padding-left: 40px;
}
}

.plugin-item__disabled {
opacity: 0.5;
background: $gray-light;
}

// Checkbox for multiselect purposes
.plugin-item__checkbox[type=checkbox] {
position: absolute;
Expand Down

0 comments on commit b3b71d3

Please sign in to comment.