-
Notifications
You must be signed in to change notification settings - Fork 1k
/
InputListItem.jsx
268 lines (236 loc) · 9.36 KB
/
InputListItem.jsx
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import PropTypes from 'prop-types';
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import createReactClass from 'create-react-class';
import Reflux from 'reflux';
import AppConfig from 'util/AppConfig';
import { LinkContainer } from 'components/common/router';
import { DropdownButton, MenuItem, Col, Button } from 'components/bootstrap';
import { EntityListItem, IfPermitted, LinkToNode, Spinner } from 'components/common';
import { ConfigurationWell } from 'components/configurationforms';
import PermissionsMixin from 'util/PermissionsMixin';
import Routes from 'routing/Routes';
import recentMessagesTimeRange from 'util/TimeRangeHelper';
import {
InputForm,
InputStateBadge,
InputStateControl,
InputStaticFields,
InputThroughput,
StaticFieldForm,
} from 'components/inputs';
import { InputsActions } from 'stores/inputs/InputsStore';
import { InputTypesStore } from 'stores/inputs/InputTypesStore';
import withTelemetry from 'logic/telemetry/withTelemetry';
import { getPathnameWithoutId } from 'util/URLUtils';
import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants';
import withLocation from 'routing/withLocation';
const InputListItem = createReactClass({
// eslint-disable-next-line react/no-unused-class-component-methods
displayName: 'InputListItem',
// eslint-disable-next-line react/no-unused-class-component-methods
propTypes: {
input: PropTypes.object.isRequired,
currentNode: PropTypes.object.isRequired,
permissions: PropTypes.array.isRequired,
sendTelemetry: PropTypes.func.isRequired,
location: PropTypes.object.isRequired,
},
mixins: [PermissionsMixin, Reflux.connect(InputTypesStore)],
_deleteInput() {
this.props.sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.INPUT_DELETED, {
app_pathname: getPathnameWithoutId(this.props.location.pathname),
app_action_value: 'input-delete',
});
// eslint-disable-next-line no-alert
if (window.confirm(`Do you really want to delete input '${this.props.input.title}'?`)) {
InputsActions.delete(this.props.input);
}
},
_openStaticFieldForm() {
this.staticFieldForm.open();
},
_editInput() {
const { sendTelemetry, location } = this.props;
this.configurationForm.open();
sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.INPUT_EDIT_CLICKED, {
app_pathname: getPathnameWithoutId(location.pathname),
app_action_value: 'show-received-messages',
});
},
_updateInput(data) {
InputsActions.update(this.props.input.id, data);
this.props.sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.INPUT_UPDATED, {
app_pathname: getPathnameWithoutId(this.props.location.pathname),
app_action_value: 'input-edit',
});
},
render() {
if (!this.state.inputTypes) {
return <Spinner />;
}
const { input, sendTelemetry, location } = this.props;
const definition = this.state.inputDescriptions[input.type];
const titleSuffix = (
<span>
{this.props.input.name}
({this.props.input.id})
<InputStateBadge input={this.props.input} />
</span>
);
const actions = [];
const queryField = (input.type === 'org.graylog.plugins.forwarder.input.ForwarderServiceInput') ? 'gl2_forwarder_input' : 'gl2_source_input';
if (this.isPermitted(this.props.permissions, ['searches:relative'])) {
actions.push(
<LinkContainer key={`received-messages-${this.props.input.id}`}
to={Routes.search(`${queryField}:${this.props.input.id}`, recentMessagesTimeRange())}>
<Button onClick={() => {
sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.SHOW_RECEIVED_MESSAGES_CLICKED, {
app_pathname: getPathnameWithoutId(location.pathname),
app_action_value: 'show-received-messages',
});
}}>
Show received messages
</Button>
</LinkContainer>,
);
}
if (this.isPermitted(this.props.permissions, [`inputs:edit:${this.props.input.id}`])) {
if (!AppConfig.isCloud()) {
let extractorRoute;
if (this.props.input.global) {
extractorRoute = Routes.global_input_extractors(this.props.input.id);
} else {
extractorRoute = Routes.local_input_extractors(this.props.currentNode.node_id, this.props.input.id);
}
actions.push(
<LinkContainer key={`manage-extractors-${this.props.input.id}`} to={extractorRoute}>
<Button onClick={() => {
sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.MANAGE_EXTRACTORS_CLICKED, {
app_pathname: getPathnameWithoutId(location.pathname),
app_action_value: 'manage-extractors',
});
}}>
Manage extractors
</Button>
</LinkContainer>,
);
}
actions.push(<InputStateControl key={`input-state-control-${this.props.input.id}`} input={this.props.input} />);
}
let showMetricsMenuItem;
if (!this.props.input.global) {
showMetricsMenuItem = (
<LinkContainer to={Routes.filtered_metrics(this.props.input.node, this.props.input.id)}>
<MenuItem key={`show-metrics-${this.props.input.id}`}
onClick={() => {
sendTelemetry(TELEMETRY_EVENT_TYPE.INPUTS.SHOW_METRICS_CLICKED, {
app_pathname: getPathnameWithoutId(location.pathname),
app_action_value: 'show-metrics',
});
}}>
Show metrics
</MenuItem>
</LinkContainer>
);
}
actions.push(
<DropdownButton key={`more-actions-${this.props.input.id}`}
title="More actions"
id={`more-actions-dropdown-${this.props.input.id}`}
pullRight>
<IfPermitted permissions={`inputs:edit:${this.props.input.id}`}>
<MenuItem key={`edit-input-${this.props.input.id}`}
onSelect={this._editInput}
disabled={definition === undefined}>
Edit input
</MenuItem>
</IfPermitted>
{showMetricsMenuItem}
<IfPermitted permissions={`inputs:edit:${this.props.input.id}`}>
<MenuItem key={`add-static-field-${this.props.input.id}`} onSelect={this._openStaticFieldForm}>Add static
field
</MenuItem>
</IfPermitted>
<IfPermitted permissions="inputs:terminate">
<MenuItem key={`divider-${this.props.input.id}`} divider />
</IfPermitted>
<IfPermitted permissions="inputs:terminate">
<MenuItem key={`delete-input-${this.props.input.id}`} onSelect={this._deleteInput}>Delete input</MenuItem>
</IfPermitted>
</DropdownButton>,
);
let subtitle;
if (!this.props.input.global && this.props.input.node) {
subtitle = (
<span>
On node{' '}<LinkToNode nodeId={this.props.input.node} />
</span>
);
}
const inputForm = definition
? (
<InputForm ref={(configurationForm) => {
this.configurationForm = configurationForm;
}}
key={`edit-form-input-${input.id}`}
globalValue={input.global}
nodeValue={input.node}
configFields={definition.requested_configuration}
title={`Editing Input ${input.title}`}
titleValue={input.title}
typeName={input.type}
includeTitleField
submitAction={this._updateInput}
submitButtonText="Update input"
values={input.attributes} />
) : null;
const additionalContent = (
<div>
<Col md={8}>
<ConfigurationWell className="configuration-well"
id={input.id}
configuration={input.attributes}
typeDefinition={definition || {}} />
<StaticFieldForm ref={(staticFieldForm) => {
this.staticFieldForm = staticFieldForm;
}}
input={this.props.input} />
<InputStaticFields input={this.props.input} />
</Col>
<Col md={4}>
<InputThroughput input={input} />
</Col>
{inputForm}
</div>
);
return (
<EntityListItem key={`entry-list-${this.props.input.id}`}
title={this.props.input.title}
titleSuffix={titleSuffix}
description={subtitle}
createdFromContentPack={!!this.props.input.content_pack}
actions={actions}
contentRow={additionalContent} />
);
},
});
export default withLocation(withTelemetry(InputListItem));