Allowed ability to set default sort_by/order on listings
- improved performance of listings (less refresh of items) - fixed sorting issue where the order would not be reversed
This commit is contained in:
@@ -1,98 +1,91 @@
|
|||||||
define([
|
import MailPoet from 'mailpoet'
|
||||||
'react',
|
import React from 'react'
|
||||||
'classnames',
|
import classNames from 'classnames'
|
||||||
'mailpoet'
|
|
||||||
], function(
|
|
||||||
React,
|
|
||||||
classNames,
|
|
||||||
MailPoet
|
|
||||||
) {
|
|
||||||
|
|
||||||
var ListingHeader = React.createClass({
|
|
||||||
handleSelectItems: function() {
|
|
||||||
return this.props.onSelectItems(
|
|
||||||
this.refs.toggle.checked
|
|
||||||
);
|
|
||||||
},
|
|
||||||
render: function() {
|
|
||||||
var columns = this.props.columns.map(function(column, index) {
|
|
||||||
column.is_primary = (index === 0);
|
|
||||||
column.sorted = (this.props.sort_by === column.name)
|
|
||||||
? this.props.sort_order
|
|
||||||
: 'desc';
|
|
||||||
return (
|
|
||||||
<ListingColumn
|
|
||||||
onSort={this.props.onSort}
|
|
||||||
sort_by={this.props.sort_by}
|
|
||||||
key={ 'column-' + index }
|
|
||||||
column={column} />
|
|
||||||
);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
var checkbox = false;
|
|
||||||
|
|
||||||
if(this.props.is_selectable === true) {
|
|
||||||
checkbox = (
|
|
||||||
<th
|
|
||||||
className="manage-column column-cb check-column">
|
|
||||||
<label className="screen-reader-text">
|
|
||||||
{MailPoet.I18n.t('selectAll')}
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
name="select_all"
|
|
||||||
ref="toggle"
|
|
||||||
checked={ this.props.selection }
|
|
||||||
onChange={ this.handleSelectItems } />
|
|
||||||
</th>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const ListingHeader = React.createClass({
|
||||||
|
handleSelectItems: function() {
|
||||||
|
return this.props.onSelectItems(
|
||||||
|
this.refs.toggle.checked
|
||||||
|
);
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
const columns = this.props.columns.map(function(column, index) {
|
||||||
|
column.is_primary = (index === 0);
|
||||||
|
column.sorted = (this.props.sort_by === column.name)
|
||||||
|
? this.props.sort_order
|
||||||
|
: 'desc';
|
||||||
return (
|
return (
|
||||||
<tr>
|
<ListingColumn
|
||||||
{checkbox}
|
onSort={this.props.onSort}
|
||||||
{columns}
|
sort_by={this.props.sort_by}
|
||||||
</tr>
|
key={ 'column-' + index }
|
||||||
|
column={column} />
|
||||||
);
|
);
|
||||||
}
|
}.bind(this));
|
||||||
});
|
|
||||||
|
|
||||||
var ListingColumn = React.createClass({
|
let checkbox;
|
||||||
handleSort: function() {
|
|
||||||
var sort_by = this.props.column.name,
|
|
||||||
sort_order = (this.props.column.sorted === 'asc') ? 'desc' : 'asc';
|
|
||||||
this.props.onSort(sort_by, sort_order);
|
|
||||||
},
|
|
||||||
render: function() {
|
|
||||||
var classes = classNames(
|
|
||||||
'manage-column',
|
|
||||||
{ 'column-primary': this.props.column.is_primary },
|
|
||||||
{ 'sortable': this.props.column.sortable },
|
|
||||||
this.props.column.sorted,
|
|
||||||
{ 'sorted': (this.props.sort_by === this.props.column.name) }
|
|
||||||
);
|
|
||||||
var label;
|
|
||||||
|
|
||||||
if(this.props.column.sortable === true) {
|
if(this.props.is_selectable === true) {
|
||||||
label = (
|
checkbox = (
|
||||||
<a onClick={this.handleSort}>
|
|
||||||
<span>{ this.props.column.label }</span>
|
|
||||||
<span className="sorting-indicator"></span>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
label = this.props.column.label;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<th
|
<th
|
||||||
className={ classes }
|
className="manage-column column-cb check-column">
|
||||||
id={this.props.column.name }
|
<label className="screen-reader-text">
|
||||||
scope="col"
|
{MailPoet.I18n.t('selectAll')}
|
||||||
width={ this.props.column.width || null }
|
</label>
|
||||||
>{label}</th>
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="select_all"
|
||||||
|
ref="toggle"
|
||||||
|
checked={ this.props.selection }
|
||||||
|
onChange={ this.handleSelectItems } />
|
||||||
|
</th>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return ListingHeader;
|
return (
|
||||||
|
<tr>
|
||||||
|
{checkbox}
|
||||||
|
{columns}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ListingColumn = React.createClass({
|
||||||
|
handleSort: function() {
|
||||||
|
const sort_by = this.props.column.name;
|
||||||
|
const sort_order = (this.props.column.sorted === 'asc') ? 'desc' : 'asc';
|
||||||
|
this.props.onSort(sort_by, sort_order);
|
||||||
|
},
|
||||||
|
render: function() {
|
||||||
|
const classes = classNames(
|
||||||
|
'manage-column',
|
||||||
|
{ 'column-primary': this.props.column.is_primary },
|
||||||
|
{ 'sortable': this.props.column.sortable },
|
||||||
|
this.props.column.sorted,
|
||||||
|
{ 'sorted': (this.props.sort_by === this.props.column.name) }
|
||||||
|
);
|
||||||
|
let label;
|
||||||
|
|
||||||
|
if(this.props.column.sortable === true) {
|
||||||
|
label = (
|
||||||
|
<a onClick={ this.handleSort }>
|
||||||
|
<span>{ this.props.column.label }</span>
|
||||||
|
<span className="sorting-indicator"></span>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
label = this.props.column.label;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
className={ classes }
|
||||||
|
id={this.props.column.name }
|
||||||
|
scope="col"
|
||||||
|
width={ this.props.column.width || null }
|
||||||
|
>{label}</th>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = ListingHeader;
|
File diff suppressed because it is too large
Load Diff
@@ -244,6 +244,8 @@ const SegmentList = React.createClass({
|
|||||||
columns={ columns }
|
columns={ columns }
|
||||||
bulk_actions={ bulk_actions }
|
bulk_actions={ bulk_actions }
|
||||||
item_actions={ item_actions }
|
item_actions={ item_actions }
|
||||||
|
sort_by="name"
|
||||||
|
sort_order="asc"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@@ -27,8 +27,8 @@ class Handler {
|
|||||||
// searching
|
// searching
|
||||||
'search' => (isset($data['search']) ? $data['search'] : null),
|
'search' => (isset($data['search']) ? $data['search'] : null),
|
||||||
// sorting
|
// sorting
|
||||||
'sort_by' => (isset($data['sort_by']) ? $data['sort_by'] : 'id'),
|
'sort_by' => (!empty($data['sort_by']) ? $data['sort_by'] : 'id'),
|
||||||
'sort_order' => (isset($data['sort_order']) ? $data['sort_order'] : 'asc'),
|
'sort_order' => (!empty($data['sort_order']) ? $data['sort_order'] : 'asc'),
|
||||||
// grouping
|
// grouping
|
||||||
'group' => (isset($data['group']) ? $data['group'] : null),
|
'group' => (isset($data['group']) ? $data['group'] : null),
|
||||||
// filters
|
// filters
|
||||||
|
Reference in New Issue
Block a user