Skip to content

Commit

Permalink
onChangeItemsPerPage update
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed Mar 4, 2022
1 parent 46f433e commit 127c9e5
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface SavedObjectFinderState {
query: string;
isFetchingItems: boolean;
page: number;
perPage: number;
perPage: number | 'all';
sortDirection?: Direction;
sortOpen: boolean;
filterOpen: boolean;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) =>
Expand Down

0 comments on commit 127c9e5

Please sign in to comment.