import { AlertmanagerAlert } from 'app/plugins/datasource/alertmanager/types'; import React, { FC, useState } from 'react'; import { CollapseToggle } from '../CollapseToggle'; import { StateTag } from '../StateTag'; import { ActionIcon } from '../rules/ActionIcon'; import { getAlertTableStyles } from '../../styles/table'; import { useStyles } from '@grafana/ui'; import { dateTimeAsMoment, toDuration } from '@grafana/data'; import { AlertLabels } from '../AlertLabels'; interface Props { alert: AlertmanagerAlert; className?: string; } export const SilencedAlertsTableRow: FC = ({ alert, className }) => { const [isCollapsed, setIsCollapsed] = useState(true); const tableStyles = useStyles(getAlertTableStyles); const alertDuration = toDuration(dateTimeAsMoment(alert.endsAt).diff(alert.startsAt)).asSeconds(); const alertName = Object.entries(alert.labels).reduce((name, [labelKey, labelValue]) => { if (labelKey === 'alertname' || labelKey === '__alert_rule_title__') { name = labelValue; } return name; }, ''); return ( <> setIsCollapsed(collapsed)} /> {alert.status.state} for {alertDuration} seconds {alertName} {!isCollapsed && ( )} ); };