mirror of
https://github.com/grafana/grafana.git
synced 2025-09-20 05:53:07 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import pluralize from 'pluralize';
|
|
import React from 'react';
|
|
|
|
import { useStyles2 } from '@grafana/ui';
|
|
import { AlertmanagerGroup, AlertState } from 'app/plugins/datasource/alertmanager/types';
|
|
|
|
import { getNotificationsTextColors } from '../../styles/notifications';
|
|
|
|
interface Props {
|
|
group: AlertmanagerGroup;
|
|
}
|
|
|
|
export const AlertGroupHeader = ({ group }: Props) => {
|
|
const textStyles = useStyles2(getNotificationsTextColors);
|
|
const total = group.alerts.length;
|
|
const countByStatus = group.alerts.reduce((statusObj, alert) => {
|
|
if (statusObj[alert.status.state]) {
|
|
statusObj[alert.status.state] += 1;
|
|
} else {
|
|
statusObj[alert.status.state] = 1;
|
|
}
|
|
return statusObj;
|
|
}, {} as Record<AlertState, number>);
|
|
|
|
return (
|
|
<div>
|
|
{`${total} ${pluralize('alert', total)}: `}
|
|
{Object.entries(countByStatus).map(([state, count], index) => {
|
|
return (
|
|
<span
|
|
key={`${JSON.stringify(group.labels)}-notifications-${index}`}
|
|
className={textStyles[state as AlertState]}
|
|
>
|
|
{index > 0 && ', '}
|
|
{`${count} ${state}`}
|
|
</span>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
};
|