-
Notifications
You must be signed in to change notification settings - Fork 87
/
DashboardControls.js
83 lines (76 loc) · 2.37 KB
/
DashboardControls.js
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
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import _ from 'lodash';
import { EuiFieldSearch, EuiFlexGroup, EuiSelect, EuiFlexItem, EuiPagination } from '@elastic/eui';
import { ALERT_STATE, MONITOR_TYPE } from '../../../../utils/constants';
const severityOptions = [
{ value: 'ALL', text: 'All severity levels' },
{ value: '1', text: '1 (Highest)' },
{ value: '2', text: '2 (High)' },
{ value: '3', text: '3 (Medium)' },
{ value: '4', text: '4 (Low)' },
{ value: '5', text: '5 (Lowest)' },
];
const stateOptions = [
{ value: 'ALL', text: 'All alerts' },
{ value: ALERT_STATE.ACTIVE, text: 'Active' },
{ value: ALERT_STATE.ACKNOWLEDGED, text: 'Acknowledged' },
{ value: ALERT_STATE.COMPLETED, text: 'Completed' },
{ value: ALERT_STATE.ERROR, text: 'Error' },
{ value: ALERT_STATE.DELETED, text: 'Deleted' },
];
const DashboardControls = ({
activePage,
pageCount,
search,
severity = severityOptions[0],
state = stateOptions[0],
onSearchChange,
onSeverityChange,
onStateChange,
onPageChange,
isAlertsFlyout = false,
monitorType,
}) => {
let supportedStateOptions = stateOptions;
switch (monitorType) {
case MONITOR_TYPE.DOC_LEVEL:
const supportedStates = [ALERT_STATE.ACKNOWLEDGED, ALERT_STATE.ACTIVE, ALERT_STATE.ERROR];
supportedStateOptions = stateOptions.filter((state) =>
_.includes(supportedStates, state.value)
);
break;
}
return (
<EuiFlexGroup style={{ padding: '0px 5px' }}>
<EuiFlexItem>
<EuiFieldSearch
fullWidth={true}
placeholder="Search"
onChange={onSearchChange}
value={search}
/>
</EuiFlexItem>
{isAlertsFlyout ? null : (
<EuiFlexItem grow={false}>
<EuiSelect options={severityOptions} value={severity} onChange={onSeverityChange} />
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiSelect
options={supportedStateOptions}
value={state}
onChange={onStateChange}
data-test-subj={'dashboardAlertStateFilter'}
/>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ justifyContent: 'center' }}>
<EuiPagination pageCount={pageCount} activePage={activePage} onPageClick={onPageChange} />
</EuiFlexItem>
</EuiFlexGroup>
);
};
export default DashboardControls;