@grafana/create-plugin 4.3.0 → 4.4.0-canary.836.aa6cb3b.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": "4.
|
|
3
|
+
"version": "4.4.0-canary.836.aa6cb3b.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"directory": "packages/create-plugin",
|
|
6
6
|
"url": "https://github.com/grafana/plugin-tools"
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=20"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "aa6cb3b69e6737ce4846bc00ec0595a4187bc72c"
|
|
91
91
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSourceInstanceSettings, CoreApp } from '@grafana/data';
|
|
2
|
-
import { DataSourceWithBackend } from '@grafana/runtime';
|
|
1
|
+
import { DataSourceInstanceSettings, CoreApp, ScopedVars } from '@grafana/data';
|
|
2
|
+
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
|
|
3
3
|
|
|
4
4
|
import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
|
|
5
5
|
|
|
@@ -9,6 +9,18 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
getDefaultQuery(_: CoreApp): Partial<MyQuery> {
|
|
12
|
-
return DEFAULT_QUERY
|
|
12
|
+
return DEFAULT_QUERY;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
applyTemplateVariables(query: MyQuery, scopedVars: ScopedVars): Record<string, any> {
|
|
16
|
+
return {
|
|
17
|
+
...query,
|
|
18
|
+
queryText: getTemplateSrv().replace(query.queryText, scopedVars),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
filterQuery(query: MyQuery): boolean {
|
|
23
|
+
// if no query has been provided, prevent the query from being executed
|
|
24
|
+
return !!query.queryText;
|
|
13
25
|
}
|
|
14
26
|
}
|
|
@@ -3,16 +3,20 @@ import { InlineField, Input, SecretInput } from '@grafana/ui';
|
|
|
3
3
|
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
|
4
4
|
import { MyDataSourceOptions, MySecureJsonData } from '../types';
|
|
5
5
|
|
|
6
|
-
interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions> {}
|
|
6
|
+
interface Props extends DataSourcePluginOptionsEditorProps<MyDataSourceOptions, MySecureJsonData> {}
|
|
7
7
|
|
|
8
8
|
export function ConfigEditor(props: Props) {
|
|
9
9
|
const { onOptionsChange, options } = props;
|
|
10
|
+
const { jsonData, secureJsonFields, secureJsonData } = options;
|
|
11
|
+
|
|
10
12
|
const onPathChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
11
|
-
|
|
12
|
-
...options
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
onOptionsChange({
|
|
14
|
+
...options,
|
|
15
|
+
jsonData: {
|
|
16
|
+
...jsonData,
|
|
17
|
+
path: event.target.value,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
// Secure field (only sent to the backend)
|
|
@@ -39,29 +43,29 @@ export function ConfigEditor(props: Props) {
|
|
|
39
43
|
});
|
|
40
44
|
};
|
|
41
45
|
|
|
42
|
-
const { jsonData, secureJsonFields } = options;
|
|
43
|
-
const secureJsonData = (options.secureJsonData || {}) as MySecureJsonData;
|
|
44
|
-
|
|
45
46
|
return (
|
|
46
|
-
|
|
47
|
-
<InlineField label="Path" labelWidth={
|
|
47
|
+
<>
|
|
48
|
+
<InlineField label="Path" labelWidth={14} interactive tooltip={'Json field returned to frontend'}>
|
|
48
49
|
<Input
|
|
50
|
+
id="config-editor-path"
|
|
49
51
|
onChange={onPathChange}
|
|
50
|
-
value={jsonData.path
|
|
51
|
-
placeholder="
|
|
52
|
+
value={jsonData.path}
|
|
53
|
+
placeholder="Enter the path, e.g. /api/v1"
|
|
52
54
|
width={40}
|
|
53
55
|
/>
|
|
54
56
|
</InlineField>
|
|
55
|
-
<InlineField label="API Key" labelWidth={
|
|
57
|
+
<InlineField label="API Key" labelWidth={14} interactive tooltip={'Secure json field (backend only)'}>
|
|
56
58
|
<SecretInput
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
required
|
|
60
|
+
id="config-editor-api-key"
|
|
61
|
+
isConfigured={secureJsonFields.apiKey}
|
|
62
|
+
value={secureJsonData?.apiKey}
|
|
63
|
+
placeholder="Enter your API key"
|
|
60
64
|
width={40}
|
|
61
65
|
onReset={onResetAPIKey}
|
|
62
66
|
onChange={onAPIKeyChange}
|
|
63
67
|
/>
|
|
64
68
|
</InlineField>
|
|
65
|
-
|
|
69
|
+
</>
|
|
66
70
|
);
|
|
67
71
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ChangeEvent } from 'react';
|
|
2
|
-
import { InlineField, Input } from '@grafana/ui';
|
|
2
|
+
import { InlineField, Input, Stack } from '@grafana/ui';
|
|
3
3
|
import { QueryEditorProps } from '@grafana/data';
|
|
4
4
|
import { DataSource } from '../datasource';
|
|
5
5
|
import { MyDataSourceOptions, MyQuery } from '../types';
|
|
@@ -20,13 +20,26 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
|
|
|
20
20
|
const { queryText, constant } = query;
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<
|
|
23
|
+
<Stack gap={0}>
|
|
24
24
|
<InlineField label="Constant">
|
|
25
|
-
<Input
|
|
25
|
+
<Input
|
|
26
|
+
id="query-editor-constant"
|
|
27
|
+
onChange={onConstantChange}
|
|
28
|
+
value={constant}
|
|
29
|
+
width={8}
|
|
30
|
+
type="number"
|
|
31
|
+
step="0.1"
|
|
32
|
+
/>
|
|
26
33
|
</InlineField>
|
|
27
34
|
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
|
|
28
|
-
<Input
|
|
35
|
+
<Input
|
|
36
|
+
id="query-editor-query-text"
|
|
37
|
+
onChange={onQueryTextChange}
|
|
38
|
+
value={queryText || ''}
|
|
39
|
+
required
|
|
40
|
+
placeholder="Enter a query"
|
|
41
|
+
/>
|
|
29
42
|
</InlineField>
|
|
30
|
-
</
|
|
43
|
+
</Stack>
|
|
31
44
|
);
|
|
32
45
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CoreApp,
|
|
2
3
|
DataQueryRequest,
|
|
3
4
|
DataQueryResponse,
|
|
4
5
|
DataSourceApi,
|
|
@@ -7,13 +8,22 @@ import {
|
|
|
7
8
|
FieldType,
|
|
8
9
|
} from '@grafana/data';
|
|
9
10
|
|
|
10
|
-
import { MyQuery, MyDataSourceOptions } from './types';
|
|
11
|
+
import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
|
|
11
12
|
|
|
12
13
|
export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
|
|
13
14
|
constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
|
|
14
15
|
super(instanceSettings);
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
getDefaultQuery(_: CoreApp): Partial<MyQuery> {
|
|
19
|
+
return DEFAULT_QUERY;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
filterQuery(query: MyQuery): boolean {
|
|
23
|
+
// if no query has been provided, prevent the query from being executed
|
|
24
|
+
return !!query.queryText;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
|
|
18
28
|
const { range } = options;
|
|
19
29
|
const from = range!.from.valueOf();
|