Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
40 changes: 7 additions & 33 deletions packages/dashboards/src/lib/components/providers/refresher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ describe("Refresher > ", () => {
});

beforeEach(() => {
eventBus = new EventBus<IEvent>();
eventBus = new EventBus();
refresherSettings = new RefresherSettingsService();
TestBed.runInInjectionContext(() => {
refresher = new Refresher(eventBus, ngZone, refresherSettings);
});
refresher = new Refresher(eventBus, ngZone, refresherSettings);
});

describe("updateConfiguration > ", () => {
Expand All @@ -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");
Expand All @@ -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();
}));
});
});
26 changes: 12 additions & 14 deletions packages/dashboards/src/lib/components/providers/refresher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -49,24 +50,20 @@ export class Refresher implements OnDestroy, IConfigurable {
protected interval = DEFAULT_REFRESH_INTERVAL;
protected eventDef = REFRESH;

public readonly destroy$ = new Subject<void>();

constructor(
@Inject(PIZZAGNA_EVENT_BUS) protected readonly eventBus: EventBus<IWidgetEvent>,
protected readonly ngZone: NgZone,
protected readonly refresherSettings: RefresherSettingsService
@Inject(PIZZAGNA_EVENT_BUS) protected eventBus: EventBus<IWidgetEvent>,
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 {
Expand All @@ -81,6 +78,8 @@ export class Refresher implements OnDestroy, IConfigurable {

public ngOnDestroy(): void {
this.clearInterval();
this.destroy$.next();
this.destroy$.complete();
}

private initializeInterval() {
Expand All @@ -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;
}
Expand Down