import { css } from '@emotion/css'; import { useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Stack, TextLink, useStyles2 } from '@grafana/ui'; import { AlertmanagerGroup } from 'app/plugins/datasource/alertmanager/types'; import { createContactPointSearchLink } from '../../utils/misc'; import { AlertLabels } from '../AlertLabels'; import { CollapseToggle } from '../CollapseToggle'; import { MetaText } from '../MetaText'; import { AlertGroupAlertsTable } from './AlertGroupAlertsTable'; import { AlertGroupHeader } from './AlertGroupHeader'; interface Props { group: AlertmanagerGroup; alertManagerSourceName: string; } export const AlertGroup = ({ alertManagerSourceName, group }: Props) => { const [isCollapsed, setIsCollapsed] = useState(true); const styles = useStyles2(getStyles); // When group is grouped, receiver.name is 'NONE' as it can contain multiple receivers const receiverInGroup = group.receiver.name !== 'NONE'; const contactPoint = group.receiver.name; return (
setIsCollapsed(!isCollapsed)} data-testid="alert-group-collapse-toggle" /> {Object.keys(group.labels).length ? ( {receiverInGroup && ( Delivered to{' '} {group.receiver.name} )} ) : ( No grouping )}
{!isCollapsed && }
); }; const getStyles = (theme: GrafanaTheme2) => ({ wrapper: css({ '& + &': { marginTop: theme.spacing(2), }, }), header: css({ display: 'flex', flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', padding: theme.spacing(1), backgroundColor: theme.colors.background.secondary, width: '100%', }), group: css({ display: 'flex', flexDirection: 'row', alignItems: 'center', }), });