@grafana/assistant 0.0.1-alpha.2
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/README.md +119 -0
- package/dist/dashboarding.d.ts +23 -0
- package/dist/dashboarding.js +2 -0
- package/dist/dashboarding.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @grafana/assistant
|
|
2
|
+
|
|
3
|
+
Type definitions for Grafana Assistant functions and dashboard operations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @grafana/assistant
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import type { AddCallbackFunction, FunctionImplementation, DashboardOperations } from '@grafana/assistant';
|
|
15
|
+
|
|
16
|
+
// Use the type to define your assistant function handler
|
|
17
|
+
const registerFunction: AddCallbackFunction = (pluginId, namespace, functionName, functionImpl) => {
|
|
18
|
+
// Your implementation here
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Example function implementation
|
|
22
|
+
const myFunction: FunctionImplementation = (param1, param2) => {
|
|
23
|
+
return `Result: ${param1} + ${param2}`;
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Types
|
|
28
|
+
|
|
29
|
+
### AddCallbackFunction
|
|
30
|
+
|
|
31
|
+
A function signature for registering assistant functions.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
type AddCallbackFunction = (pluginId: string, namespace: string, functionName: string, functionImpl: FunctionImplementation) => void;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Parameters:**
|
|
38
|
+
- `pluginId: string` - The plugin ID of the function
|
|
39
|
+
- `namespace: string` - The namespace for the function
|
|
40
|
+
- `functionName: string` - The name of the function
|
|
41
|
+
- `functionImpl: FunctionImplementation` - The implementation of the function
|
|
42
|
+
|
|
43
|
+
### FunctionImplementation
|
|
44
|
+
|
|
45
|
+
A type for function implementations that can be registered with the assistant.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
type FunctionImplementation = (...args: any[]) => any;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### DashboardOperations
|
|
52
|
+
|
|
53
|
+
Operations available for dashboard manipulation.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
type DashboardOperations = {
|
|
57
|
+
addPanel: (vizPanel: VizPanel) => void;
|
|
58
|
+
duplicatePanel: (vizPanel: VizPanel) => void;
|
|
59
|
+
copyPanel: (vizPanel: VizPanel) => void;
|
|
60
|
+
pastePanel: () => void;
|
|
61
|
+
removePanel: (panel: VizPanel) => void;
|
|
62
|
+
createNewPanel: () => void;
|
|
63
|
+
createNewRow: () => void;
|
|
64
|
+
onEnterEditMode: () => void;
|
|
65
|
+
openSaveDrawer: (options?: SaveDrawerOptions) => void;
|
|
66
|
+
onStarDashboard: () => void;
|
|
67
|
+
canEditDashboard: () => boolean;
|
|
68
|
+
exitEditMode: (options: ExitEditModeOptions) => void;
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Example: Registering Dashboard Operations
|
|
73
|
+
|
|
74
|
+
Here's how Grafana core would register all dashboard operations:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
Object.keys(DashboardOperations).forEach((actionName) => {
|
|
78
|
+
const action = DashboardOperations[actionName as keyof typeof DashboardOperations];
|
|
79
|
+
addCallbackFunction.fn('grafana', 'dashboarding', actionName, action);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This example shows how to:
|
|
84
|
+
1. Iterate through all available dashboard operations
|
|
85
|
+
2. Extract each operation function
|
|
86
|
+
3. Register it with the assistant using the 'dashboarding' namespace
|
|
87
|
+
|
|
88
|
+
## Example: Using Registered Functions
|
|
89
|
+
|
|
90
|
+
Once functions are registered, they can be retrieved and used from the function registry:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { functionRegistry } from './functions/registry';
|
|
94
|
+
import type { DashboardOperations } from '@grafana/assistant';
|
|
95
|
+
|
|
96
|
+
// Retrieve a specific function from the registry
|
|
97
|
+
const onEnterEditMode = functionRegistry.getFunction<DashboardOperations['onEnterEditMode']>(
|
|
98
|
+
'grafana',
|
|
99
|
+
'dashboarding',
|
|
100
|
+
'onEnterEditMode'
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (!onEnterEditMode) {
|
|
104
|
+
throw new Error('onEnterEditMode function not found');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Use the retrieved function
|
|
108
|
+
onEnterEditMode();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This example demonstrates:
|
|
112
|
+
1. Using `functionRegistry.getFunction()` to retrieve registered functions by plugin ID, namespace, and function name
|
|
113
|
+
2. Type-safe function retrieval using TypeScript generics
|
|
114
|
+
3. Null checking before using the function
|
|
115
|
+
4. Calling the retrieved function
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { VizPanel } from '@grafana/scenes';
|
|
2
|
+
export type SaveDrawerOptions = {
|
|
3
|
+
saveAsCopy?: boolean;
|
|
4
|
+
onSaveSuccess?: () => void;
|
|
5
|
+
};
|
|
6
|
+
export type ExitEditModeOptions = {
|
|
7
|
+
skipConfirm: boolean;
|
|
8
|
+
restoreInitialState?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type DashboardOperations = {
|
|
11
|
+
addPanel: (vizPanel: VizPanel) => void;
|
|
12
|
+
duplicatePanel: (vizPanel: VizPanel) => void;
|
|
13
|
+
copyPanel: (vizPanel: VizPanel) => void;
|
|
14
|
+
pastePanel: () => void;
|
|
15
|
+
removePanel: (panel: VizPanel) => void;
|
|
16
|
+
createNewPanel: () => void;
|
|
17
|
+
createNewRow: () => void;
|
|
18
|
+
onEnterEditMode: () => void;
|
|
19
|
+
openSaveDrawer: (options?: SaveDrawerOptions) => void;
|
|
20
|
+
onStarDashboard: () => void;
|
|
21
|
+
canEditDashboard: () => boolean;
|
|
22
|
+
exitEditMode: (options: ExitEditModeOptions) => void;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboarding.js","sourceRoot":"","sources":["../src/dashboarding.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type FunctionImplementation = (...args: any[]) => any;
|
|
2
|
+
/**
|
|
3
|
+
* Function signature for registering Assistant functions. These functions
|
|
4
|
+
* support the tools offered by the Assistant.
|
|
5
|
+
*
|
|
6
|
+
* @param pluginId - The plugin ID of the function
|
|
7
|
+
* @param namespace - The namespace for the function
|
|
8
|
+
* @param functionName - The name of the function
|
|
9
|
+
* @param functionImpl - The implementation of the function
|
|
10
|
+
*/
|
|
11
|
+
export type AddCallbackFunction = (pluginId: string, namespace: string, functionName: string, functionImpl: FunctionImplementation) => void;
|
|
12
|
+
export * from './dashboarding';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,cAAc,gBAAgB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grafana/assistant",
|
|
3
|
+
"version": "0.0.1-alpha.2",
|
|
4
|
+
"description": "Type definitions for Grafana Assistant functions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prebuild": "rm -rf dist",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"clean": "rm -rf dist",
|
|
15
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"grafana",
|
|
19
|
+
"assistant",
|
|
20
|
+
"types",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "Grafana Labs",
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.0.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@grafana/scenes": ">=5.41.0"
|
|
33
|
+
}
|
|
34
|
+
}
|