From a64b45996465becba143e74310d9c4384016d3ef Mon Sep 17 00:00:00 2001 From: Pavel Grim Date: Tue, 12 Aug 2025 13:16:48 +0200 Subject: [PATCH] Revert "OO-49414 Ability to disable refreshers globaly (#766)" This reverts commit 5c09f4d0ae8bd9c116290cbb85b33fc85c27354d. --- docs/CHANGELOG.md | 6 --- .../providers/refresher-settings.service.ts | 13 +++--- .../components/providers/refresher.spec.ts | 40 ++++--------------- .../src/lib/components/providers/refresher.ts | 26 ++++++------ 4 files changed, 24 insertions(+), 61 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1b94808ec..936a7a748 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,11 +1,5 @@ # Changelog -## [17.0.1] 📅 2025-07-31 - -### Added - -- `@nova-ui/dashboards` | Added ability to globaly disable refreshers - ## [17.0.0] 📅 2025-04-20 ### Angular upgrade 17 diff --git a/packages/dashboards/src/lib/components/providers/refresher-settings.service.ts b/packages/dashboards/src/lib/components/providers/refresher-settings.service.ts index e7f32b646..d09d92f95 100644 --- a/packages/dashboards/src/lib/components/providers/refresher-settings.service.ts +++ b/packages/dashboards/src/lib/components/providers/refresher-settings.service.ts @@ -30,22 +30,19 @@ import { DEFAULT_REFRESH_INTERVAL } from "./types"; providedIn: "root", }) export class RefresherSettingsService { - /** - * This is a system wide definition for disabling all refreshers. - */ - public readonly disabled$ = new BehaviorSubject(false); - - public readonly refreshRateSeconds$ = new BehaviorSubject(DEFAULT_REFRESH_INTERVAL); + private _refreshRateSeconds: number = DEFAULT_REFRESH_INTERVAL; + public refreshRateSeconds$ = new BehaviorSubject(this.refreshRateSeconds); /** * This is a system wide definition of refresh rate. Widgets have to be configured to use * the system settings to leverage this value. */ public get refreshRateSeconds(): number { - return this.refreshRateSeconds$.value; + return this._refreshRateSeconds; } public set refreshRateSeconds(value: number) { - this.refreshRateSeconds$.next(value); + this._refreshRateSeconds = value; + this.refreshRateSeconds$.next(this._refreshRateSeconds); } } diff --git a/packages/dashboards/src/lib/components/providers/refresher.spec.ts b/packages/dashboards/src/lib/components/providers/refresher.spec.ts index 8dbb3c6fe..cb843a938 100644 --- a/packages/dashboards/src/lib/components/providers/refresher.spec.ts +++ b/packages/dashboards/src/lib/components/providers/refresher.spec.ts @@ -40,11 +40,9 @@ describe("Refresher > ", () => { }); beforeEach(() => { - eventBus = new EventBus(); + eventBus = new EventBus(); refresherSettings = new RefresherSettingsService(); - TestBed.runInInjectionContext(() => { - refresher = new Refresher(eventBus, ngZone, refresherSettings); - }); + refresher = new Refresher(eventBus, ngZone, refresherSettings); }); describe("updateConfiguration > ", () => { @@ -66,20 +64,16 @@ describe("Refresher > ", () => { describe("ngOnDestroy > ", () => { it("should clear the interval", fakeAsync(() => { - const spy = spyOn(eventBus.getStream(REFRESH), "next"); - refresher.updateConfiguration({}); - // Sanity check - tick(DEFAULT_REFRESH_INTERVAL * 1000); - expect(spy).toHaveBeenCalledTimes(1); - // Verify + refresher = new Refresher(eventBus, ngZone, refresherSettings); refresher.ngOnDestroy(); - tick(DEFAULT_REFRESH_INTERVAL * 1000 * 2); - expect(spy).toHaveBeenCalledTimes(1); + const spy = spyOn(eventBus.getStream(REFRESH), "next"); + tick(DEFAULT_REFRESH_INTERVAL * 2); + expect(spy).toHaveBeenCalledTimes(0); })); }); describe("refresherSettings", () => { - it("updates interval when global settings interval changes", fakeAsync(() => { + it("updates interval when global settings change", fakeAsync(() => { refresherSettings.refreshRateSeconds = 1; refresher.updateConfiguration({ overrideDefaultSettings: false }); const spy = spyOn(eventBus.getStream(REFRESH), "next"); @@ -94,25 +88,5 @@ describe("Refresher > ", () => { expect(spy).toHaveBeenCalledTimes(2); refresher.ngOnDestroy(); })); - - it("disables interval when global disabled settings changes", fakeAsync(() => { - refresher.updateConfiguration({}); - const spy = spyOn(eventBus.getStream(REFRESH), "next"); - // Sanity check - tick(DEFAULT_REFRESH_INTERVAL * 1000); - expect(spy).toHaveBeenCalledTimes(1); - - // Verify disabling - refresherSettings.disabled$.next(true); - tick(DEFAULT_REFRESH_INTERVAL * 1000 * 10); - expect(spy).toHaveBeenCalledTimes(1); - - // Verify enabling - refresherSettings.disabled$.next(false); - tick(DEFAULT_REFRESH_INTERVAL * 1000); - expect(spy).toHaveBeenCalledTimes(2); - - refresher.ngOnDestroy(); - })); }); }); diff --git a/packages/dashboards/src/lib/components/providers/refresher.ts b/packages/dashboards/src/lib/components/providers/refresher.ts index f1c5a893f..fff93da25 100644 --- a/packages/dashboards/src/lib/components/providers/refresher.ts +++ b/packages/dashboards/src/lib/components/providers/refresher.ts @@ -19,7 +19,8 @@ // THE SOFTWARE. import { Inject, Injectable, NgZone, OnDestroy } from "@angular/core"; -import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; +import { Subject } from "rxjs"; +import { takeUntil } from "rxjs/operators"; import { EventBus, EventDefinition } from "@nova-ui/bits"; @@ -49,24 +50,20 @@ export class Refresher implements OnDestroy, IConfigurable { protected interval = DEFAULT_REFRESH_INTERVAL; protected eventDef = REFRESH; + public readonly destroy$ = new Subject(); + constructor( - @Inject(PIZZAGNA_EVENT_BUS) protected readonly eventBus: EventBus, - protected readonly ngZone: NgZone, - protected readonly refresherSettings: RefresherSettingsService + @Inject(PIZZAGNA_EVENT_BUS) protected eventBus: EventBus, + protected ngZone: NgZone, + protected refresherSettings: RefresherSettingsService ) { this.refresherSettings.refreshRateSeconds$ - .pipe(takeUntilDestroyed()) - .subscribe(() => { + .pipe(takeUntil(this.destroy$)) + .subscribe((systemRefreshRate) => { if (!this.overrideDefaultSettings) { this.initializeInterval(); } }); - - this.refresherSettings.disabled$ - .pipe(takeUntilDestroyed()) - .subscribe(() => { - this.initializeInterval(); - }); } public updateConfiguration(properties: IRefresherProperties): void { @@ -81,6 +78,8 @@ export class Refresher implements OnDestroy, IConfigurable { public ngOnDestroy(): void { this.clearInterval(); + this.destroy$.next(); + this.destroy$.complete(); } private initializeInterval() { @@ -89,8 +88,7 @@ export class Refresher implements OnDestroy, IConfigurable { if ( typeof this.interval === "undefined" || this.getInterval() <= 0 || - this.enabled === false || - this.refresherSettings.disabled$.value === true + this.enabled === false ) { return; }