import React, { FC, useState, Fragment } from 'react'; import { Link } from '@reach/router'; import { Alert, Collapse, Table, Badge } from 'reactstrap'; import { RuleStatus } from './AlertContents'; import { Rule } from '../../types/types'; import { faChevronDown, faChevronRight } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { createExpressionLink, parsePrometheusFloat, formatDuration } from '../../utils/index'; interface CollapsibleAlertPanelProps { rule: Rule; showAnnotations: boolean; } const alertColors: RuleStatus = { firing: 'danger', pending: 'warning', inactive: 'success', }; const CollapsibleAlertPanel: FC = ({ rule, showAnnotations }) => { const [open, toggle] = useState(false); return ( <> toggle(!open)} color={alertColors[rule.state]} style={{ cursor: 'pointer' }}> {rule.name} ({`${rule.alerts.length} active`})
          
            
name: {rule.name}
expr: {rule.query}
{rule.duration > 0 && (
for: {formatDuration(rule.duration * 1000)}
)} {rule.labels && Object.keys(rule.labels).length > 0 && (
labels:
{Object.entries(rule.labels).map(([key, value]) => (
{key}: {value}
))}
)} {rule.annotations && Object.keys(rule.annotations).length > 0 && (
annotations:
{Object.entries(rule.annotations).map(([key, value]) => (
{key}: {value}
))}
)}
{rule.alerts.length > 0 && ( {rule.alerts.map((alert, i) => { return ( {showAnnotations && } ); })}
Labels State Active Since Value
{Object.entries(alert.labels).map(([k, v], j) => { return ( {k}={v} ); })}
{alert.state}
{alert.activeAt} {parsePrometheusFloat(alert.value)}
)}
); }; interface AnnotationsProps { annotations: Record; } export const Annotations: FC = ({ annotations }) => { return (
Annotations
{Object.entries(annotations).map(([k, v], i) => { return (
{k}
{v}
); })}
); }; export default CollapsibleAlertPanel;