2 ChangeDetectionStrategy,
9 } from '@angular/core';
17 } from 'carbon-components-angular';
18 import { ProductiveCardComponent } from '~/app/shared/components/productive-card/productive-card.component';
19 import { RouterModule } from '@angular/router';
20 import { ComponentsModule } from '~/app/shared/components/components.module';
21 import { SummaryService } from '~/app/shared/services/summary.service';
22 import { Summary } from '~/app/shared/models/summary.model';
23 import { combineLatest, Observable, of } from 'rxjs';
24 import { CommonModule } from '@angular/common';
25 import { PipesModule } from '~/app/shared/pipes/pipes.module';
26 import { UpgradeInfoInterface } from '~/app/shared/models/upgrade.interface';
27 import { UpgradeService } from '~/app/shared/api/upgrade.service';
28 import { catchError, filter, map, startWith } from 'rxjs/operators';
29 import { HealthCardTabSection, HealthCardVM } from '~/app/shared/models/overview';
31 type OverviewHealthData = {
33 upgrade: UpgradeInfoInterface;
36 interface HealthItemConfig {
37 key: 'mon' | 'mgr' | 'osd' | 'hosts';
44 selector: 'cd-overview-health-card',
47 ProductiveCardComponent,
59 templateUrl: './overview-health-card.component.html',
60 styleUrl: './overview-health-card.component.scss',
61 encapsulation: ViewEncapsulation.None,
62 changeDetection: ChangeDetectionStrategy.OnPush
64 export class OverviewHealthCardComponent {
65 private readonly summaryService = inject(SummaryService);
66 private readonly upgradeService = inject(UpgradeService);
68 @Input({ required: true }) vm!: HealthCardVM;
69 @Output() viewIncidents = new EventEmitter<void>();
70 @Output() activeSectionChange = new EventEmitter<HealthCardTabSection | null>();
72 activeSection: HealthCardTabSection | null = null;
73 healthItems: HealthItemConfig[] = [
74 { key: 'mon', label: $localize`Monitor` },
75 { key: 'mgr', label: $localize`Manager` },
76 { key: 'osd', label: $localize`OSD` },
77 { key: 'hosts', label: $localize`Nodes` }
80 toggleSection(section: HealthCardTabSection) {
81 this.activeSection = this.activeSection === section ? null : section;
82 this.activeSectionChange.emit(this.activeSection);
85 readonly data$: Observable<OverviewHealthData> = combineLatest([
86 this.summaryService.summaryData$.pipe(filter((summary): summary is Summary => !!summary)),
87 this.upgradeService.listCached().pipe(
88 startWith(null as UpgradeInfoInterface),
89 catchError(() => of(null))
91 ]).pipe(map(([summary, upgrade]) => ({ summary, upgrade })));
93 onViewIncidentsClick() {
94 this.viewIncidents.emit();