onChangeItemsPerPage update

This commit is contained in:
Greg Thompson 2022-03-04 14:36:56 -06:00
parent 46f433eac3
commit 127c9e5840
No known key found for this signature in database
GPG key ID: ED1F695C1077B958

View file

@ -65,7 +65,7 @@ interface SavedObjectFinderState {
query: string;
isFetchingItems: boolean;
page: number;
perPage: number;
perPage: number | 'all';
sortDirection?: Direction;
sortOpen: boolean;
filterOpen: boolean;
@ -213,6 +213,9 @@ class SavedObjectFinderUi extends React.Component<
}
private getPageCount() {
if (this.state.perPage === 'all') {
return 1;
}
return Math.ceil(
(this.state.filteredTypes.length === 0
? this.state.items.length
@ -244,9 +247,9 @@ class SavedObjectFinderUi extends React.Component<
}
// If begin is greater than the length of the sequence, an empty array is returned.
const startIndex = this.state.page * this.state.perPage;
const startIndex = this.state.perPage === 'all' ? 1 : this.state.page * this.state.perPage;
// If end is greater than the length of the sequence, slice extracts through to the end of the sequence (arr.length).
const lastIndex = startIndex + this.state.perPage;
const lastIndex = this.state.perPage === 'all' ? items.length : startIndex + this.state.perPage;
return items
.filter(
(item) =>