-
Notifications
You must be signed in to change notification settings - Fork 1
Fixed bug with filtering and pagination. #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from | |||||
import { DatasetInfo } from "src/app/interface/navigation.interface"; | ||||||
import { MaybeNull } from "src/app/common/app.types"; | ||||||
import { IDropdownSettings } from "ng-multiselect-dropdown"; | ||||||
import { MetadataBlockFragment } from "src/app/api/kamu.graphql.interface"; | ||||||
|
||||||
@Component({ | ||||||
selector: "app-block-navigation", | ||||||
|
@@ -15,6 +16,7 @@ export class BlockNavigationComponent { | |||||
@Input() public datasetHistory: MaybeNull<DatasetHistoryUpdate>; | ||||||
@Input() public currentBlockHash: string; | ||||||
@Input() public datasetInfo: DatasetInfo; | ||||||
@Input() public allHistory: MetadataBlockFragment[]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to initialize this parameter with an empty array, it will help avoid error if for some reason the parameter will be undefined or null.
Suggested change
|
||||||
@Output() public onPageChangeEmit = new EventEmitter<number>(); | ||||||
public searchHash = ""; | ||||||
public currentPage = 1; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { NavigationEnd, Router } from "@angular/router"; | |
import { BlockService } from "./block.service"; | ||
import { AppDatasetSubscriptionsService } from "src/app/dataset-view/dataset.subscriptions.service"; | ||
import _ from "lodash"; | ||
import { MetadataBlockFragment } from "src/app/api/kamu.graphql.interface"; | ||
|
||
@Component({ | ||
selector: "app-metadata-block", | ||
|
@@ -37,6 +38,7 @@ export class MetadataBlockComponent extends BaseProcessingComponent implements O | |
public blockHash: string; | ||
public datasetHistoryUpdate: MaybeNull<DatasetHistoryUpdate> = null; | ||
private blocksPerPage = 10; | ||
public mapHistory = new Map<number, DatasetHistoryUpdate>(); | ||
|
||
ngOnInit(): void { | ||
this.datasetInfo = this.getDatasetInfoFromUrl(); | ||
|
@@ -54,14 +56,31 @@ export class MetadataBlockComponent extends BaseProcessingComponent implements O | |
this.loadMetadataBlock(), | ||
this.loadHistory(), | ||
this.appDatasetSubsService.onDatasetHistoryChanges.subscribe((result: DatasetHistoryUpdate) => { | ||
this.datasetHistoryUpdate = result; | ||
this.mapHistory.set(result.pageInfo.currentPage, result); | ||
if (result.pageInfo.hasNextPage && result.pageInfo.totalPages !== this.mapHistory.size) { | ||
this.loadHistory(result.pageInfo.currentPage + 1); | ||
} | ||
const firstPageHistory = this.mapHistory.get(0); | ||
if (firstPageHistory) { | ||
this.datasetHistoryUpdate = firstPageHistory; | ||
} | ||
Comment on lines
+59
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try implementing a lazy load algorithm. It should request and cache the next page only if really needed, if the consumer keeps asking for more data. Imagine you have a history of a few hundred pages, and the answer to the filter, like 10 events of certain type, is satisfied by the time you processed page 3 (let's say you've found enough nodes to show a page of filtered results), It would be unnecessary to continue loading history. But maybe user requests another 10 events of this type, so you would continue loading to page 8 to satisfy it. Loading hundreds of pages still does not look reasonable. |
||
this.cdr.detectChanges(); | ||
}), | ||
); | ||
} | ||
|
||
public get allHistory(): MetadataBlockFragment[] { | ||
return Array.from(this.mapHistory.values()) | ||
.map((item) => item.history) | ||
.reduce((acc, cur) => [...acc, ...cur], []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks N^2 to me by complexity - you are creating lists and copying all elements + another page's elements on each step. Consider implementing something like a Composite Iterator. |
||
} | ||
|
||
public onPageChange(currentPage: number): void { | ||
this.trackSubscription(this.loadHistory(currentPage - 1)); | ||
const currentHistory = this.mapHistory.get(currentPage - 1); | ||
if (currentHistory) { | ||
this.datasetHistoryUpdate = currentHistory; | ||
this.cdr.detectChanges(); | ||
} | ||
} | ||
|
||
private loadMetadataBlock(): Subscription { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to place
.page-item .page-link
inside the&::ng-deep
, in cease there will be other styles for pagination.Also, yould you please remove parent
&
here& span
? It's not neededCould you please remove
!important
?I think it should work without it.
importatn
is kind of last resort, and should be avoided in most of the cases,usually it could be handled by adding "weight" to selectors - add class/id, or parent, or additional selector in a link
.page-link
, I assume there will be no other text/inline elements