]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
bf1c855b25ec223564459e27b17ec6a6f7105d18
[ceph.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 { HealthCardTabSection, HealthCardVM } from '~/app/shared/models/overview';
30
31 type OverviewHealthData = {
32   summary: Summary;
33   upgrade: UpgradeInfoInterface;
34 };
35
36 interface HealthItemConfig {
37   key: 'mon' | 'mgr' | 'osd' | 'hosts';
38   label: string;
39   prefix?: string;
40   i18n?: boolean;
41 }
42
43 @Component({
44   selector: 'cd-overview-health-card',
45   imports: [
46     CommonModule,
47     ProductiveCardComponent,
48     SkeletonModule,
49     ButtonModule,
50     RouterModule,
51     ComponentsModule,
52     LinkModule,
53     PipesModule,
54     TooltipModule,
55     TabsModule,
56     LayoutModule
57   ],
58   standalone: true,
59   templateUrl: './overview-health-card.component.html',
60   styleUrl: './overview-health-card.component.scss',
61   encapsulation: ViewEncapsulation.None,
62   changeDetection: ChangeDetectionStrategy.OnPush
63 })
64 export class OverviewHealthCardComponent {
65   private readonly summaryService = inject(SummaryService);
66   private readonly upgradeService = inject(UpgradeService);
67
68   @Input({ required: true }) vm!: HealthCardVM;
69   @Output() viewIncidents = new EventEmitter<void>();
70   @Output() activeSectionChange = new EventEmitter<HealthCardTabSection | null>();
71
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` }
78   ];
79
80   toggleSection(section: HealthCardTabSection) {
81     this.activeSection = this.activeSection === section ? null : section;
82     this.activeSectionChange.emit(this.activeSection);
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 }