diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts index 39847a1e45..22f4a69cc0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts @@ -210,6 +210,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, private subscription: IWidgetSubscription; private widgetResize$: ResizeObserver; private destroy$ = new Subject(); + private paginationResetsSubscription: Subscription; private displayActivity = false; private displayDetails = true; @@ -315,6 +316,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, if (this.widgetResize$) { this.widgetResize$.disconnect(); } + this.paginationResetsSubscription?.unsubscribe(); this.destroy$.next(); this.destroy$.complete(); } @@ -331,7 +333,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, }); if (this.displayPagination) { - setupPaginationResets(this.ctx, this.paginator, this.sort, this.destroy$); + this.paginationResetsSubscription = setupPaginationResets(this.ctx, this.paginator, this.sort); this.ctx.aliasController?.filtersChanged.pipe( takeUntil(this.destroy$) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts index d8fb02c372..1f129828f5 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts @@ -46,7 +46,7 @@ import { deepClone, hashCode, isDefined, isDefinedAndNotNull, isObject, isUndefi import cssjs from '@core/css/css'; import { CollectionViewer, DataSource } from '@angular/cdk/collections'; import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; -import { BehaviorSubject, fromEvent, merge, Observable, of, Subject } from 'rxjs'; +import { BehaviorSubject, fromEvent, merge, Observable, of, Subject, Subscription } from 'rxjs'; import { emptyPageData, PageData } from '@shared/models/page/page-data'; import { EntityId } from '@shared/models/id/entity-id'; import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models'; @@ -165,6 +165,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni private subscription: IWidgetSubscription; private widgetResize$: ResizeObserver; private destroy$ = new Subject(); + private paginationResetsSubscription: Subscription; private defaultPageSize; private defaultSortOrder = 'entityName'; @@ -248,6 +249,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni if (this.widgetResize$) { this.widgetResize$.disconnect(); } + this.paginationResetsSubscription?.unsubscribe(); this.destroy$.next(); this.destroy$.complete(); } @@ -266,7 +268,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni }); if (this.displayPagination) { - setupPaginationResets(this.ctx, this.paginator, this.sort, this.destroy$); + this.paginationResetsSubscription = setupPaginationResets(this.ctx, this.paginator, this.sort); this.ctx.aliasController?.filtersChanged.pipe( takeUntil(this.destroy$) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts index f7587f8356..3d3a956790 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts @@ -33,7 +33,7 @@ import { TbFunction } from '@shared/models/js-function.models'; import { forkJoin, Observable, of, ReplaySubject, Subscription } from 'rxjs'; -import { catchError, distinctUntilChanged, map, share, skip, startWith, takeUntil } from 'rxjs/operators'; +import { catchError, distinctUntilChanged, map, share, skip, startWith } from 'rxjs/operators'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import type { ValueFormatProcessor } from '@shared/models/widget-settings.models'; @@ -521,14 +521,11 @@ export function isValidPageStepCount(value: number): boolean { export function setupPaginationResets(ctx: WidgetContext, paginator: MatPaginator, - sort: MatSort, - destroyNotifier$: Observable): Subscription { + sort: MatSort): Subscription { const subscription = new Subscription(); subscription.add( - sort.sortChange.pipe( - takeUntil(destroyNotifier$) - ).subscribe(() => paginator.pageIndex = 0) + sort.sortChange.subscribe(() => paginator.pageIndex = 0) ); subscription.add( @@ -536,8 +533,7 @@ export function setupPaginationResets(ctx: WidgetContext, map(() => ctx.stateController.getStateParams()), startWith(ctx.stateController.getStateParams()), distinctUntilChanged(isEqual), - skip(1), - takeUntil(destroyNotifier$) + skip(1) ).subscribe(() => paginator.firstPage()) ); return subscription; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts index 91f44664fb..f269428f6b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts @@ -287,6 +287,9 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI if (this.widgetResize$) { this.widgetResize$.disconnect(); } + this.subscriptions.forEach(subscription => subscription.unsubscribe()); + this.destroy$.next(); + this.destroy$.complete(); } ngAfterViewInit(): void { @@ -654,7 +657,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI if (this.displayPagination) { paginator = this.paginators.toArray()[index]; this.subscriptions.push( - setupPaginationResets(this.ctx, paginator, sort, this.destroy$) + setupPaginationResets(this.ctx, paginator, sort) ); observables.push(paginator.page); }