@grafana/create-plugin 6.2.0-canary.2314.19503588692.0 → 6.2.0-canary.2314.19505018775.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": "6.2.0-canary.2314.
|
|
3
|
+
"version": "6.2.0-canary.2314.19505018775.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"directory": "packages/create-plugin",
|
|
6
6
|
"url": "https://github.com/grafana/plugin-tools"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=20"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "68ffe571c164963b0c82c2d1788c307914495307"
|
|
64
64
|
}
|
|
@@ -1,66 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
# Project overview
|
|
2
|
+
This repository contains a **Grafana panel plugin**, providing a custom visualization for Grafana dashboards.
|
|
3
|
+
Panel plugins are used to:
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
* Display data from Grafana data sources in custom ways
|
|
6
|
+
* Add interactive behavior (drill-downs, navigation, etc.)
|
|
7
|
+
* Visualize or control external systems (IoT, integrations, custom controls)
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
- Add custom interactivity, such as navigation or drill-downs
|
|
7
|
-
- Visualize or control external systems (for example, IoT devices or custom integrations)
|
|
9
|
+
---
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
# Plugin anatomy
|
|
10
12
|
|
|
11
|
-
A typical panel plugin
|
|
13
|
+
A typical panel plugin includes:
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
## **plugin.json**
|
|
16
|
+
* Declares plugin ID, type (`panel`), name, version
|
|
17
|
+
* Loaded by Grafana at startup
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
## **Main module (`src/module.ts`)**
|
|
20
|
+
* Exports: `new PanelPlugin(PanelComponent)`
|
|
21
|
+
* Registers panel options, migrations, defaults
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- Works with Grafana data frames and field configuration APIs to read query results and settings.
|
|
23
|
+
## **Panel component (`src/components/Panel.tsx`)**
|
|
24
|
+
* React component receiving: `data`, `timeRange`, `width`, `height`, `options`
|
|
25
|
+
* Renders visualization using Grafana data frames and field configs
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
---
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
# Agent goals
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
- Follow idiomatic React and TypeScript practices consistent with Grafana’s official example plugins
|
|
32
|
-
- Treat AGENTS.md as the authoritative source. If anything in .config/AGENTS conflicts with this file, follow the instructions in AGENTS.md
|
|
31
|
+
Agents must:
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
* Preserve the existing options schema unless adding a migration handler
|
|
34
|
+
* Follow idiomatic React + TypeScript patterns used in official Grafana examples
|
|
35
|
+
* Treat **`AGENTS.md` as the authoritative source** over `.config/AGENTS/*`
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
- `src/module.ts` – main plugin entry point (creates `PanelPlugin`)
|
|
38
|
-
- `src/components` – React components for the panel
|
|
39
|
-
- `src/types.ts` – TypeScript types for panel options and internal models
|
|
40
|
-
- `tests/` – End-to-end tests (if configured)
|
|
41
|
-
- `provisioning/` - Provisioning files used in the local development environment.
|
|
42
|
-
- `README.md` – Human-facing project documentation
|
|
37
|
+
---
|
|
43
38
|
|
|
44
|
-
|
|
39
|
+
# Repository layout (Compact)
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- They’re necessary
|
|
54
|
-
- They’re compatible with Grafana’s frontend environment and plugin guidelines
|
|
55
|
-
- If custom styling is needed, please using `Emotion`.
|
|
41
|
+
* `plugin.json` — Panel plugin manifest
|
|
42
|
+
* `src/module.ts` — Main plugin entry
|
|
43
|
+
* `src/components/` — Panel React components
|
|
44
|
+
* `src/types.ts` — Option and model types
|
|
45
|
+
* `tests/` — E2E tests (if present)
|
|
46
|
+
* `provisioning/` — Local development provisioning
|
|
47
|
+
* `README.md` — Human documentation
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
---
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
# Coding guidelines
|
|
52
|
+
|
|
53
|
+
* Use **TypeScript** and **functional React components**
|
|
54
|
+
* Use **@grafana/ui**, **@grafana/data**, **@grafana/runtime**
|
|
55
|
+
* Respect `width` and `height`; keep layout responsive
|
|
56
|
+
* Avoid unnecessary dependencies; ensure Grafana compatibility
|
|
57
|
+
* Use **Emotion** for custom styling
|
|
58
|
+
* Follow existing file structure
|
|
59
|
+
* Keep code typed and predictable
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
# Safety & constraints (Compact)
|
|
64
|
+
|
|
65
|
+
Agents must **not**:
|
|
66
|
+
|
|
67
|
+
* Change plugin IDs or plugin type in `plugin.json`
|
|
68
|
+
* Modify anything under `.config/*`
|
|
69
|
+
* Add a backend — panel plugins are **frontend only**
|
|
70
|
+
* Remove or change existing options without a migration handler
|
|
71
|
+
* Break public APIs (options, field configs, panel props)
|
|
72
|
+
|
|
73
|
+
Agents **should**:
|
|
74
|
+
|
|
75
|
+
* Keep the plugin backward compatible
|
|
76
|
+
* Mirror patterns from Grafana’s official panel plugin examples
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
# How-to
|
|
81
|
+
* [How-to add panel options](./howto/add-panel-options.md)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Adding a New Panel Option
|
|
2
|
+
|
|
3
|
+
Always complete **all three steps**:
|
|
4
|
+
|
|
5
|
+
### **1. Extend the options type**
|
|
6
|
+
|
|
7
|
+
File: `src/types.ts`
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export interface SimpleOptions {
|
|
11
|
+
// existing...
|
|
12
|
+
myOptionName: MyOptionType;
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
* Property name must match the builder `path`.
|
|
17
|
+
* Type must match expected editor output.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### **2. Register the option in `setPanelOptions`**
|
|
22
|
+
|
|
23
|
+
File: `src/module.ts` inside `setPanelOptions((builder) => { ... })`
|
|
24
|
+
|
|
25
|
+
Use the correct builder method:
|
|
26
|
+
|
|
27
|
+
| Type | Builder |
|
|
28
|
+
| ------------------ | -------------------- |
|
|
29
|
+
| boolean | `addBooleanSwitch` |
|
|
30
|
+
| number | `addNumberInput` |
|
|
31
|
+
| string | `addTextInput` |
|
|
32
|
+
| select | `addSelect` |
|
|
33
|
+
| radio | `addRadio` |
|
|
34
|
+
| radio group | `addRadio` |
|
|
35
|
+
| slider | `addSliderInput` |
|
|
36
|
+
| color picker | `addColorPicker` |
|
|
37
|
+
| unit picker | `addUnitPicker` |
|
|
38
|
+
| field namer picker | `addFieldNamePicker` |
|
|
39
|
+
|
|
40
|
+
Template:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
builder.addXxx({
|
|
44
|
+
path: 'myOptionName', // must match type property
|
|
45
|
+
name: 'My option',
|
|
46
|
+
defaultValue: <default>,
|
|
47
|
+
description: '',
|
|
48
|
+
settings: { /* optional */ },
|
|
49
|
+
// Optional visibility rule:
|
|
50
|
+
// showIf: (opts) => opts.someOtherOption,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Rules:
|
|
55
|
+
|
|
56
|
+
* Every option **must** have a `defaultValue`.
|
|
57
|
+
* Put numeric constraints in `settings` (`min`, `max`, `step`).
|
|
58
|
+
* Use `showIf` for conditional display.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### **3. Use the option in the panel component**
|
|
63
|
+
|
|
64
|
+
File: `src/Panel.tsx` (or equivalent)
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
export const Panel = ({ options }) => {
|
|
68
|
+
const { myOptionName } = options;
|
|
69
|
+
// apply it in rendering/logic
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
No option may remain unused.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
# Quick Editor Recipes
|
|
78
|
+
|
|
79
|
+
### **Boolean**
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
.addBooleanSwitch({ path: 'flag', name: 'Flag', defaultValue: false })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### **Number**
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
.addNumberInput({
|
|
89
|
+
path: 'max',
|
|
90
|
+
name: 'Max value',
|
|
91
|
+
defaultValue: 10,
|
|
92
|
+
settings: { min: 1, max: 100, step: 1 },
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### **String**
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
.addTextInput({ path: 'label', name: 'Label', defaultValue: '' })
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### **Select**
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
.addSelect({
|
|
106
|
+
path: 'mode',
|
|
107
|
+
name: 'Mode',
|
|
108
|
+
defaultValue: 'auto',
|
|
109
|
+
settings: { options: [
|
|
110
|
+
{ value: 'a', label: 'A' },
|
|
111
|
+
{ value: 'b', label: 'B' },
|
|
112
|
+
]},
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### **Radio**
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
.addRadio({
|
|
120
|
+
path: 'size',
|
|
121
|
+
name: 'Size',
|
|
122
|
+
defaultValue: 'md',
|
|
123
|
+
settings: { options: [
|
|
124
|
+
{ value: 'sm', label: 'Small' },
|
|
125
|
+
{ value: 'md', label: 'Medium' },
|
|
126
|
+
{ value: 'lg', label: 'Large' },
|
|
127
|
+
]},
|
|
128
|
+
showIf: (o) => o.showSize,
|
|
129
|
+
})
|
|
130
|
+
```
|