1
1
import React , { ChangeEvent , PureComponent } from 'react' ;
2
- import { Checkbox , ControlledCollapse , LegacyForms } from '@grafana/ui' ;
2
+ import {
3
+ Checkbox ,
4
+ ControlledCollapse ,
5
+ InlineField ,
6
+ Input ,
7
+ SecretInput ,
8
+ SecretTextArea ,
9
+ Switch
10
+ } from '@grafana/ui' ;
3
11
import { DataSourcePluginOptionsEditorProps } from '@grafana/data' ;
4
12
import { SnowflakeOptions , SnowflakeSecureOptions } from './types' ;
5
13
6
- const { SecretFormField, FormField, Switch } = LegacyForms ;
7
-
8
14
interface Props extends DataSourcePluginOptionsEditorProps < SnowflakeOptions > { }
9
15
10
16
interface State { }
11
17
18
+ const LABEL_WIDTH = 30
19
+ const INPUT_WIDTH = 40
20
+
12
21
export class ConfigEditor extends PureComponent < Props , State > {
13
22
onAccountChange = ( event : ChangeEvent < HTMLInputElement > ) => {
14
23
const { onOptionsChange, options } = this . props ;
@@ -21,7 +30,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
21
30
}
22
31
23
32
// Sanitize value to avoid error
24
- const regex = new RegExp ( ' https?://' ) ;
33
+ const regex = / h t t p s ? : \/ \/ / ;
25
34
value = value . replace ( regex , '' ) ;
26
35
27
36
const jsonData = {
@@ -139,7 +148,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
139
148
} ) ;
140
149
} ;
141
150
142
- onPrivateKeyChange = ( event : ChangeEvent < HTMLInputElement > ) => {
151
+ onPrivateKeyChange = ( event : ChangeEvent < HTMLTextAreaElement > ) => {
143
152
const { onOptionsChange, options } = this . props ;
144
153
onOptionsChange ( {
145
154
...options ,
@@ -174,140 +183,134 @@ export class ConfigEditor extends PureComponent<Props, State> {
174
183
< div className = "gf-form-group" >
175
184
< h3 className = "page-heading" > Connection</ h3 >
176
185
177
- < div className = "gf-form" >
178
- < FormField
179
- label = "Account name"
180
- labelWidth = { 10 }
181
- inputWidth = { 30 }
186
+ < InlineField label = "Account name"
187
+ tooltip = "All access to Snowflake is either through your account name (provided by Snowflake) or a URL that uses the following format: `xxxxx.snowflakecomputing.com`"
188
+ labelWidth = { LABEL_WIDTH } >
189
+ < Input
182
190
onChange = { this . onAccountChange }
183
- tooltip = "All access to Snowflake is either through your account name (provided by Snowflake) or a URL that uses the following format: `xxxxx.snowflakecomputing.com`"
184
- value = { jsonData . account || '' }
191
+ value = { jsonData . account ?? '' }
185
192
placeholder = "xxxxxx.snowflakecomputing.com"
193
+ width = { INPUT_WIDTH }
186
194
/>
187
- </ div >
188
-
189
- < div className = "gf-form" >
190
- < FormField
191
- label = "Username"
192
- labelWidth = { 10 }
193
- inputWidth = { 20 }
195
+ </ InlineField >
196
+ < InlineField label = "Username"
197
+ labelWidth = { LABEL_WIDTH } >
198
+ < Input
194
199
onChange = { this . onUsernameChange }
195
- value = { jsonData . username || '' }
200
+ value = { jsonData . username ?? '' }
196
201
placeholder = "Username"
202
+ width = { INPUT_WIDTH }
197
203
/>
198
- </ div >
199
-
200
- < div className = "gf-form" >
204
+ </ InlineField >
205
+ < InlineField label = "basic or key pair authentication"
206
+ style = { { alignItems : 'center' } }
207
+ labelWidth = { LABEL_WIDTH } >
201
208
< Switch
202
- label = "basic or key pair authentication"
203
- checked = { jsonData . basicAuth }
209
+ checked = { jsonData . basicAuth ?? false }
210
+ style = { { textAlign : 'center' } }
204
211
onChange = { this . onAuthenticationChange }
205
212
/>
206
- </ div >
207
- < div className = "gf-form" >
208
- { ! jsonData . basicAuth && (
209
- < SecretFormField
210
- isConfigured = { ( secureJsonFields && secureJsonFields . password ) as boolean }
211
- value = { secureJsonData . password || '' }
212
- label = "Password"
213
+ </ InlineField >
214
+ { ! jsonData . basicAuth && (
215
+ < InlineField label = "Password"
216
+ labelWidth = { LABEL_WIDTH } >
217
+ < SecretInput
218
+ isConfigured = { secureJsonFields ? .password }
219
+ value = { secureJsonData . password ?? '' }
213
220
placeholder = "password"
214
- labelWidth = { 10 }
215
- inputWidth = { 20 }
221
+ width = { INPUT_WIDTH }
216
222
onReset = { this . onResetPassword }
217
223
onChange = { this . onPasswordChange }
218
224
/>
219
- ) }
220
- { jsonData . basicAuth && (
221
- < SecretFormField
222
- isConfigured = { ( secureJsonFields && secureJsonFields . privateKey ) as boolean }
223
- value = { secureJsonData . privateKey || '' }
224
- tooltip = "The private key must be encoded in base 64 URL encoded pkcs8 (remove PEM header '----- BEGIN PRIVATE KEY -----' and '----- END PRIVATE KEY -----', remove line space and replace '+' with '-' and '/' with '_')"
225
- label = "Private key"
225
+ </ InlineField >
226
+ ) }
227
+ { jsonData . basicAuth && (
228
+ < InlineField label = "Private key"
229
+ tooltip = "The private key must be encoded in base 64 URL encoded pkcs8 (remove PEM header '----- BEGIN PRIVATE KEY -----' and '----- END PRIVATE KEY -----', remove line space and replace '+' with '-' and '/' with '_')"
230
+ labelWidth = { LABEL_WIDTH } >
231
+ < SecretTextArea
232
+ isConfigured = { secureJsonFields ?. privateKey }
233
+ value = { secureJsonData . privateKey ?? '' }
226
234
placeholder = "MIIB..."
227
- labelWidth = { 10 }
228
- inputWidth = { 20 }
229
235
onReset = { this . onResetPrivateKey }
230
236
onChange = { this . onPrivateKeyChange }
237
+ cols = { 38 }
238
+ rows = { 5 }
231
239
/>
232
- ) }
233
- </ div >
234
- < div className = "gf-form" >
235
- < FormField
236
- label = "Role"
237
- labelWidth = { 10 }
238
- inputWidth = { 20 }
240
+ </ InlineField >
241
+ ) }
242
+ < InlineField label = "Role"
243
+ labelWidth = { LABEL_WIDTH } >
244
+ < Input
245
+ width = { INPUT_WIDTH }
239
246
onChange = { this . onRoleChange }
240
- value = { jsonData . role || '' }
247
+ value = { jsonData . role ?? '' }
241
248
placeholder = "Role"
242
249
/>
243
- </ div >
250
+ </ InlineField >
244
251
< br />
245
252
< h3 className = "page-heading" > Parameter configuration</ h3 >
246
253
247
- < div className = "gf-form" >
248
- < FormField
249
- label = "Warehouse"
250
- labelWidth = { 10 }
251
- inputWidth = { 20 }
254
+ < InlineField label = "Warehouse"
255
+ labelWidth = { LABEL_WIDTH } >
256
+ < Input
257
+ width = { INPUT_WIDTH }
252
258
onChange = { this . onWarehouseChange }
253
- value = { jsonData . warehouse || '' }
259
+ value = { jsonData . warehouse ?? '' }
254
260
placeholder = "Default warehouse"
255
261
/>
256
- </ div >
262
+ </ InlineField >
257
263
258
- < div className = "gf-form" >
259
- < FormField
260
- label = "Database"
261
- labelWidth = { 10 }
262
- inputWidth = { 20 }
264
+ < InlineField label = "Database"
265
+ labelWidth = { LABEL_WIDTH } >
266
+ < Input
267
+ width = { INPUT_WIDTH }
263
268
onChange = { this . onDatabaseChange }
264
- value = { jsonData . database || '' }
269
+ value = { jsonData . database ?? '' }
265
270
placeholder = "Default database"
266
271
/>
267
- </ div >
272
+ </ InlineField >
268
273
269
- < div className = "gf-form" >
270
- < FormField
271
- label = "Schema"
272
- labelWidth = { 10 }
273
- inputWidth = { 20 }
274
+ < InlineField label = "Schema"
275
+ labelWidth = { LABEL_WIDTH } >
276
+ < Input
277
+ width = { INPUT_WIDTH }
274
278
onChange = { this . onSchemaChange }
275
- value = { jsonData . schema || '' }
279
+ value = { jsonData . schema ?? '' }
276
280
placeholder = "Default Schema"
277
281
/>
278
- </ div >
282
+ </ InlineField >
279
283
< br />
280
284
< h3 className = "page-heading" > Session configuration</ h3 >
281
285
282
- < div className = "gf-form" >
283
- < FormField
284
- label = "Extra options"
285
- labelWidth = { 10 }
286
- inputWidth = { 30 }
286
+ < InlineField label = "Extra options"
287
+ labelWidth = { LABEL_WIDTH } >
288
+ < Input
289
+ width = { INPUT_WIDTH }
287
290
onChange = { this . onExtraOptionChange }
288
- value = { jsonData . extraConfig || '' }
291
+ value = { jsonData . extraConfig ?? '' }
289
292
placeholder = "TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY& XXXXX = yyyyy & ..."
290
293
/>
291
- </ div >
294
+ </ InlineField >
292
295
< br />
293
296
< ControlledCollapse label = "Experimental" >
294
- < div className = "gf-form" >
295
- < FormField
296
- label = "Max Chunk Download Workers"
297
- labelWidth = { 15 }
298
- inputWidth = { 3 }
297
+ < InlineField label = "Max Chunk Download Workers"
298
+ labelWidth = { LABEL_WIDTH } >
299
+ < Input
300
+ width = { INPUT_WIDTH }
299
301
onChange = { this . onMaxChunkDownloadWorkersChange }
300
- value = { jsonData . maxChunkDownloadWorkers || '10' }
302
+ value = { jsonData . maxChunkDownloadWorkers ?? '10' }
301
303
/>
302
- </ div >
304
+ </ InlineField >
303
305
< br />
304
- < div className = "gf-form" >
305
- < Checkbox
306
- value = { jsonData . customJSONDecoderEnabled }
307
- onChange = { this . onCustomJSONDecoderEnabledChange }
308
- label = "Enable Custom JSON Decoder"
309
- />
310
- </ div >
306
+ < InlineField label = "Enable Custom JSON Decoder"
307
+ style = { { alignItems : 'center' } }
308
+ labelWidth = { LABEL_WIDTH } >
309
+ < Checkbox
310
+ value = { jsonData . customJSONDecoderEnabled ?? false }
311
+ onChange = { this . onCustomJSONDecoderEnabledChange }
312
+ />
313
+ </ InlineField >
311
314
</ ControlledCollapse >
312
315
</ div >
313
316
) ;
0 commit comments