Listing method update for Newsletters/Forms/Segments/Subscribers

- updated unit tests
This commit is contained in:
Jonathan Labreuille
2016-09-08 14:34:21 +02:00
parent d6eaa4ac8a
commit 0c5589a3e3
10 changed files with 123 additions and 86 deletions

View File

@@ -456,20 +456,28 @@ const Listing = React.createClass({
sort_by: this.state.sort_by,
sort_order: this.state.sort_order
}
}).always(() => {
this.setState({ loading: false });
}).done((response) => {
this.setState({
items: response.items || [],
filters: response.filters || {},
groups: response.groups || [],
count: response.count || 0,
loading: false
items: response.data || [],
filters: response.meta.filters || {},
groups: response.meta.groups || [],
count: response.meta.count || 0
}, () => {
// if viewing an empty trash
if (this.state.group === 'trash' && response.count === 0) {
if (this.state.group === 'trash' && response.meta.count === 0) {
// redirect to default group
this.handleGroup('all');
}
});
}).fail(function(response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
{ scroll: true }
);
}
});
}
},