Segments page review

- remove edit link for WordPress users list
- hide trashed segments from Import
- fixed display issue in listing's item actions
This commit is contained in:
Jonathan Labreuille
2016-02-12 11:30:08 +01:00
parent 214aa60d0e
commit e928a5c2bc
4 changed files with 26 additions and 13 deletions

View File

@ -74,10 +74,11 @@ define(
); );
} }
var custom_actions = this.props.item_actions; const custom_actions = this.props.item_actions;
var item_actions = false; let item_actions = false;
if(custom_actions.length > 0) { if(custom_actions.length > 0) {
let is_first = true;
item_actions = custom_actions.map(function(action, index) { item_actions = custom_actions.map(function(action, index) {
if(action.display !== undefined) { if(action.display !== undefined) {
if(action.display(this.props.item) === false) { if(action.display(this.props.item) === false) {
@ -85,10 +86,12 @@ define(
} }
} }
let custom_action = null;
if(action.name === 'trash') { if(action.name === 'trash') {
return ( custom_action = (
<span key={ 'action-'+index } className="trash"> <span key={ 'action-'+index } className="trash">
{(index > 0) ? ' | ' : ''} {(!is_first) ? ' | ' : ''}
<a <a
href="javascript:;" href="javascript:;"
onClick={ this.handleTrashItem.bind( onClick={ this.handleTrashItem.bind(
@ -100,27 +103,27 @@ define(
</span> </span>
); );
} else if(action.refresh) { } else if(action.refresh) {
return ( custom_action = (
<span <span
onClick={ this.props.onRefreshItems } onClick={ this.props.onRefreshItems }
key={ 'action-'+index } className={ action.name }> key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''} {(!is_first) ? ' | ' : ''}
{ action.link(this.props.item) } { action.link(this.props.item) }
</span> </span>
); );
} else if(action.link) { } else if(action.link) {
return ( custom_action = (
<span <span
key={ 'action-'+index } className={ action.name }> key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''} {(!is_first) ? ' | ' : ''}
{ action.link(this.props.item) } { action.link(this.props.item) }
</span> </span>
); );
} else { } else {
return ( custom_action = (
<span <span
key={ 'action-'+index } className={ action.name }> key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''} {(!is_first) ? ' | ' : ''}
<a href="javascript:;" onClick={ <a href="javascript:;" onClick={
(action.onClick !== undefined) (action.onClick !== undefined)
? action.onClick.bind(null, ? action.onClick.bind(null,
@ -132,6 +135,12 @@ define(
</span> </span>
); );
} }
if(custom_action !== null && is_first === true) {
is_first = false;
}
return custom_action;
}.bind(this)); }.bind(this));
} else { } else {
item_actions = ( item_actions = (

View File

@ -12,7 +12,7 @@ define(
Form Form
) { ) {
var fields = [ let fields = [
{ {
name: 'name', name: 'name',
label: 'Name', label: 'Name',
@ -25,7 +25,7 @@ define(
} }
]; ];
var messages = { const messages = {
onUpdate: function() { onUpdate: function() {
MailPoet.Notice.success('Segment successfully updated!'); MailPoet.Notice.success('Segment successfully updated!');
}, },
@ -34,7 +34,7 @@ define(
} }
}; };
var SegmentForm = React.createClass({ const SegmentForm = React.createClass({
mixins: [ mixins: [
Router.History Router.History
], ],

View File

@ -96,6 +96,9 @@ const item_actions = [
return ( return (
<Link to={ `/edit/${item.id}` }>Edit</Link> <Link to={ `/edit/${item.id}` }>Edit</Link>
); );
},
display: function(segment) {
return (segment.type !== 'wp_users');
} }
}, },
{ {

View File

@ -122,6 +122,7 @@ class Segment extends Model {
->group_by(self::$_table.'.id') ->group_by(self::$_table.'.id')
->group_by(self::$_table.'.name') ->group_by(self::$_table.'.name')
->where(self::$_table.'.type', 'default') ->where(self::$_table.'.type', 'default')
->whereNull(self::$_table.'.deleted_at')
->findArray(); ->findArray();
} }