-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathDetectorControls.tsx
107 lines (101 loc) · 2.93 KB
/
DetectorControls.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
98
99
100
101
102
103
104
105
106
107
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import React, { useState } from 'react';
import {
EuiSmallButton,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
} from '@elastic/eui';
import { Detector } from '../../../../models/interfaces';
import { getApplication, getNavigationUI, getUISettings } from '../../../../services';
import { USE_NEW_HOME_PAGE } from '../../../../utils/constants';
interface DetectorControls {
onEditDetector(): void;
onEditFeatures(): void;
onDelete(): void;
onStartDetector(): void;
onStopDetector(): void;
detector: Detector;
}
export const DetectorControls = (props: DetectorControls) => {
const [isOpen, setIsOpen] = useState(false);
const useUpdatedUX = getUISettings().get(USE_NEW_HOME_PAGE);
const { HeaderControl } = getNavigationUI();
const { setAppRightControls } = getApplication();
const ActionsPopover = (
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiPopover
id="actionsPopover"
button={
<EuiSmallButton
iconType="arrowDown"
iconSide="right"
data-test-subj="actionsButton"
onClick={() => setIsOpen(!isOpen)}
>
Actions
</EuiSmallButton>
}
panelPaddingSize="none"
anchorPosition="downLeft"
isOpen={isOpen}
closePopover={() => setIsOpen(false)}
>
<EuiContextMenuPanel>
<EuiContextMenuItem
key="editDetector"
data-test-subj="editDetectorSettingsItem"
onClick={props.onEditDetector}
>
Edit detector settings
</EuiContextMenuItem>
<EuiContextMenuItem
key="editFeatures"
data-test-subj="editModelConfigurationItem"
onClick={props.onEditFeatures}
>
Edit model configuration
</EuiContextMenuItem>
<EuiContextMenuItem
key="deleteDetector"
data-test-subj="deleteDetectorItem"
onClick={props.onDelete}
style={{ color: '#FF6666' }}
>
Delete detector
</EuiContextMenuItem>
</EuiContextMenuPanel>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
);
const renderActionsPopover = () => {
return useUpdatedUX ? (
<HeaderControl
setMountPoint={setAppRightControls}
controls={[
{
renderComponent: ActionsPopover
}
]}
/>
) : (
ActionsPopover
);
};
return (
renderActionsPopover()
);
};