Skip to content
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

NAS-131558 / 25.04 / Change observable subscription for apps widget #11172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ <h3>{{ 'App' | translate }}</h3>
[job]="job() | async"
></ix-app-card-info>

<ix-app-cpu-info
class="square"
[stats]="stats() | async"
></ix-app-cpu-info>

<ix-app-network-info
class="rectangle"
[stats]="stats() | async"
></ix-app-network-info>

<ix-app-memory-info
class="square"
[stats]="stats() | async"
></ix-app-memory-info>

<ix-app-disk-info
class="rectangle"
[stats]="stats() | async"
></ix-app-disk-info>
@if (stats$) {
<ix-app-cpu-info
class="square"
[stats]="stats$ | async"
></ix-app-cpu-info>

<ix-app-network-info
class="rectangle"
[stats]="stats$ | async"
></ix-app-network-info>

<ix-app-memory-info
class="square"
[stats]="stats$ | async"
></ix-app-memory-info>

<ix-app-disk-info
class="rectangle"
[stats]="stats$ | async"
></ix-app-disk-info>
}

</div>
</mat-card-content>
</mat-card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fakeAsync } from '@angular/core/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { MockComponents } from 'ng-mocks';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('WidgetAppComponent', () => {
mockProvider(WidgetResourcesService, {
serverTime$: of(new Date()),
getApp: () => of(app),
getAppStats: () => of(),
getAppStats: () => of({}),
getAppStatusUpdates: () => of(),
}),
mockProvider(RedirectService, {
Expand Down Expand Up @@ -99,13 +100,14 @@ describe('WidgetAppComponent', () => {
});
});

it('checks components', () => {
it('checks components', fakeAsync(() => {
spectator.detectChanges();
expect(spectator.query(AppControlsComponent)).toBeTruthy();
expect(spectator.query(AppCardLogoComponent)).toBeTruthy();
expect(spectator.query(AppCardInfoComponent)).toBeTruthy();
expect(spectator.query(AppCpuInfoComponent)).toBeTruthy();
expect(spectator.query(AppMemoryInfoComponent)).toBeTruthy();
expect(spectator.query(AppNetworkInfoComponent)).toBeTruthy();
expect(spectator.query(AppDiskInfoComponent)).toBeTruthy();
});
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { AsyncPipe } from '@angular/common';
import {
Component, ChangeDetectionStrategy, input,
computed,
effect,
ChangeDetectorRef,
} from '@angular/core';
import { MatCard, MatCardContent } from '@angular/material/card';
import { TranslateModule } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { LoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { AppStats } from 'app/interfaces/app.interface';
import { WithLoadingStateDirective } from 'app/modules/loader/directives/with-loading-state/with-loading-state.directive';
import { AppCardLogoComponent } from 'app/pages/apps/components/app-card-logo/app-card-logo.component';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
Expand Down Expand Up @@ -43,10 +48,18 @@ export class WidgetAppComponent implements WidgetComponent<WidgetAppSettings> {
size = input.required<SlotSize>();
settings = input.required<WidgetAppSettings>();

appName = computed(() => this.settings().appName);
app = computed(() => this.resources.getApp(this.appName()));
job = computed(() => this.resources.getAppStatusUpdates(this.appName()));
stats = computed(() => this.resources.getAppStats(this.appName()));
protected appName = computed(() => this.settings().appName);
protected app = computed(() => this.resources.getApp(this.appName()));
protected job = computed(() => this.resources.getAppStatusUpdates(this.appName()));
protected stats$: Observable<LoadingState<AppStats>>;

constructor(private resources: WidgetResourcesService) {}
effect = effect(() => {
this.stats$ = this.resources.getAppStats(this.appName());
this.cdr.markForCheck();
});

constructor(
private resources: WidgetResourcesService,
private cdr: ChangeDetectorRef,
) {}
}
Loading