8
8
Input ,
9
9
RadioButtonGroup ,
10
10
SecretInput ,
11
- Checkbox ,
12
11
} from '@grafana/ui' ;
13
12
import { DataSourcePluginOptionsEditorProps , SelectableValue } from '@grafana/data' ;
14
13
import {
@@ -18,7 +17,7 @@ import {
18
17
ConnectionStringScheme ,
19
18
} from '../types' ;
20
19
21
- interface Props extends DataSourcePluginOptionsEditorProps < MongoDataSourceOptions , MongoDataSourceSecureJsonData > { }
20
+ interface Props extends DataSourcePluginOptionsEditorProps < MongoDataSourceOptions , MongoDataSourceSecureJsonData > { }
22
21
23
22
const mongoDBAuthMethods : SelectableValue [ ] = [
24
23
{ label : 'None' , value : MongoDBAuthMethod . NONE } ,
@@ -47,119 +46,56 @@ export function ConfigEditor(props: Props) {
47
46
jsonData . connectionStringScheme = ConnectionStringScheme . STANDARD ;
48
47
}
49
48
50
- const onHostChange = ( event : ChangeEvent < HTMLInputElement > ) => {
51
- onOptionsChange ( {
52
- ...options ,
53
- jsonData : {
54
- ...jsonData ,
55
- host : event . target . value ,
56
- } ,
57
- } ) ;
58
- } ;
59
-
60
- const onUsernameChange = ( event : ChangeEvent < HTMLInputElement > ) => {
61
- onOptionsChange ( {
62
- ...options ,
63
- jsonData : {
64
- ...jsonData ,
65
- username : event . target . value ,
66
- } ,
67
- } ) ;
68
- } ;
69
-
70
- const onConnectionParametersChange = ( event : ChangeEvent < HTMLInputElement > ) => {
71
- onOptionsChange ( {
72
- ...options ,
73
- jsonData : {
74
- ...jsonData ,
75
- connectionParameters : event . target . value ,
76
- } ,
77
- } ) ;
78
- } ;
79
-
80
- const onPortChange = ( event : ChangeEvent < HTMLInputElement > ) => {
81
- onOptionsChange ( {
82
- ...options ,
83
- jsonData : {
84
- ...jsonData ,
85
- port : event . target . valueAsNumber ,
86
- } ,
87
- } ) ;
88
- } ;
89
-
90
- const onDatabaseChange = ( event : ChangeEvent < HTMLInputElement > ) => {
91
- onOptionsChange ( {
92
- ...options ,
93
- jsonData : {
94
- ...jsonData ,
95
- database : event . target . value ,
96
- } ,
97
- } ) ;
98
- } ;
99
-
100
- const onAuthTypeChange = ( authType : string ) => {
101
- onOptionsChange ( {
102
- ...options ,
103
- jsonData : {
104
- ...jsonData ,
105
- authType : authType ,
106
- } ,
107
- } ) ;
108
- } ;
109
-
110
- const onConnectionStringSchemeChange = ( scheme : string ) => {
111
- onOptionsChange ( {
112
- ...options ,
113
- jsonData : {
114
- ...jsonData ,
115
- connectionStringScheme : scheme ,
116
- } ,
117
- } ) ;
118
- } ;
119
-
120
- const onPasswordChange = ( event : ChangeEvent < HTMLInputElement > ) => {
121
- onOptionsChange ( {
122
- ...options ,
123
- secureJsonData : {
124
- password : event . target . value ,
125
- } ,
126
- } ) ;
127
- } ;
128
-
129
- const onResetPassword = ( ) => {
130
- onOptionsChange ( {
131
- ...options ,
132
- secureJsonFields : {
133
- ...options . secureJsonFields ,
134
- password : false ,
135
- } ,
136
- secureJsonData : {
137
- ...options . secureJsonData ,
138
- password : '' ,
139
- } ,
140
- } ) ;
141
- } ;
142
-
143
49
return (
144
50
< >
145
51
< Field label = "Connection string scheme" >
146
52
< RadioButtonGroup
147
53
options = { mongoConnectionStringSchemes }
148
54
value = { jsonData . connectionStringScheme || ConnectionStringScheme . STANDARD }
149
- onChange = { onConnectionStringSchemeChange }
55
+ onChange = { ( scheme : string ) => {
56
+ onOptionsChange ( {
57
+ ...options ,
58
+ jsonData : {
59
+ ...jsonData ,
60
+ connectionStringScheme : scheme ,
61
+ } ,
62
+ } ) ;
63
+ } }
150
64
/>
151
65
</ Field >
152
66
< InlineFieldRow label = "Connection" >
153
67
< InlineField label = "Host" tooltip = "MongoDB host address" >
154
- < Input required id = "config-editor-host" value = { jsonData . host } onChange = { onHostChange } width = { 30 } > </ Input >
68
+ < Input
69
+ required
70
+ id = "config-editor-host"
71
+ value = { jsonData . host }
72
+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) => {
73
+ onOptionsChange ( {
74
+ ...options ,
75
+ jsonData : {
76
+ ...jsonData ,
77
+ host : event . target . value ,
78
+ } ,
79
+ } ) ;
80
+ } }
81
+ width = { 30 }
82
+ > </ Input >
155
83
</ InlineField >
156
84
{ jsonData . connectionStringScheme === ConnectionStringScheme . STANDARD && (
157
85
< InlineField label = "Port" tooltip = "MongoDB port" >
158
86
< Input
159
87
id = "config-editor-port"
160
88
value = { jsonData . port }
161
89
type = "number"
162
- onChange = { onPortChange }
90
+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) => {
91
+ onOptionsChange ( {
92
+ ...options ,
93
+ jsonData : {
94
+ ...jsonData ,
95
+ port : event . target . valueAsNumber ,
96
+ } ,
97
+ } ) ;
98
+ } }
163
99
width = { 15 }
164
100
defaultValue = { 27017 }
165
101
> </ Input >
@@ -172,7 +108,15 @@ export function ConfigEditor(props: Props) {
172
108
required
173
109
id = "config-editor-database"
174
110
value = { jsonData . database }
175
- onChange = { onDatabaseChange }
111
+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) => {
112
+ onOptionsChange ( {
113
+ ...options ,
114
+ jsonData : {
115
+ ...jsonData ,
116
+ database : event . target . value ,
117
+ } ,
118
+ } ) ;
119
+ } }
176
120
width = { 30 }
177
121
> </ Input >
178
122
</ InlineField >
@@ -185,7 +129,15 @@ export function ConfigEditor(props: Props) {
185
129
required
186
130
id = "config-editor-connection-parameters"
187
131
value = { jsonData . connectionParameters }
188
- onChange = { onConnectionParametersChange }
132
+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) => {
133
+ onOptionsChange ( {
134
+ ...options ,
135
+ jsonData : {
136
+ ...jsonData ,
137
+ connectionParameters : event . target . value ,
138
+ } ,
139
+ } ) ;
140
+ } }
189
141
width = { 35 }
190
142
> </ Input >
191
143
</ InlineField >
@@ -195,7 +147,15 @@ export function ConfigEditor(props: Props) {
195
147
< RadioButtonGroup
196
148
options = { mongoDBAuthMethods }
197
149
value = { jsonData . authType || MongoDBAuthMethod . NONE }
198
- onChange = { onAuthTypeChange }
150
+ onChange = { ( authType : string ) => {
151
+ onOptionsChange ( {
152
+ ...options ,
153
+ jsonData : {
154
+ ...jsonData ,
155
+ authType : authType ,
156
+ } ,
157
+ } ) ;
158
+ } }
199
159
/>
200
160
</ Field >
201
161
</ FieldSet >
@@ -207,7 +167,15 @@ export function ConfigEditor(props: Props) {
207
167
required
208
168
id = "config-editor-username"
209
169
value = { jsonData . username }
210
- onChange = { onUsernameChange }
170
+ onChange = { ( evt : ChangeEvent < HTMLInputElement > ) => {
171
+ onOptionsChange ( {
172
+ ...options ,
173
+ jsonData : {
174
+ ...jsonData ,
175
+ username : evt . target . value ,
176
+ } ,
177
+ } ) ;
178
+ } }
211
179
width = { 35 }
212
180
> </ Input >
213
181
</ InlineField >
@@ -218,57 +186,80 @@ export function ConfigEditor(props: Props) {
218
186
isConfigured = { secureJsonFields . password }
219
187
value = { secureJsonData ?. password || '' }
220
188
width = { 35 }
221
- onReset = { onResetPassword }
222
- onChange = { onPasswordChange }
189
+ onReset = { ( ) => {
190
+ onOptionsChange ( {
191
+ ...options ,
192
+ secureJsonFields : {
193
+ ...options . secureJsonFields ,
194
+ password : false ,
195
+ } ,
196
+ secureJsonData : {
197
+ ...options . secureJsonData ,
198
+ password : '' ,
199
+ } ,
200
+ } ) ;
201
+ } }
202
+ onChange = { ( event : ChangeEvent < HTMLInputElement > ) => {
203
+ onOptionsChange ( {
204
+ ...options ,
205
+ secureJsonData : {
206
+ password : event . target . value ,
207
+ } ,
208
+ } ) ;
209
+ } }
223
210
/>
224
211
</ InlineField >
225
212
</ >
226
213
) }
227
214
228
215
{ jsonData . authType === MongoDBAuthMethod . TLS_SSL && (
229
216
< >
230
- < Field label = "Certificate Authority" >
217
+ < Field label = "Certificate Authority" description = "Path to Certificate Authority (.pem)" >
231
218
< Input
232
219
required
233
220
id = "config-editor-tls-ca"
234
221
value = { jsonData . caCertPath }
235
- onChange = { ( evt : ChangeEvent < HTMLInputElement > ) => onOptionsChange ( {
236
- ...options ,
237
- jsonData : {
238
- ...jsonData ,
239
- caCertPath : evt . target . value ,
240
- } ,
241
- } ) }
242
-
222
+ onChange = { ( evt : ChangeEvent < HTMLInputElement > ) =>
223
+ onOptionsChange ( {
224
+ ...options ,
225
+ jsonData : {
226
+ ...jsonData ,
227
+ caCertPath : evt . target . value ,
228
+ } ,
229
+ } )
230
+ }
243
231
> </ Input >
244
232
</ Field >
245
233
< Field label = "Client Certificate" description = "Path to public client certificate (.pem)" >
246
234
< Input
247
235
required
248
236
id = "config-editor-tls-cc"
249
237
value = { jsonData . clientCertPath }
250
- onChange = { ( evt : ChangeEvent < HTMLInputElement > ) => onOptionsChange ( {
251
- ...options ,
252
- jsonData : {
253
- ...jsonData ,
254
- clientCertPath : evt . target . value ,
255
- } ,
256
- } ) }
257
-
238
+ onChange = { ( evt : ChangeEvent < HTMLInputElement > ) =>
239
+ onOptionsChange ( {
240
+ ...options ,
241
+ jsonData : {
242
+ ...jsonData ,
243
+ clientCertPath : evt . target . value ,
244
+ } ,
245
+ } )
246
+ }
258
247
> </ Input >
259
248
</ Field >
260
249
< Field label = "Client Key" description = "Path to private client key (.pem)" >
261
250
< Input
262
251
required
263
252
id = "config-editor-tls-ck"
264
253
value = { jsonData . clientKeyPath }
265
- onChange = { ( evt : ChangeEvent < HTMLInputElement > ) => onOptionsChange ( {
266
- ...options ,
267
- jsonData : {
268
- ...jsonData ,
269
- clientKeyPath : evt . target . value ,
270
- } ,
271
- } ) }
254
+ onChange = { ( evt : ChangeEvent < HTMLInputElement > ) =>
255
+ onOptionsChange ( {
256
+ ...options ,
257
+ jsonData : {
258
+ ...jsonData ,
259
+ clientKeyPath : evt . target . value ,
260
+ } ,
261
+ } )
262
+ }
272
263
> </ Input >
273
264
</ Field >
274
265
< Field label = "Client Key Password" >
@@ -301,29 +292,8 @@ export function ConfigEditor(props: Props) {
301
292
}
302
293
/>
303
294
</ Field >
304
- < Checkbox
305
- value = { false }
306
- label = "tlsInsecure"
307
- description = "This includes tlsAllowInvalidHostnames and tlsAllowInvalidCertificates."
308
- />
309
- < Checkbox
310
- value = { false }
311
- label = "tlsAllowInvalidHostnames"
312
- description = "Disable the validation of the hostnames in the certificate presented by the mongod/mongos instance."
313
- />
314
- < Checkbox
315
- value = { false }
316
- label = "tlsAllowInvalidCertificates"
317
- description = "This includes tlsAllowInvalidHostnames and tlsAllowInvalidCertificates."
318
- />
319
- < Checkbox
320
- value = { false }
321
- label = "tlsInsecure"
322
- description = "Disable the validation of the server certificates."
323
- />
324
295
</ >
325
- )
326
- }
296
+ ) }
327
297
</ >
328
298
) ;
329
299
}
0 commit comments