Browse Source

Fixed empty last page in Alarms, Entities and Time series table widgets when data decreases

pull/16705/head
Maksym Tsymbarov 2 months ago
parent
commit
a115ec8247
  1. 16
      ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts
  2. 16
      ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts
  3. 6
      ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts

16
ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts

@ -327,6 +327,16 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
this.paginator.firstPage();
}
});
this.alarmsDatasource.totalPages().pipe(
debounceTime(0),
takeUntil(this.destroy$)
).subscribe((totalPages) => {
if (this.paginator.pageIndex > 0 && this.paginator.pageIndex >= totalPages) {
this.paginator.pageIndex = Math.max(totalPages - 1, 0);
this.updateData();
}
});
}
((this.displayPagination ? merge(this.sort.sortChange, this.paginator.page) : this.sort.sortChange) as Observable<any>).pipe(
takeUntil(this.destroy$)
@ -1401,6 +1411,12 @@ class AlarmsDatasource implements DataSource<AlarmDataInfo> {
);
}
totalPages(): Observable<number> {
return this.pageDataSubject.pipe(
map((pageData) => pageData.totalPages)
);
}
toggleSelection(alarm: AlarmDataInfo) {
const hasValue = this.selection.hasValue();
this.selection.toggle(alarm);

16
ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts

@ -261,6 +261,16 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
this.paginator.firstPage();
}
});
this.entityDatasource.totalPages().pipe(
debounceTime(0),
takeUntil(this.destroy$)
).subscribe((totalPages) => {
if (this.paginator.pageIndex > 0 && this.paginator.pageIndex >= totalPages) {
this.paginator.pageIndex = Math.max(totalPages - 1, 0);
this.updateData();
}
});
}
((this.displayPagination ? merge(this.sort.sortChange, this.paginator.page) : this.sort.sortChange) as Observable<any>).pipe(
takeUntil(this.destroy$)
@ -997,6 +1007,12 @@ class EntityDatasource implements DataSource<EntityData> {
);
}
totalPages(): Observable<number> {
return this.pageDataSubject.pipe(
map((pageData) => pageData.totalPages)
);
}
public toggleCurrentEntity(entity: EntityData): boolean {
if (this.currentEntity !== entity) {
this.currentEntity = entity;

6
ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts

@ -1039,7 +1039,11 @@ class TimeseriesDatasource implements DataSource<TimeseriesRow> {
switchMap(() => {
return this.allRows$.pipe(
map((data) => {
const fetchData = pageLink.filterData(data);
let fetchData = pageLink.filterData(data);
if (pageLink.page > 0 && pageLink.page >= fetchData.totalPages) {
pageLink.page = Math.max(fetchData.totalPages - 1, 0);
fetchData = pageLink.filterData(data);
}
if (this.cellButtonActions.length) {
let maxCellButtonAction: number;
if (this.usedShowCellActionFunction && !this.reserveSpaceForHiddenAction) {

Loading…
Cancel
Save