11import 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' ;
311import { DataSourcePluginOptionsEditorProps } from '@grafana/data' ;
412import { SnowflakeOptions , SnowflakeSecureOptions } from './types' ;
513
6- const { SecretFormField, FormField, Switch } = LegacyForms ;
7-
814interface Props extends DataSourcePluginOptionsEditorProps < SnowflakeOptions > { }
915
1016interface State { }
1117
18+ const LABEL_WIDTH = 30
19+ const INPUT_WIDTH = 40
20+
1221export class ConfigEditor extends PureComponent < Props , State > {
1322 onAccountChange = ( event : ChangeEvent < HTMLInputElement > ) => {
1423 const { onOptionsChange, options } = this . props ;
@@ -21,7 +30,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
2130 }
2231
2332 // Sanitize value to avoid error
24- const regex = new RegExp ( ' https?://' ) ;
33+ const regex = / h t t p s ? : \/ \/ / ;
2534 value = value . replace ( regex , '' ) ;
2635
2736 const jsonData = {
@@ -139,7 +148,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
139148 } ) ;
140149 } ;
141150
142- onPrivateKeyChange = ( event : ChangeEvent < HTMLInputElement > ) => {
151+ onPrivateKeyChange = ( event : ChangeEvent < HTMLTextAreaElement > ) => {
143152 const { onOptionsChange, options } = this . props ;
144153 onOptionsChange ( {
145154 ...options ,
@@ -174,140 +183,134 @@ export class ConfigEditor extends PureComponent<Props, State> {
174183 < div className = "gf-form-group" >
175184 < h3 className = "page-heading" > Connection</ h3 >
176185
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
182190 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 ?? '' }
185192 placeholder = "xxxxxx.snowflakecomputing.com"
193+ width = { INPUT_WIDTH }
186194 />
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
194199 onChange = { this . onUsernameChange }
195- value = { jsonData . username || '' }
200+ value = { jsonData . username ?? '' }
196201 placeholder = "Username"
202+ width = { INPUT_WIDTH }
197203 />
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 } >
201208 < Switch
202- label = "basic or key pair authentication"
203- checked = { jsonData . basicAuth }
209+ checked = { jsonData . basicAuth ?? false }
210+ style = { { textAlign : 'center' } }
204211 onChange = { this . onAuthenticationChange }
205212 />
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 ?? '' }
213220 placeholder = "password"
214- labelWidth = { 10 }
215- inputWidth = { 20 }
221+ width = { INPUT_WIDTH }
216222 onReset = { this . onResetPassword }
217223 onChange = { this . onPasswordChange }
218224 />
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 ?? '' }
226234 placeholder = "MIIB..."
227- labelWidth = { 10 }
228- inputWidth = { 20 }
229235 onReset = { this . onResetPrivateKey }
230236 onChange = { this . onPrivateKeyChange }
237+ cols = { 38 }
238+ rows = { 5 }
231239 />
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 }
239246 onChange = { this . onRoleChange }
240- value = { jsonData . role || '' }
247+ value = { jsonData . role ?? '' }
241248 placeholder = "Role"
242249 />
243- </ div >
250+ </ InlineField >
244251 < br />
245252 < h3 className = "page-heading" > Parameter configuration</ h3 >
246253
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 }
252258 onChange = { this . onWarehouseChange }
253- value = { jsonData . warehouse || '' }
259+ value = { jsonData . warehouse ?? '' }
254260 placeholder = "Default warehouse"
255261 />
256- </ div >
262+ </ InlineField >
257263
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 }
263268 onChange = { this . onDatabaseChange }
264- value = { jsonData . database || '' }
269+ value = { jsonData . database ?? '' }
265270 placeholder = "Default database"
266271 />
267- </ div >
272+ </ InlineField >
268273
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 }
274278 onChange = { this . onSchemaChange }
275- value = { jsonData . schema || '' }
279+ value = { jsonData . schema ?? '' }
276280 placeholder = "Default Schema"
277281 />
278- </ div >
282+ </ InlineField >
279283 < br />
280284 < h3 className = "page-heading" > Session configuration</ h3 >
281285
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 }
287290 onChange = { this . onExtraOptionChange }
288- value = { jsonData . extraConfig || '' }
291+ value = { jsonData . extraConfig ?? '' }
289292 placeholder = "TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY& XXXXX = yyyyy & ..."
290293 />
291- </ div >
294+ </ InlineField >
292295 < br />
293296 < 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 }
299301 onChange = { this . onMaxChunkDownloadWorkersChange }
300- value = { jsonData . maxChunkDownloadWorkers || '10' }
302+ value = { jsonData . maxChunkDownloadWorkers ?? '10' }
301303 />
302- </ div >
304+ </ InlineField >
303305 < 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 >
311314 </ ControlledCollapse >
312315 </ div >
313316 ) ;
0 commit comments