Skip to content

Commit

Permalink
Add Organization Users (#52)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
asimonok and mikhail-vl authored Sep 10, 2023
1 parent b35fc76 commit e2d2059
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 69 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Change Log

## 2.1.0 (IN PROGRESS)
## 2.1.0 (2023-09-10)

### Features / Enhancements

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

## 2.0.0 (2023-07-17)

Expand Down
87 changes: 81 additions & 6 deletions provisioning/dashboards/panels.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
},
"id": 6,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
Expand All @@ -77,7 +78,7 @@
},
"showHeader": true
},
"pluginVersion": "9.4.3",
"pluginVersion": "10.0.3",
"targets": [
{
"annotationDashboard": "",
Expand Down Expand Up @@ -140,7 +141,7 @@
},
"textMode": "auto"
},
"pluginVersion": "9.4.3",
"pluginVersion": "10.0.3",
"targets": [
{
"annotationDashboard": "",
Expand Down Expand Up @@ -204,7 +205,7 @@
},
"textMode": "auto"
},
"pluginVersion": "9.4.3",
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -260,6 +261,7 @@
},
"id": 3,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
Expand All @@ -268,7 +270,7 @@
},
"showHeader": true
},
"pluginVersion": "9.4.3",
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -327,13 +329,14 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 5,
"w": 24,
"x": 0,
"y": 19
},
"id": 8,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
Expand All @@ -342,7 +345,7 @@
},
"showHeader": true
},
"pluginVersion": "9.4.3",
"pluginVersion": "10.0.3",
"targets": [
{
"annotationDashboard": "",
Expand All @@ -362,6 +365,78 @@
],
"title": "Alert Rules",
"type": "table"
},
{
"datasource": {
"type": "volkovlabs-grapi-datasource",
"uid": "grapi"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"inspect": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 5,
"w": 24,
"x": 0,
"y": 24
},
"id": 9,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": ["sum"],
"show": false
},
"showHeader": true
},
"pluginVersion": "10.0.3",
"targets": [
{
"annotationDashboard": "",
"annotationLimit": 100,
"annotationNewState": "",
"annotationPattern": "",
"annotationPrevState": "",
"annotationRange": "",
"annotationType": "",
"datasource": {
"type": "volkovlabs-grapi-datasource",
"uid": "grapi"
},
"refId": "A",
"requestType": "orgUsers"
}
],
"title": "Users",
"type": "table"
}
],
"refresh": "",
Expand Down
41 changes: 17 additions & 24 deletions src/api/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DataSourceSettings, FieldType, MutableDataFrame } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { Messages, RequestType } from '../constants';
import { Query } from '../types';
import { notifyError } from '../utils';
import { convertToFrame, notifyError } from '../utils';
import { BaseApi } from './base';

/**
Expand All @@ -18,7 +18,7 @@ export class DataSources extends BaseApi {
* Fetch
*/
const response = await lastValueFrom(
getBackendSrv().fetch({
getBackendSrv().fetch<DataSourceSettings[]>({
method: 'GET',
url: `${this.api.instanceSettings.url}/api/datasources`,
})
Expand All @@ -32,7 +32,7 @@ export class DataSources extends BaseApi {
return [];
}

return response.data as DataSourceSettings[];
return response.data;
};

/**
Expand All @@ -45,76 +45,69 @@ export class DataSources extends BaseApi {
}

/**
* Create frame
* Create Frame
*/
const frame = new MutableDataFrame({
const frame = convertToFrame<DataSourceSettings>({
name: RequestType.DATASOURCES,
refId: query.refId,
fields: [
{
name: 'Id',
type: FieldType.number,
getValue: (item) => item.id,
},
{
name: 'Org Id',
type: FieldType.number,
getValue: (item) => item.orgId,
},
{
name: 'UID',
type: FieldType.string,
getValue: (item) => item.uid,
},
{
name: 'Name',
type: FieldType.string,
getValue: (item) => item.name,
},
{
name: 'Type',
type: FieldType.string,
getValue: (item) => item.type,
},
{
name: 'Type Logo URL',
type: FieldType.string,
getValue: (item) => item.typeLogoUrl,
},
{
name: 'Type Name',
type: FieldType.string,
getValue: (item) => item.typeName,
},
{
name: 'Is Default',
type: FieldType.boolean,
getValue: (item) => item.isDefault,
},
{
name: 'Read Only',
type: FieldType.boolean,
getValue: (item) => item.readOnly,
},
{
name: 'URL',
type: FieldType.string,
getValue: (item) => item.url,
},
{
name: 'User',
type: FieldType.string,
getValue: (item) => item.user,
},
],
});

/**
* Add Data
*/
datasources.forEach((datasource) => {
frame.appendRow([
datasource.id,
datasource.orgId,
datasource.uid,
datasource.name,
datasource.type,
datasource.typeLogoUrl,
datasource.typeName,
datasource.isDefault,
datasource.readOnly,
datasource.url,
datasource.user,
]);
items: datasources,
});

return [frame];
Expand Down
19 changes: 9 additions & 10 deletions src/api/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FieldType, MutableDataFrame } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { Messages, RequestType } from '../constants';
import { Health as HealthType, Query } from '../types';
import { notifyError } from '../utils';
import { convertToFrame, notifyError } from '../utils';
import { BaseApi } from './base';

/**
Expand All @@ -15,7 +15,7 @@ export class Health extends BaseApi {
*/
get = async (): Promise<HealthType | undefined> => {
const response = await lastValueFrom(
getBackendSrv().fetch({
getBackendSrv().fetch<HealthType>({
method: 'GET',
url: `${this.api.instanceSettings.url}/api/health`,
})
Expand All @@ -32,7 +32,7 @@ export class Health extends BaseApi {
/**
* Data received
*/
return response.data as HealthType;
return response.data;
};

/**
Expand All @@ -45,32 +45,31 @@ export class Health extends BaseApi {
}

/**
* Create frame
* Create Frame
*/
const frame = new MutableDataFrame({
const frame = convertToFrame<HealthType>({
name: RequestType.HEALTH,
refId: query.refId,
fields: [
{
name: 'Commit',
type: FieldType.string,
getValue: (item) => item.commit,
},
{
name: 'Database',
type: FieldType.string,
getValue: (item) => item.database,
},
{
name: 'Version',
type: FieldType.string,
getValue: (item) => item.version,
},
],
items: [health],
});

/**
* Add Data
*/
frame.appendRow([health.commit, health.database, health.version]);

return [frame];
};
}
Loading

0 comments on commit e2d2059

Please sign in to comment.