1 import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
2 import { CommonModule } from '@angular/common';
3 import { combineLatest } from 'rxjs';
5 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
6 import { ButtonModule, GridModule, LinkModule, TilesModule } from 'carbon-components-angular';
7 import { RouterModule } from '@angular/router';
8 import { ProductiveCardComponent } from '~/app/shared/components/productive-card/productive-card.component';
9 import { ComponentsModule } from '~/app/shared/components/components.module';
10 import { map, shareReplay, startWith } from 'rxjs/operators';
19 selector: 'cd-overview-alerts-card',
27 ProductiveCardComponent,
31 templateUrl: './overview-alerts-card.component.html',
32 styleUrl: './overview-alerts-card.component.scss',
33 changeDetection: ChangeDetectionStrategy.OnPush
35 export class OverviewAlertsCardComponent implements OnInit {
36 private readonly prometheusAlertService = inject(PrometheusAlertService);
39 this.prometheusAlertService.getGroupedAlerts(true);
42 readonly vm$ = combineLatest([
43 this.prometheusAlertService.totalAlerts$.pipe(startWith(0)),
44 this.prometheusAlertService.criticalAlerts$.pipe(startWith(0)),
45 this.prometheusAlertService.warningAlerts$.pipe(startWith(0))
47 map(([total, critical, warning]) => {
48 const hasAlerts = total > 0;
49 const hasCritical = critical > 0;
50 const hasWarning = warning > 0;
52 const icon = !hasAlerts
58 const statusText = hasAlerts ? $localize`Need attention` : $localize`No active alerts`;
61 hasCritical && { key: 'critical', icon: AlertIcon.error, count: critical },
62 hasWarning && { key: 'warning', icon: AlertIcon.warning, count: warning }
65 return { total, icon, statusText, badges };
67 shareReplay({ bufferSize: 1, refCount: true })