@grafana/create-plugin 0.10.0 → 0.11.0-canary.172.d1fcc2b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "0.10.0",
3
+ "version": "0.11.0-canary.172.d1fcc2b.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=16"
62
62
  },
63
- "gitHead": "4528730fa262596399c6e1b0158311ae31bf64bd"
63
+ "gitHead": "d1fcc2b10cc167f921a7b0ca131ddaef8286317c"
64
64
  }
@@ -3,6 +3,7 @@ package plugin
3
3
  import (
4
4
  "context"
5
5
  "encoding/json"
6
+ "fmt"
6
7
  "math/rand"
7
8
  "time"
8
9
 
@@ -73,10 +74,12 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query
73
74
 
74
75
  err := json.Unmarshal(query.JSON, &qm)
75
76
  if err != nil {
76
- return backend.ErrDataResponse(backend.StatusBadRequest, "json unmarshal: " + err.Error())
77
+ return backend.ErrDataResponse(backend.StatusBadRequest, fmt.Sprintf("json unmarshal: %v", err.Error()))
77
78
  }
78
79
 
79
80
  // create data frame response.
81
+ // For an overview on data frames and how grafana handles them:
82
+ // https://grafana.com/docs/grafana/latest/developers/plugins/data-frames/
80
83
  frame := data.NewFrame("response")
81
84
 
82
85
  // add fields.
@@ -1,17 +1,13 @@
1
- import React, { ChangeEvent, PureComponent } from 'react';
2
- import { LegacyForms } from '@grafana/ui';
1
+ import React, { ChangeEvent } from 'react';
2
+ import { InlineField, Input, SecretInput } from '@grafana/ui';
3
3
  import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
4
4
  import { MyDataSourceOptions, MySecureJsonData } from '../types';
5
5
 
6
- const { SecretFormField, FormField } = LegacyForms;
7
-
8
6
  interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions> {}
9
7
 
10
- interface State {}
11
-
12
- export class ConfigEditor extends PureComponent<Props, State> {
13
- onPathChange = (event: ChangeEvent<HTMLInputElement>) => {
14
- const { onOptionsChange, options } = this.props;
8
+ export function ConfigEditor(props: Props) {
9
+ const { onOptionsChange, options } = props;
10
+ const onPathChange = (event: ChangeEvent<HTMLInputElement>) => {
15
11
  const jsonData = {
16
12
  ...options.jsonData,
17
13
  path: event.target.value,
@@ -20,8 +16,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
20
16
  };
21
17
 
22
18
  // Secure field (only sent to the backend)
23
- onAPIKeyChange = (event: ChangeEvent<HTMLInputElement>) => {
24
- const { onOptionsChange, options } = this.props;
19
+ const onAPIKeyChange = (event: ChangeEvent<HTMLInputElement>) => {
25
20
  onOptionsChange({
26
21
  ...options,
27
22
  secureJsonData: {
@@ -30,8 +25,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
30
25
  });
31
26
  };
32
27
 
33
- onResetAPIKey = () => {
34
- const { onOptionsChange, options } = this.props;
28
+ const onResetAPIKey = () => {
35
29
  onOptionsChange({
36
30
  ...options,
37
31
  secureJsonFields: {
@@ -45,39 +39,29 @@ export class ConfigEditor extends PureComponent<Props, State> {
45
39
  });
46
40
  };
47
41
 
48
- render() {
49
- const { options } = this.props;
50
- const { jsonData, secureJsonFields } = options;
51
- const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;
52
-
53
- return (
54
- <div className="gf-form-group">
55
- <div className="gf-form">
56
- <FormField
57
- label="Path"
58
- labelWidth={6}
59
- inputWidth={20}
60
- onChange={this.onPathChange}
61
- value={jsonData.path || ''}
62
- placeholder="json field returned to frontend"
63
- />
64
- </div>
42
+ const { jsonData, secureJsonFields } = options;
43
+ const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;
65
44
 
66
- <div className="gf-form-inline">
67
- <div className="gf-form">
68
- <SecretFormField
69
- isConfigured={(secureJsonFields && secureJsonFields.apiKey) as boolean}
70
- value={secureJsonData.apiKey || ''}
71
- label="API Key"
72
- placeholder="secure json field (backend only)"
73
- labelWidth={6}
74
- inputWidth={20}
75
- onReset={this.onResetAPIKey}
76
- onChange={this.onAPIKeyChange}
77
- />
78
- </div>
79
- </div>
80
- </div>
81
- );
82
- }
45
+ return (
46
+ <div className="gf-form-group">
47
+ <InlineField label="Path" labelWidth={12}>
48
+ <Input
49
+ onChange={onPathChange}
50
+ value={jsonData.path || ''}
51
+ placeholder="json field returned to frontend"
52
+ width={40}
53
+ />
54
+ </InlineField>
55
+ <InlineField label="API Key" labelWidth={12}>
56
+ <SecretInput
57
+ isConfigured={(secureJsonFields && secureJsonFields.apiKey) as boolean}
58
+ value={secureJsonData.apiKey || ''}
59
+ placeholder="secure json field (backend only)"
60
+ width={40}
61
+ onReset={onResetAPIKey}
62
+ onChange={onAPIKeyChange}
63
+ />
64
+ </InlineField>
65
+ </div>
66
+ );
83
67
  }
@@ -1,47 +1,32 @@
1
- import React, { ChangeEvent, PureComponent } from 'react';
2
- import { LegacyForms } from '@grafana/ui';
1
+ import React, { ChangeEvent } from 'react';
2
+ import { InlineField, Input } from '@grafana/ui';
3
3
  import { QueryEditorProps } from '@grafana/data';
4
4
  import { DataSource } from '../datasource';
5
5
  import { MyDataSourceOptions, MyQuery } from '../types';
6
6
 
7
- const { FormField } = LegacyForms;
8
-
9
7
  type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
10
8
 
11
- export class QueryEditor extends PureComponent<Props> {
12
- onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
13
- const { onChange, query } = this.props;
9
+ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
10
+ const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
14
11
  onChange({ ...query, queryText: event.target.value });
15
12
  };
16
13
 
17
- onConstantChange = (event: ChangeEvent<HTMLInputElement>) => {
18
- const { onChange, query, onRunQuery } = this.props;
14
+ const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => {
19
15
  onChange({ ...query, constant: parseFloat(event.target.value) });
20
16
  // executes the query
21
17
  onRunQuery();
22
18
  };
23
19
 
24
- render() {
25
- const { queryText, constant } = this.props.query;
20
+ const { queryText, constant } = query;
26
21
 
27
- return (
28
- <div className="gf-form">
29
- <FormField
30
- width={4}
31
- value={constant}
32
- onChange={this.onConstantChange}
33
- label="Constant"
34
- type="number"
35
- step="0.1"
36
- />
37
- <FormField
38
- labelWidth={8}
39
- value={queryText || ''}
40
- onChange={this.onQueryTextChange}
41
- label="Query Text"
42
- tooltip="Not used yet"
43
- />
44
- </div>
45
- );
46
- }
22
+ return (
23
+ <div className="gf-form">
24
+ <InlineField label="Constant">
25
+ <Input onChange={onConstantChange} value={constant} width={8} type="number" step="0.1" />
26
+ </InlineField>
27
+ <InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
28
+ <Input onChange={onQueryTextChange} value={queryText || ''} />
29
+ </InlineField>
30
+ </div>
31
+ );
47
32
  }