Skip to content

Commit e2d2059

Browse files
asimonokmikhail-vl
andauthored
Add Organization Users (#52)
* Refactor APIs * Update tests * Add local request mode * Update tests * Add get users query * Update with using convertToFrame util * Add Get Org Users query * Update CHANGELOG.md * Rename Org Users * Set default mode as Remote * Update provisioning --------- Co-authored-by: Mikhail <[email protected]>
1 parent b35fc76 commit e2d2059

17 files changed

+425
-69
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Change Log
22

3-
## 2.1.0 (IN PROGRESS)
3+
## 2.1.0 (2023-09-10)
44

55
### Features / Enhancements
66

77
- Refactor API and increase test coverage (#50)
88
- Update ESLint configuration (#50)
9+
- Add Local mode to access local instance (#51)
10+
- Add Organization Users (#52)
911

1012
## 2.0.0 (2023-07-17)
1113

provisioning/dashboards/panels.json

+81-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
},
7070
"id": 6,
7171
"options": {
72+
"cellHeight": "sm",
7273
"footer": {
7374
"countRows": false,
7475
"fields": "",
@@ -77,7 +78,7 @@
7778
},
7879
"showHeader": true
7980
},
80-
"pluginVersion": "9.4.3",
81+
"pluginVersion": "10.0.3",
8182
"targets": [
8283
{
8384
"annotationDashboard": "",
@@ -140,7 +141,7 @@
140141
},
141142
"textMode": "auto"
142143
},
143-
"pluginVersion": "9.4.3",
144+
"pluginVersion": "10.0.3",
144145
"targets": [
145146
{
146147
"annotationDashboard": "",
@@ -204,7 +205,7 @@
204205
},
205206
"textMode": "auto"
206207
},
207-
"pluginVersion": "9.4.3",
208+
"pluginVersion": "10.0.3",
208209
"targets": [
209210
{
210211
"datasource": {
@@ -260,6 +261,7 @@
260261
},
261262
"id": 3,
262263
"options": {
264+
"cellHeight": "sm",
263265
"footer": {
264266
"countRows": false,
265267
"fields": "",
@@ -268,7 +270,7 @@
268270
},
269271
"showHeader": true
270272
},
271-
"pluginVersion": "9.4.3",
273+
"pluginVersion": "10.0.3",
272274
"targets": [
273275
{
274276
"datasource": {
@@ -327,13 +329,14 @@
327329
"overrides": []
328330
},
329331
"gridPos": {
330-
"h": 8,
332+
"h": 5,
331333
"w": 24,
332334
"x": 0,
333335
"y": 19
334336
},
335337
"id": 8,
336338
"options": {
339+
"cellHeight": "sm",
337340
"footer": {
338341
"countRows": false,
339342
"fields": "",
@@ -342,7 +345,7 @@
342345
},
343346
"showHeader": true
344347
},
345-
"pluginVersion": "9.4.3",
348+
"pluginVersion": "10.0.3",
346349
"targets": [
347350
{
348351
"annotationDashboard": "",
@@ -362,6 +365,78 @@
362365
],
363366
"title": "Alert Rules",
364367
"type": "table"
368+
},
369+
{
370+
"datasource": {
371+
"type": "volkovlabs-grapi-datasource",
372+
"uid": "grapi"
373+
},
374+
"fieldConfig": {
375+
"defaults": {
376+
"color": {
377+
"mode": "thresholds"
378+
},
379+
"custom": {
380+
"align": "auto",
381+
"cellOptions": {
382+
"type": "auto"
383+
},
384+
"inspect": false
385+
},
386+
"mappings": [],
387+
"thresholds": {
388+
"mode": "absolute",
389+
"steps": [
390+
{
391+
"color": "green",
392+
"value": null
393+
},
394+
{
395+
"color": "red",
396+
"value": 80
397+
}
398+
]
399+
}
400+
},
401+
"overrides": []
402+
},
403+
"gridPos": {
404+
"h": 5,
405+
"w": 24,
406+
"x": 0,
407+
"y": 24
408+
},
409+
"id": 9,
410+
"options": {
411+
"cellHeight": "sm",
412+
"footer": {
413+
"countRows": false,
414+
"fields": "",
415+
"reducer": ["sum"],
416+
"show": false
417+
},
418+
"showHeader": true
419+
},
420+
"pluginVersion": "10.0.3",
421+
"targets": [
422+
{
423+
"annotationDashboard": "",
424+
"annotationLimit": 100,
425+
"annotationNewState": "",
426+
"annotationPattern": "",
427+
"annotationPrevState": "",
428+
"annotationRange": "",
429+
"annotationType": "",
430+
"datasource": {
431+
"type": "volkovlabs-grapi-datasource",
432+
"uid": "grapi"
433+
},
434+
"refId": "A",
435+
"requestType": "orgUsers"
436+
}
437+
],
438+
"title": "Users",
439+
"type": "table"
365440
}
366441
],
367442
"refresh": "",

src/api/datasources.ts

+17-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DataSourceSettings, FieldType, MutableDataFrame } from '@grafana/data';
33
import { getBackendSrv } from '@grafana/runtime';
44
import { Messages, RequestType } from '../constants';
55
import { Query } from '../types';
6-
import { notifyError } from '../utils';
6+
import { convertToFrame, notifyError } from '../utils';
77
import { BaseApi } from './base';
88

99
/**
@@ -18,7 +18,7 @@ export class DataSources extends BaseApi {
1818
* Fetch
1919
*/
2020
const response = await lastValueFrom(
21-
getBackendSrv().fetch({
21+
getBackendSrv().fetch<DataSourceSettings[]>({
2222
method: 'GET',
2323
url: `${this.api.instanceSettings.url}/api/datasources`,
2424
})
@@ -32,7 +32,7 @@ export class DataSources extends BaseApi {
3232
return [];
3333
}
3434

35-
return response.data as DataSourceSettings[];
35+
return response.data;
3636
};
3737

3838
/**
@@ -45,76 +45,69 @@ export class DataSources extends BaseApi {
4545
}
4646

4747
/**
48-
* Create frame
48+
* Create Frame
4949
*/
50-
const frame = new MutableDataFrame({
50+
const frame = convertToFrame<DataSourceSettings>({
5151
name: RequestType.DATASOURCES,
5252
refId: query.refId,
5353
fields: [
5454
{
5555
name: 'Id',
5656
type: FieldType.number,
57+
getValue: (item) => item.id,
5758
},
5859
{
5960
name: 'Org Id',
6061
type: FieldType.number,
62+
getValue: (item) => item.orgId,
6163
},
6264
{
6365
name: 'UID',
6466
type: FieldType.string,
67+
getValue: (item) => item.uid,
6568
},
6669
{
6770
name: 'Name',
6871
type: FieldType.string,
72+
getValue: (item) => item.name,
6973
},
7074
{
7175
name: 'Type',
7276
type: FieldType.string,
77+
getValue: (item) => item.type,
7378
},
7479
{
7580
name: 'Type Logo URL',
7681
type: FieldType.string,
82+
getValue: (item) => item.typeLogoUrl,
7783
},
7884
{
7985
name: 'Type Name',
8086
type: FieldType.string,
87+
getValue: (item) => item.typeName,
8188
},
8289
{
8390
name: 'Is Default',
8491
type: FieldType.boolean,
92+
getValue: (item) => item.isDefault,
8593
},
8694
{
8795
name: 'Read Only',
8896
type: FieldType.boolean,
97+
getValue: (item) => item.readOnly,
8998
},
9099
{
91100
name: 'URL',
92101
type: FieldType.string,
102+
getValue: (item) => item.url,
93103
},
94104
{
95105
name: 'User',
96106
type: FieldType.string,
107+
getValue: (item) => item.user,
97108
},
98109
],
99-
});
100-
101-
/**
102-
* Add Data
103-
*/
104-
datasources.forEach((datasource) => {
105-
frame.appendRow([
106-
datasource.id,
107-
datasource.orgId,
108-
datasource.uid,
109-
datasource.name,
110-
datasource.type,
111-
datasource.typeLogoUrl,
112-
datasource.typeName,
113-
datasource.isDefault,
114-
datasource.readOnly,
115-
datasource.url,
116-
datasource.user,
117-
]);
110+
items: datasources,
118111
});
119112

120113
return [frame];

src/api/health.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FieldType, MutableDataFrame } from '@grafana/data';
33
import { getBackendSrv } from '@grafana/runtime';
44
import { Messages, RequestType } from '../constants';
55
import { Health as HealthType, Query } from '../types';
6-
import { notifyError } from '../utils';
6+
import { convertToFrame, notifyError } from '../utils';
77
import { BaseApi } from './base';
88

99
/**
@@ -15,7 +15,7 @@ export class Health extends BaseApi {
1515
*/
1616
get = async (): Promise<HealthType | undefined> => {
1717
const response = await lastValueFrom(
18-
getBackendSrv().fetch({
18+
getBackendSrv().fetch<HealthType>({
1919
method: 'GET',
2020
url: `${this.api.instanceSettings.url}/api/health`,
2121
})
@@ -32,7 +32,7 @@ export class Health extends BaseApi {
3232
/**
3333
* Data received
3434
*/
35-
return response.data as HealthType;
35+
return response.data;
3636
};
3737

3838
/**
@@ -45,32 +45,31 @@ export class Health extends BaseApi {
4545
}
4646

4747
/**
48-
* Create frame
48+
* Create Frame
4949
*/
50-
const frame = new MutableDataFrame({
50+
const frame = convertToFrame<HealthType>({
5151
name: RequestType.HEALTH,
5252
refId: query.refId,
5353
fields: [
5454
{
5555
name: 'Commit',
5656
type: FieldType.string,
57+
getValue: (item) => item.commit,
5758
},
5859
{
5960
name: 'Database',
6061
type: FieldType.string,
62+
getValue: (item) => item.database,
6163
},
6264
{
6365
name: 'Version',
6466
type: FieldType.string,
67+
getValue: (item) => item.version,
6568
},
6669
],
70+
items: [health],
6771
});
6872

69-
/**
70-
* Add Data
71-
*/
72-
frame.appendRow([health.commit, health.database, health.version]);
73-
7473
return [frame];
7574
};
7675
}

0 commit comments

Comments
 (0)