Files
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* 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
2022-04-22 14:33:13 +01:00

52 lines
1.4 KiB
TypeScript

import React, { FC, useState } from 'react';
import { intervalToAbbreviatedDurationString } from '@grafana/data';
import { AlertmanagerAlert } from 'app/plugins/datasource/alertmanager/types';
import { AlertLabels } from '../AlertLabels';
import { CollapseToggle } from '../CollapseToggle';
import { AmAlertStateTag } from './AmAlertStateTag';
interface Props {
alert: AlertmanagerAlert;
className?: string;
}
export const SilencedAlertsTableRow: FC<Props> = ({ alert, className }) => {
const [isCollapsed, setIsCollapsed] = useState(true);
const duration = intervalToAbbreviatedDurationString({
start: new Date(alert.startsAt),
end: new Date(alert.endsAt),
});
const alertName = Object.entries(alert.labels).reduce((name, [labelKey, labelValue]) => {
if (labelKey === 'alertname' || labelKey === '__alert_rule_title__') {
name = labelValue;
}
return name;
}, '');
return (
<>
<tr className={className}>
<td>
<CollapseToggle isCollapsed={isCollapsed} onToggle={(collapsed) => setIsCollapsed(collapsed)} />
</td>
<td>
<AmAlertStateTag state={alert.status.state} />
</td>
<td>for {duration} seconds</td>
<td>{alertName}</td>
</tr>
{!isCollapsed && (
<tr className={className}>
<td></td>
<td colSpan={5}>
<AlertLabels labels={alert.labels} />
</td>
</tr>
)}
</>
);
};