]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
49372345ae1bf0dffb78e996258993da597caa23
[ceph-ci.git] /
1 import {
2   ChangeDetectionStrategy,
3   Component,
4   EventEmitter,
5   inject,
6   Input,
7   Output,
8   ViewEncapsulation
9 } from '@angular/core';
10 import {
11   SkeletonModule,
12   ButtonModule,
13   LinkModule,
14   TooltipModule,
15   TabsModule,
16   LayoutModule
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 { HealthCardVM } from '~/app/shared/models/overview';
30
31 type OverviewHealthData = {
32   summary: Summary;
33   upgrade: UpgradeInfoInterface;
34 };
35
36 type TabSection = 'system' | 'hardware' | 'resiliency';
37
38 interface HealthItemConfig {
39   key: 'mon' | 'mgr' | 'osd' | 'hosts';
40   label: string;
41   prefix?: string;
42   i18n?: boolean;
43 }
44
45 @Component({
46   selector: 'cd-overview-health-card',
47   imports: [
48     CommonModule,
49     ProductiveCardComponent,
50     SkeletonModule,
51     ButtonModule,
52     RouterModule,
53     ComponentsModule,
54     LinkModule,
55     PipesModule,
56     TooltipModule,
57     TabsModule,
58     LayoutModule
59   ],
60   standalone: true,
61   templateUrl: './overview-health-card.component.html',
62   styleUrl: './overview-health-card.component.scss',
63   encapsulation: ViewEncapsulation.None,
64   changeDetection: ChangeDetectionStrategy.OnPush
65 })
66 export class OverviewHealthCardComponent {
67   private readonly summaryService = inject(SummaryService);
68   private readonly upgradeService = inject(UpgradeService);
69
70   @Input({ required: true }) vm!: HealthCardVM;
71   @Output() viewIncidents = new EventEmitter<void>();
72
73   activeSection: TabSection | null = null;
74   healthItems: HealthItemConfig[] = [
75     { key: 'mon', label: $localize`Monitor` },
76     { key: 'mgr', label: $localize`Manager` },
77     { key: 'osd', label: $localize`OSD` },
78     { key: 'hosts', label: $localize`Nodes` }
79   ];
80
81   toggleSection(section: TabSection) {
82     this.activeSection = this.activeSection === section ? null : section;
83   }
84
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))
90     )
91   ]).pipe(map(([summary, upgrade]) => ({ summary, upgrade })));
92
93   onViewIncidentsClick() {
94     this.viewIncidents.emit();
95   }
96 }