import { css } from '@emotion/css'; import React, { useState, useEffect } from 'react'; import { GrafanaTheme2, intervalToAbbreviatedDurationString } from '@grafana/data'; import { useStyles2, LinkButton } from '@grafana/ui'; import { AlertLabels } from 'app/features/alerting/unified/components/AlertLabels'; import { CollapseToggle } from 'app/features/alerting/unified/components/CollapseToggle'; import { AlertGroupHeader } from 'app/features/alerting/unified/components/alert-groups/AlertGroupHeader'; import { getNotificationsTextColors } from 'app/features/alerting/unified/styles/notifications'; import { makeAMLink, makeLabelBasedSilenceLink } from 'app/features/alerting/unified/utils/misc'; import { AlertmanagerGroup, AlertState } from 'app/plugins/datasource/alertmanager/types'; type Props = { alertManagerSourceName: string; group: AlertmanagerGroup; expandAll: boolean; }; export const AlertGroup = ({ alertManagerSourceName, group, expandAll }: Props) => { const [showAlerts, setShowAlerts] = useState(expandAll); const styles = useStyles2(getStyles); const textStyles = useStyles2(getNotificationsTextColors); useEffect(() => setShowAlerts(expandAll), [expandAll]); return (
{Object.keys(group.labels).length > 0 ? ( ) : (
No grouping
)}
setShowAlerts(!showAlerts)} />{' '}
{showAlerts && (
{group.alerts.map((alert, index) => { const state = alert.status.state.toUpperCase(); const interval = intervalToAbbreviatedDurationString({ start: new Date(alert.startsAt), end: Date.now(), }); return (
{state} for {interval}
{alert.status.state === AlertState.Suppressed && ( Manage silences )} {alert.status.state === AlertState.Active && ( Silence )} {alert.generatorURL && ( See source )}
); })}
)}
); }; const getStyles = (theme: GrafanaTheme2) => ({ noGroupingText: css` height: ${theme.spacing(4)}; `, group: css` background-color: ${theme.colors.background.secondary}; margin: ${theme.spacing(0.5, 1, 0.5, 1)}; padding: ${theme.spacing(1)}; `, row: css` display: flex; flex-direction: row; align-items: center; `, alerts: css` margin: ${theme.spacing(0, 2, 0, 4)}; `, alert: css` padding: ${theme.spacing(1, 0)}; & + & { border-top: 1px solid ${theme.colors.border.medium}; } `, button: css` & + & { margin-left: ${theme.spacing(1)}; } `, actionsRow: css` padding: ${theme.spacing(1, 0)}; `, });