-
Notifications
You must be signed in to change notification settings - Fork 8k
/
rule_status_failed_callout.tsx
97 lines (87 loc) · 2.45 KB
/
rule_status_failed_callout.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { EuiCallOut, EuiCodeBlock } from '@elastic/eui';
import { FormattedDate } from '../../../../common/components/formatted_date';
import { RuleExecutionStatus } from '../../../../../common/detection_engine/rule_monitoring';
import * as i18n from './translations';
interface RuleStatusFailedCallOutProps {
date: string;
message: string;
status?: RuleExecutionStatus | null;
}
const RuleStatusFailedCallOutComponent: React.FC<RuleStatusFailedCallOutProps> = ({
date,
message,
status,
}) => {
const { shouldBeDisplayed, color, title } = getPropsByStatus(status);
if (!shouldBeDisplayed) {
return null;
}
return (
<div
css={`
pre {
margin-block-end: 0;
margin-right: 24px; // Otherwise the copy button overlaps the scrollbar
padding-inline-end: 0;
}
`}
>
<EuiCallOut
title={
<>
{title} <FormattedDate value={date} fieldName="execution_summary.last_execution.date" />
</>
}
color={color}
iconType="warning"
data-test-subj="ruleStatusFailedCallOut"
>
<EuiCodeBlock
className="eui-fullWidth"
paddingSize="none"
isCopyable
overflowHeight={96}
transparentBackground
>
{message}
</EuiCodeBlock>
</EuiCallOut>
</div>
);
};
export const RuleStatusFailedCallOut = React.memo(RuleStatusFailedCallOutComponent);
RuleStatusFailedCallOut.displayName = 'RuleStatusFailedCallOut';
interface HelperProps {
shouldBeDisplayed: boolean;
color: 'danger' | 'warning';
title: string;
}
const getPropsByStatus = (status: RuleExecutionStatus | null | undefined): HelperProps => {
switch (status) {
case RuleExecutionStatus.failed:
return {
shouldBeDisplayed: true,
color: 'danger',
title: i18n.ERROR_CALLOUT_TITLE,
};
case RuleExecutionStatus['partial failure']:
return {
shouldBeDisplayed: true,
color: 'warning',
title: i18n.PARTIAL_FAILURE_CALLOUT_TITLE,
};
default:
return {
shouldBeDisplayed: false,
color: 'warning',
title: '',
};
}
};