2020-10-28 02:23:22 -05:00
|
|
|
import React, { useCallback } from 'react';
|
2019-05-13 02:38:19 -05:00
|
|
|
// @ts-ignore
|
2018-09-03 06:46:39 -05:00
|
|
|
import Highlighter from 'react-highlight-words';
|
2020-10-28 02:23:22 -05:00
|
|
|
import { Icon, IconName, Button, LinkButton, Card } from '@grafana/ui';
|
2018-09-03 06:46:39 -05:00
|
|
|
import { AlertRule } from '../../types';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
rule: AlertRule;
|
|
|
|
search: string;
|
2018-09-10 02:29:53 -05:00
|
|
|
onTogglePause: () => void;
|
2018-09-03 06:46:39 -05:00
|
|
|
}
|
|
|
|
|
2020-10-28 02:23:22 -05:00
|
|
|
const AlertRuleItem = ({ rule, search, onTogglePause }: Props) => {
|
|
|
|
const ruleUrl = `${rule.url}?editPanel=${rule.panelId}&tab=alert`;
|
|
|
|
const renderText = useCallback(
|
2021-01-20 00:59:48 -06:00
|
|
|
(text) => (
|
2018-09-03 06:46:39 -05:00
|
|
|
<Highlighter
|
2020-10-28 02:23:22 -05:00
|
|
|
key={text}
|
2018-09-03 06:46:39 -05:00
|
|
|
highlightClassName="highlight-search-match"
|
|
|
|
textToHighlight={text}
|
2020-10-28 02:23:22 -05:00
|
|
|
searchWords={[search]}
|
2018-09-03 06:46:39 -05:00
|
|
|
/>
|
2020-10-28 02:23:22 -05:00
|
|
|
),
|
|
|
|
[search]
|
|
|
|
);
|
2018-09-03 06:46:39 -05:00
|
|
|
|
2020-10-28 02:23:22 -05:00
|
|
|
return (
|
2021-01-26 05:12:41 -06:00
|
|
|
<Card heading={<a href={ruleUrl}>{renderText(rule.name)}</a>}>
|
|
|
|
<Card.Figure>
|
|
|
|
<Icon size="xl" name={rule.stateIcon as IconName} className={`alert-rule-item__icon ${rule.stateClass}`} />
|
|
|
|
</Card.Figure>
|
|
|
|
<Card.Meta>
|
|
|
|
<span key="state">
|
|
|
|
<span key="text" className={`${rule.stateClass}`}>
|
|
|
|
{renderText(rule.stateText)}{' '}
|
2020-11-19 01:48:56 -06:00
|
|
|
</span>
|
2021-01-26 05:12:41 -06:00
|
|
|
for {rule.stateAge}
|
|
|
|
</span>
|
|
|
|
{rule.info ? renderText(rule.info) : null}
|
|
|
|
</Card.Meta>
|
|
|
|
<Card.Actions>
|
|
|
|
<Button
|
|
|
|
key="play"
|
|
|
|
variant="secondary"
|
|
|
|
icon={rule.state === 'paused' ? 'play' : 'pause'}
|
|
|
|
onClick={onTogglePause}
|
|
|
|
>
|
|
|
|
{rule.state === 'paused' ? 'Resume' : 'Pause'}
|
|
|
|
</Button>
|
|
|
|
<LinkButton key="edit" variant="secondary" href={ruleUrl} icon="cog">
|
|
|
|
Edit alert
|
|
|
|
</LinkButton>
|
|
|
|
</Card.Actions>
|
|
|
|
</Card>
|
2020-10-28 02:23:22 -05:00
|
|
|
);
|
|
|
|
};
|
2018-09-03 08:44:39 -05:00
|
|
|
|
2018-09-10 02:29:53 -05:00
|
|
|
export default AlertRuleItem;
|