Skip to content

Commit

Permalink
Update variable support in Scenes dashboard (#79)
Browse files Browse the repository at this point in the history
* Fix variable support in dashboard scene

* Fix lint errors

* Update version

* Update minimum version

---------

Co-authored-by: Mikhail Volkov <[email protected]>
  • Loading branch information
asimonok and mikhail-vl authored Jul 24, 2024
1 parent e1e0306 commit 8ee494f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 19 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 4.2.0 (IN PROGRESS)

### Breaking changes

- Requires Grafana 10.2 and Grafana 11

### Features / Enhancements

- Update variable support in Scenes dashboard (#79)

## 4.1.0 (2024-06-25)

### Features / Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The Business Input Data Source is a plugin for Grafana that allows storing and e

## Requirements

- Business Input Data Source version 4.X requires **Grafana 10** or **Grafana 11**.
- Business Input Data Source version 4.X requires **Grafana 10.2** or **Grafana 11**.
- Static Data Source version 3.X requires **Grafana 9.2** or **Grafana 10**.
- Static Data Source version 2.X requires **Grafana 8.5** or **Grafana 9**.
- Static Data Source version 1.X requires **Grafana 7.3**.
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
- GF_DEFAULT_APP_MODE=development
- GF_USERS_DEFAULT_THEME=light
- GF_INSTALL_PLUGINS=volkovlabs-image-panel,marcusolsson-dynamictext-panel,grafana-llm-app
# - GF_FEATURE_TOGGLES_ENABLE=dashboardScene
volumes:
- ./dist:/var/lib/grafana/plugins/marcusolsson-static-datasource
- ./provisioning:/etc/grafana/provisioning
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
"test:ci": "jest --maxWorkers 4 --coverage",
"upgrade": "npm upgrade --save"
},
"version": "4.1.0"
"version": "4.2.0"
}
23 changes: 13 additions & 10 deletions provisioning/dashboards/panels.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
"viz": false
}
},
"mappings": [],
"unitScale": true
"mappings": []
},
"overrides": []
},
Expand Down Expand Up @@ -182,6 +181,7 @@
"autoPlay": true,
"buttons": [],
"controls": true,
"formats": ["audio", "image", "pdf", "video"],
"height": 0,
"heightMode": "auto",
"infinityPlay": false,
Expand Down Expand Up @@ -237,8 +237,7 @@
"viz": false
}
},
"mappings": [],
"unitScale": true
"mappings": []
},
"overrides": []
},
Expand Down Expand Up @@ -313,8 +312,12 @@
{
"current": {
"selected": false,
"text": "Test",
"value": "Test"
"text": "1950",
"value": "1950"
},
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "P1D2C73DC01F2359B"
},
"definition": "",
"hide": 0,
Expand All @@ -330,13 +333,13 @@
"config": {},
"name": "Test",
"type": "string",
"values": ["Test"]
"values": [null]
}
],
"meta": {
"custom": {
"customCode": "const result = {\n ...frame,\n fields: frame.fields.map((field) => ({\n ...field,\n values: []\n }))\n}\n\nreturn Promise.resolve(result);",
"valuesEditor": "manual"
"customCode": "const array = new Array(100).fill(null);\n\nconst result = {\n ...frame,\n fields: frame.fields.map((field) => ({\n ...field,\n values: array.map((_, index) => `${1950 + index}`)\n }))\n}\n\nreturn Promise.resolve(result);",
"valuesEditor": "custom"
}
},
"name": "Test"
Expand All @@ -358,6 +361,6 @@
"timezone": "",
"title": "Panels",
"uid": "O4tc_E6Gz",
"version": 1,
"version": 2,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DataSource extends DataSourceApi<StaticQuery, StaticDataSourceOptio
/**
* Enable variable support
*/
this.variables = new VariableSupport();
this.variables = new VariableSupport(this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/datasource/variable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { VariableSupport } from './variable';
* Variable Support
*/
describe('VariableSupport', () => {
const variableSupport = new VariableSupport();
const variableSupport = new VariableSupport({} as any);

/**
* Type
*/
describe('GetType', () => {
it('Should return correct type', async () => {
const type = variableSupport.getType();
expect(type).toEqual('datasource');
expect(type).toEqual('custom');
});
});
});
14 changes: 11 additions & 3 deletions src/datasource/variable.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { DataSourceVariableSupport } from '@grafana/data';
import { CustomVariableSupport, DataQueryRequest, DataQueryResponse } from '@grafana/data';
import { from, Observable } from 'rxjs';
import { StaticQuery } from 'types';

import { QueryEditor } from '../components';
import { DataSource } from './datasource';

/**
* Variable Support
*/
export class VariableSupport extends DataSourceVariableSupport<DataSource, StaticQuery> {
constructor() {
export class VariableSupport extends CustomVariableSupport<DataSource, StaticQuery> {
constructor(private readonly datasource: DataSource) {
super();
}

editor = QueryEditor;

query(options: DataQueryRequest<StaticQuery>): Observable<DataQueryResponse> {
return from(this.datasource.query(options));
}
}
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://github.com/grafana/grafana/raw/main/docs/sources/developers/plugins/plugin.schema.json",
"annotations": true,
"dependencies": {
"grafanaDependency": ">=10.0.0",
"grafanaDependency": ">=10.2.0",
"plugins": []
},
"id": "marcusolsson-static-datasource",
Expand Down

0 comments on commit 8ee494f

Please sign in to comment.