-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.tsx
134 lines (129 loc) · 4.28 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiTextColor } from '@elastic/eui';
import React, { FC, useMemo } from 'react';
import { HeaderMenu } from '../../header_menu';
import { headerMenuCss, noLinkedRulesCss } from '../list_header.styles';
import * as i18n from '../../translations';
import { Rule } from '../../types';
import { generateLinkedRulesMenuItems } from '../../generate_linked_rules_menu_item';
interface MenuItemsProps {
isReadonly: boolean;
dataTestSubj?: string;
linkedRules: Rule[];
canUserEditList?: boolean;
securityLinkAnchorComponent: React.ElementType; // This property needs to be removed to avoid the Prop Drilling, once we move all the common components from x-pack/security-solution/common
onDeleteList: () => void;
onManageRules: () => void;
onExportList: () => void;
onDuplicateList: () => void;
}
const MenuItemsComponent: FC<MenuItemsProps> = ({
dataTestSubj,
linkedRules,
securityLinkAnchorComponent,
isReadonly,
canUserEditList = true,
onDeleteList,
onManageRules,
onExportList,
onDuplicateList,
}) => {
const referencedLinks = useMemo(
() =>
generateLinkedRulesMenuItems({
leftIcon: 'check',
dataTestSubj,
linkedRules,
securityLinkAnchorComponent,
}),
[dataTestSubj, linkedRules, securityLinkAnchorComponent]
);
return (
<EuiFlexGroup
direction="row"
alignItems="baseline"
justifyContent="center"
responsive
data-test-subj={`${dataTestSubj || ''}Container`}
gutterSize="l"
>
<EuiFlexItem css={headerMenuCss}>
{linkedRules.length ? (
<HeaderMenu
dataTestSubj={`${dataTestSubj || ''}LinkedRulesMenu`}
emptyButton
useCustomActions
text={i18n.EXCEPTION_LIST_HEADER_LINKED_RULES(linkedRules.length)}
actions={referencedLinks}
disableActions={false}
iconType="arrowDown"
iconSide="right"
panelPaddingSize="none"
/>
) : (
<EuiTextColor data-test-subj="noLinkedRules" css={noLinkedRulesCss} color="subdued">
{i18n.EXCEPTION_LIST_HEADER_LINKED_RULES(linkedRules.length)}
</EuiTextColor>
)}
</EuiFlexItem>
{canUserEditList && (
<EuiFlexItem>
<EuiButton
data-test-subj={`${dataTestSubj || ''}ManageRulesButton`}
fill
onClick={() => {
if (typeof onManageRules === 'function') onManageRules();
}}
>
{i18n.EXCEPTION_LIST_HEADER_LINK_RULES_BUTTON}
</EuiButton>
</EuiFlexItem>
)}
<EuiFlexItem>
<HeaderMenu
iconType="boxesHorizontal"
dataTestSubj={`${dataTestSubj || ''}MenuActions`}
actions={[
{
key: '1',
icon: 'exportAction',
label: i18n.EXCEPTION_LIST_HEADER_EXPORT_ACTION,
onClick: () => {
if (typeof onExportList === 'function') onExportList();
},
},
{
key: '2',
icon: 'copy',
label: i18n.EXCEPTION_LIST_HEADER_DUPLICATE_ACTION,
onClick: () => {
if (typeof onDuplicateList === 'function') onDuplicateList();
},
disabled: !canUserEditList,
},
{
key: '3',
icon: 'trash',
label: i18n.EXCEPTION_LIST_HEADER_DELETE_ACTION,
onClick: () => {
if (typeof onDeleteList === 'function') onDeleteList();
},
disabled: !canUserEditList,
},
]}
disableActions={isReadonly}
anchorPosition="downCenter"
/>
</EuiFlexItem>
</EuiFlexGroup>
);
};
MenuItemsComponent.displayName = 'MenuItemsComponent';
export const MenuItems = React.memo(MenuItemsComponent);
MenuItems.displayName = 'MenuItems';