Skip to content

Commit

Permalink
NAS-128451: Port WidgetSysInfoComponent to new dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
denysbutenko committed May 15, 2024
1 parent caaa28c commit 5c77e75
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class WidgetResourcesService {
);

readonly systemInfo$ = this.ws.call('webui.main.dashboard.sys_info').pipe(
toLoadingState(),
shareReplay({ bufferSize: 1, refCount: true }),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ChangeDetectionStrategy, Component, input,
} from '@angular/core';
import { toLoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
import { WidgetComponent } from 'app/pages/dashboard/types/widget-component.interface';
import {
Expand All @@ -19,7 +18,7 @@ export class WidgetHostnameComponent implements WidgetComponent {
size = input.required<SlotSize>();
readonly name = hostnameWidget.name;

systemInfo$ = this.resources.systemInfo$.pipe(toLoadingState());
systemInfo$ = this.resources.systemInfo$;

constructor(
private resources: WidgetResourcesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FakeFormatDateTimePipe } from 'app/core/testing/classes/fake-format-dat
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { Codename } from 'app/enums/codename.enum';
import { ProductType } from 'app/enums/product-type.enum';
import { LoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { SystemLicense, SystemInfo } from 'app/interfaces/system-info.interface';
import { selectUpdateJobForActiveNode } from 'app/modules/jobs/store/job.selectors';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
Expand Down Expand Up @@ -63,7 +64,11 @@ describe('WidgetSysInfoActiveComponent', () => {
providers: [
mockAuth(),
mockProvider(WidgetResourcesService, {
systemInfo$: of(systemInfo),
systemInfo$: of({
isLoading: false,
error: null,
value: systemInfo,
} as LoadingState<SystemInfo>),
updateAvailable$: of(true),
refreshInteval$: of(0),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { Store } from '@ngrx/store';
import { filter, map } from 'rxjs';
import { selectUpdateJobForActiveNode } from 'app/modules/jobs/store/job.selectors';
import { WidgetResourcesService } from 'app/pages/dashboard/services/widget-resources.service';
import { SlotSize } from 'app/pages/dashboard/types/widget.interface';
Expand All @@ -30,7 +31,10 @@ export class WidgetSysInfoActiveComponent {
isUpdateRunning = toSignal(this.store$.select(selectUpdateJobForActiveNode));

updateAvailable = toSignal(this.resources.updateAvailable$);
systemInfo = toSignal(this.resources.systemInfo$);
systemInfo = toSignal(this.resources.systemInfo$.pipe(
filter((state) => !state.isLoading),
map((state) => state.value),
));
elapsedTenSecondsInterval = toSignal(this.resources.refreshInteval$);

version = computed(() => getSystemVersion(this.systemInfo().version, this.systemInfo().codename));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FakeFormatDateTimePipe } from 'app/core/testing/classes/fake-format-dat
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { Codename } from 'app/enums/codename.enum';
import { ProductType } from 'app/enums/product-type.enum';
import { LoadingState } from 'app/helpers/operators/to-loading-state.helper';
import { SystemLicense, SystemInfo } from 'app/interfaces/system-info.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { selectUpdateJobForPassiveNode } from 'app/modules/jobs/store/job.selectors';
Expand Down Expand Up @@ -70,7 +71,11 @@ describe('WidgetSysInfoPassiveComponent', () => {
mockProvider(DialogService),
mockProvider(Router),
mockProvider(WidgetResourcesService, {
systemInfo$: of(systemInfo),
systemInfo$: of({
isLoading: false,
error: null,
value: systemInfo,
} as LoadingState<SystemInfo>),
refreshInteval$: of(0),
updateAvailable$: of(true),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class WidgetSysInfoPassiveComponent {

elapsedTenSecondsInterval = toSignal(this.resources.refreshInteval$);
updateAvailable = toSignal(this.resources.updateAvailable$);
systemInfo = toSignal(this.resources.systemInfo$.pipe(map((sysInfo) => sysInfo.remote_info)));
systemInfo = toSignal(this.resources.systemInfo$.pipe(
filter((state) => !state.isLoading),
map((state) => state.value.remote_info),
));

version = computed(() => getSystemVersion(this.systemInfo().version, this.systemInfo().codename));
uptime = computed(() => this.systemInfo().uptime_seconds + (this.elapsedTenSecondsInterval() * 10));
Expand Down

0 comments on commit 5c77e75

Please sign in to comment.