[MNT-22924] Fix slow search results loading, limit number of pages (#7609)

* [MNT-22924] Fix slow search results loading, limit number of pages

* Add unit test

* Changed some of the values
This commit is contained in:
Thomas Hunter
2022-05-11 09:53:05 +01:00
committed by GitHub
parent fd0626391c
commit e844faff79
3 changed files with 36 additions and 3 deletions

View File

@@ -214,6 +214,20 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
.map((_, index) => (index + 1));
}
get limitedPages(): number[] {
if (this.lastPage <= 100) {
return this.pages;
}
const twentyItems = Array.from(Array(20));
return [
1,
...twentyItems.map((_, i) => this.current - i - 1).reverse(),
this.current,
...twentyItems.map((_, i) => this.current + i + 1),
this.lastPage
].filter((value: number, index: number, array: number[]) => value > 0 && value <= this.lastPage && !array.slice(0, index).includes(value));
}
get itemRangeText(): string {
const rangeString = this.range.join('-');