forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
171 lines (159 loc) · 4.79 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import {
EuiButtonEmpty,
EuiContextMenu,
EuiContextMenuPanelItemDescriptor,
EuiPopover
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { memoize } from 'lodash';
import React, { Fragment } from 'react';
import chrome from 'ui/chrome';
import { idx } from '@kbn/elastic-idx';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { LicenseContext } from '../../../../context/LicenseContext';
import { MachineLearningFlyout } from './MachineLearningFlyout';
import { WatcherFlyout } from './WatcherFlyout';
interface Props {
transactionTypes: string[];
urlParams: IUrlParams;
}
interface State {
isPopoverOpen: boolean;
activeFlyout: FlyoutName;
}
type FlyoutName = null | 'ML' | 'Watcher';
export class ServiceIntegrations extends React.Component<Props, State> {
public state: State = { isPopoverOpen: false, activeFlyout: null };
public getPanelItems = memoize((mlAvailable: boolean | undefined) => {
let panelItems: EuiContextMenuPanelItemDescriptor[] = [];
if (mlAvailable) {
panelItems = panelItems.concat(this.getMLPanelItems());
}
return panelItems.concat(this.getWatcherPanelItems());
});
public getMLPanelItems = () => {
return [
{
name: i18n.translate(
'xpack.apm.serviceDetails.integrationsMenu.enableMLAnomalyDetectionButtonLabel',
{
defaultMessage: 'Enable ML anomaly detection'
}
),
icon: 'machineLearningApp',
toolTipContent: i18n.translate(
'xpack.apm.serviceDetails.integrationsMenu.enableMLAnomalyDetectionButtonTooltip',
{
defaultMessage: 'Set up a machine learning job for this service'
}
),
onClick: () => {
this.closePopover();
this.openFlyout('ML');
}
}
];
};
public getWatcherPanelItems = () => {
return [
{
name: i18n.translate(
'xpack.apm.serviceDetails.integrationsMenu.enableWatcherErrorReportsButtonLabel',
{
defaultMessage: 'Enable watcher error reports'
}
),
icon: 'watchesApp',
onClick: () => {
this.closePopover();
this.openFlyout('Watcher');
}
},
{
name: i18n.translate(
'xpack.apm.serviceDetails.integrationsMenu.viewWatchesButtonLabel',
{
defaultMessage: 'View existing watches'
}
),
icon: 'watchesApp',
href: chrome.addBasePath(
'/app/kibana#/management/elasticsearch/watcher'
),
target: '_blank',
onClick: () => this.closePopover()
}
];
};
public openPopover = () =>
this.setState({
isPopoverOpen: true
});
public closePopover = () =>
this.setState({
isPopoverOpen: false
});
public openFlyout = (name: FlyoutName) =>
this.setState({ activeFlyout: name });
public closeFlyouts = () => this.setState({ activeFlyout: null });
public render() {
const button = (
<EuiButtonEmpty
iconType="arrowDown"
iconSide="right"
onClick={this.openPopover}
>
{i18n.translate(
'xpack.apm.serviceDetails.integrationsMenu.integrationsButtonLabel',
{
defaultMessage: 'Integrations'
}
)}
</EuiButtonEmpty>
);
return (
<LicenseContext.Consumer>
{license => (
<Fragment>
<EuiPopover
id="integrations-menu"
button={button}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
panelPaddingSize="none"
anchorPosition="downRight"
>
<EuiContextMenu
initialPanelId={0}
panels={[
{
id: 0,
items: this.getPanelItems(
idx(license, _ => _.features.ml.is_available)
)
}
]}
/>
</EuiPopover>
<MachineLearningFlyout
isOpen={this.state.activeFlyout === 'ML'}
onClose={this.closeFlyouts}
urlParams={this.props.urlParams}
serviceTransactionTypes={this.props.transactionTypes}
/>
<WatcherFlyout
isOpen={this.state.activeFlyout === 'Watcher'}
onClose={this.closeFlyouts}
urlParams={this.props.urlParams}
/>
</Fragment>
)}
</LicenseContext.Consumer>
);
}
}