Skip to content

Commit

Permalink
project: Fix compatibility with Grafana v7.0.0
Browse files Browse the repository at this point in the history
In Grafana v7.0.0-beta1 DashboardModel.isTimezoneUtc got removed and
cannot be used anymore in plugins. Replace it with its implementation
`this.getTimezone() === 'utc'`.

See: grafana/grafana#23586
  • Loading branch information
fetzerch committed May 24, 2020
1 parent 0ce87c9 commit 3ae2372
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 14 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.6] - 2020-05-24

### Fixed

- Compatibility with Grafana 7.0.

## [0.1.5] - 2019-08-01

### Fixed
Expand Down Expand Up @@ -50,7 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial version with sun and moon calculation and annotations.

[Unreleased]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.5...HEAD
[Unreleased]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.6...HEAD
[0.1.6]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.2...v0.1.3
Expand Down
9 changes: 8 additions & 1 deletion dist/CHANGELOG.md
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.6] - 2020-05-24

### Fixed

- Compatibility with Grafana 7.0.

## [0.1.5] - 2019-08-01

### Fixed
Expand Down Expand Up @@ -50,7 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial version with sun and moon calculation and annotations.

[Unreleased]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.5...HEAD
[Unreleased]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.6...HEAD
[0.1.6]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/fetzerch/grafana-sunandmoon-datasource/compare/v0.1.2...v0.1.3
Expand Down
2 changes: 1 addition & 1 deletion dist/module.js
Expand Up @@ -318,7 +318,7 @@ var SunAndMoonDatasource = /** @class */ (function () {
var moonTimes = SunCalc.getMoonTimes(date.toDate(), this.position.latitude, this.position.longitude);
var values = lodash_1.default.merge({}, sunTimes, lodash_1.default.mapKeys(moonTimes, function (value, key) { return "moon" + key; }));
var setHours = Date.prototype.setHours;
if (options.dashboard !== undefined && options.dashboard.isTimezoneUtc()) {
if (options.dashboard !== undefined && options.dashboard.getTimezone() === "utc") {
setHours = Date.prototype.setUTCHours;
}
values.noon = setHours.call(date.toDate(), 12, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/plugin.json
Expand Up @@ -30,8 +30,8 @@
"screenshots": [
{"name": "Sun and Moon Position", "path": "src/img/screenshot.png"}
],
"version": "0.1.5",
"updated": "2019-08-01"
"version": "0.1.6",
"updated": "2020-05-24"
},

"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "sunandmoon-datasource",
"private": true,
"version": "0.1.5",
"version": "0.1.6",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Expand Up @@ -30,8 +30,8 @@
"screenshots": [
{"name": "Sun and Moon Position", "path": "src/img/screenshot.png"}
],
"version": "0.1.5",
"updated": "2019-08-01"
"version": "0.1.6",
"updated": "2020-05-24"
},

"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions spec/datasource.jest.ts
Expand Up @@ -54,7 +54,7 @@ describe("SunAndMoonDatasource", () => {
it("annotationQuery should return all values", () => {
const options = {
annotation: {},
dashboard: { isTimezoneUtc: () => true },
dashboard: { getTimezone: () => "utc" },
range: {
from: moment("2019/03/26", "YYYY/MM/DD"),
to: moment("2019/03/26", "YYYY/MM/DD")
Expand All @@ -68,7 +68,7 @@ describe("SunAndMoonDatasource", () => {
it("annotationQuery should return specified values", () => {
const options = {
annotation: { query: "dusk, dawn"},
dashboard: { isTimezoneUtc: () => true },
dashboard: { getTimezone: () => "utc" },
range: {
from: moment("2019/03/26", "YYYY/MM/DD"),
to: moment("2019/03/26", "YYYY/MM/DD")
Expand All @@ -82,7 +82,7 @@ describe("SunAndMoonDatasource", () => {
it("annotationQuery should support local time", () => {
const options = {
annotation: {},
dashboard: { isTimezoneUtc: () => false },
dashboard: { getTimezone: () => "Europe/Berlin" },
range: {
from: moment("2019/03/26", "YYYY/MM/DD"),
to: moment("2019/03/26", "YYYY/MM/DD")
Expand Down
2 changes: 1 addition & 1 deletion src/datasource.ts
Expand Up @@ -217,7 +217,7 @@ export class SunAndMoonDatasource {
const values = _.merge({}, sunTimes,
_.mapKeys(moonTimes, (value, key) => "moon" + key));
let setHours = Date.prototype.setHours;
if (options.dashboard !== undefined && options.dashboard.isTimezoneUtc()) {
if (options.dashboard !== undefined && options.dashboard.getTimezone() === "utc") {
setHours = Date.prototype.setUTCHours;
}
values.noon = setHours.call(date.toDate(), 12, 0, 0);
Expand Down

0 comments on commit 3ae2372

Please sign in to comment.