[ML] Fixes job list page index when deleting jobs off last page (#27481)

This commit is contained in:
Pete Harverson 2018-12-19 11:05:42 +00:00 committed by GitHub
parent 3f2d08e8da
commit 746ed07505
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,12 +78,13 @@ class JobsListUI extends Component {
let list = this.state.jobsSummaryList;
list = sortBy(this.state.jobsSummaryList, (item) => item[sortField]);
list = (sortDirection === 'asc') ? list : list.reverse();
const listLength = list.length;
let pageStart = (index * size);
if (pageStart >= list.length) {
// if the page start is larger than the number of items
// due to filters being applied, calculate a new page start
pageStart = Math.floor(list.length / size) * size;
if (pageStart >= listLength && (listLength !== 0)) {
// if the page start is larger than the number of items due to
// filters being applied or jobs being deleted, calculate a new page start
pageStart = Math.floor((listLength - 1) / size) * size;
// set the state out of the render cycle
setTimeout(() => {
this.setState({
@ -93,7 +94,7 @@ class JobsListUI extends Component {
}
return {
pageOfItems: list.slice(pageStart, (pageStart + size)),
totalItemCount: list.length,
totalItemCount: listLength,
};
}