Skip to content

Commit de87cf5

Browse files
authored
feat: replace obsolete components (#99)
* feat: replace obsolete components * Fix: remove deprecated components
1 parent 6f291cc commit de87cf5

File tree

7 files changed

+112
-110
lines changed

7 files changed

+112
-110
lines changed

.eslintcache

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## 2.0.0 (not released yet)
4-
3+
## 1.9.1
54

5+
### 🔨 Changed
6+
- Remove deprecated UI components
67

78
## 1.9.0
89

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "michelin-snowflake-datasource",
3-
"version": "2.0.0",
3+
"version": "1.9.1",
44
"description": "Data source for Snowflake",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

src/ConfigEditor.tsx

Lines changed: 97 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
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';
311
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
412
import { SnowflakeOptions, SnowflakeSecureOptions } from './types';
513

6-
const { SecretFormField, FormField, Switch } = LegacyForms;
7-
814
interface Props extends DataSourcePluginOptionsEditorProps<SnowflakeOptions> {}
915

1016
interface State {}
1117

18+
const LABEL_WIDTH = 30
19+
const INPUT_WIDTH = 40
20+
1221
export 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 = /https?:\/\//;
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
);

src/QueryEditor.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export class QueryEditor extends PureComponent<Props> {
1414
onQueryTextChange = (newQuery: string) => {
1515
const { onChange, query } = this.props;
1616
onChange({ ...query, queryText: newQuery });
17+
this.props.onRunQuery();
1718
};
1819

1920
onFormat = () => {
2021
try {
21-
let formatted = format(this.props.query.queryText || "", {
22+
let formatted = format(this.props.query.queryText ?? "", {
2223
language: 'snowflake',
2324
denseOperators: false,
2425
keywordCase: 'upper',
@@ -38,7 +39,7 @@ export class QueryEditor extends PureComponent<Props> {
3839
const { onChange, query } = this.props;
3940
onChange({
4041
...query,
41-
queryType: value.value || 'table',
42+
queryType: value.value ?? 'table',
4243
});
4344

4445
this.props.onRunQuery();
@@ -78,11 +79,11 @@ export class QueryEditor extends PureComponent<Props> {
7879
const query = defaults(this.props.query, defaultQuery);
7980
const { queryText, queryType, fillMode, timeColumns } = query;
8081
const selectedOption = this.options.find((options) => options.value === queryType) || this.options;
81-
const selectedFillMode = this.optionsFillMode.find((options) => options.value === fillMode)?.value || this.optionsFillMode[0].value;
82+
const selectedFillMode = this.optionsFillMode.find((options) => options.value === fillMode)?.value ?? this.optionsFillMode[0].value;
8283

8384
return (
8485
<div>
85-
<div className="gf-form max-width-25" role="query-type-container">
86+
<div className="gf-form max-width-25">
8687
<InlineFormLabel width={10}>Query Type</InlineFormLabel>
8788
<Select
8889
width={20}
@@ -96,14 +97,12 @@ export class QueryEditor extends PureComponent<Props> {
9697
<Field>
9798
<div>
9899
<CodeEditor
99-
value={queryText || ''}
100-
onBlur={this.props.onRunQuery}
101-
onChange={this.onQueryTextChange}
100+
value={queryText ?? ''}
101+
onBlur={this.onQueryTextChange}
102102
language="sql"
103103
showLineNumbers={true}
104104
height={'200px'}
105105
showMiniMap={false}
106-
onSave={this.props.onRunQuery}
107106
/>
108107
<Button variant="secondary" icon="repeat" onClick={this.onFormat}>Format Query</Button>
109108
</div>

src/datasource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class DataSource extends DataSourceWithBackend<SnowflakeQuery, SnowflakeO
3636
} as DataQueryRequest<SnowflakeQuery>)
3737
.pipe(
3838
switchMap((response) => {
39-
if (response.error) {
40-
console.log('Error: ' + response.error.message);
41-
throw new Error(response.error.message);
39+
if (response.errors) {
40+
console.log('Error: ' + response.errors?.map(value => value.message ?? '').join(','));
41+
throw new Error(response.errors?.map(value => value.message ?? '').join(','));
4242
}
4343
return response.data;
4444
}),

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DataQuery, DataSourceJsonData } from '@grafana/data';
1+
import { DataQuery, DataSourceJsonData } from '@grafana/schema';
22

33
export interface SnowflakeQuery extends DataQuery {
44
queryText?: string;

0 commit comments

Comments
 (0)