2 ChangeDetectionStrategy,
7 } from '@angular/core';
8 import { CommonModule } from '@angular/common';
9 import { combineLatest } from 'rxjs';
11 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
12 import { ButtonModule, GridModule, LinkModule, TilesModule } from 'carbon-components-angular';
13 import { RouterModule } from '@angular/router';
14 import { ProductiveCardComponent } from '~/app/shared/components/productive-card/productive-card.component';
15 import { ComponentsModule } from '~/app/shared/components/components.module';
16 import { map, shareReplay, startWith } from 'rxjs/operators';
25 selector: 'cd-overview-alerts-card',
33 ProductiveCardComponent,
37 templateUrl: './overview-alerts-card.component.html',
38 styleUrl: './overview-alerts-card.component.scss',
39 changeDetection: ChangeDetectionStrategy.OnPush,
40 encapsulation: ViewEncapsulation.None
42 export class OverviewAlertsCardComponent implements OnInit {
43 private readonly prometheusAlertService = inject(PrometheusAlertService);
46 this.prometheusAlertService.getGroupedAlerts(true);
49 readonly vm$ = combineLatest([
50 this.prometheusAlertService.totalAlerts$.pipe(startWith(0)),
51 this.prometheusAlertService.criticalAlerts$.pipe(startWith(0)),
52 this.prometheusAlertService.warningAlerts$.pipe(startWith(0))
54 map(([total, critical, warning]) => {
55 const hasAlerts = total > 0;
56 const hasCritical = critical > 0;
57 const hasWarning = warning > 0;
59 const icon = !hasAlerts
65 const statusText = hasAlerts ? $localize`Need attention` : $localize`No active alerts`;
68 hasCritical && { key: 'critical', icon: AlertIcon.error, count: critical },
69 hasWarning && { key: 'warning', icon: AlertIcon.warning, count: warning }
72 return { total, icon, statusText, badges };
74 shareReplay({ bufferSize: 1, refCount: true })