Skip to content

Commit

Permalink
[fix] unexpected error when select time range
Browse files Browse the repository at this point in the history
  • Loading branch information
takkaO committed Jun 2, 2022
1 parent 9426750 commit dc4e674
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/grafana": "github:CorpGlory/types-grafana.git",
"@types/lodash": "^4.14.182",
"dayjs": "^1.11.2",
"moment": "^2.22.1",
"jquery": "^3.2.1",
"lodash": "^4.17.10"
},
Expand Down
4 changes: 2 additions & 2 deletions src/canvas-metric.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MetricsPanelCtrl } from 'grafana/app/plugins/sdk';

/* eslint-disable id-blacklist, no-restricted-imports, @typescript-eslint/ban-types */
//import moment from 'moment';
import moment from 'moment';
import dayjs, { extend } from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
Expand Down Expand Up @@ -244,7 +244,7 @@ export class CanvasPanelCtrl extends MetricsPanelCtrl {
} else {
const min = Math.min(this.mouse.down.ts, up.ts);
const max = Math.max(this.mouse.down.ts, up.ts);
const range = { from: dayjs.utc(min), to: dayjs.utc(max) };
const range = { from: moment.utc(min), to: moment.utc(max) };
this.mouse.position = up;
this.onMouseSelectedRange(range, evt);
}
Expand Down
7 changes: 5 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kbn from 'grafana/app/core/utils/kbn';
import appEvents from 'grafana/app/core/app_events';

/* eslint-disable id-blacklist, no-restricted-imports, @typescript-eslint/ban-types */
//import moment from 'moment';
import moment from 'moment';
import dayjs, { extend } from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
Expand Down Expand Up @@ -740,7 +740,10 @@ class DiscretePanelCtrl extends CanvasPanelCtrl {

const pt = this.hoverPoint;
if (pt && pt.start) {
const range = { from: dayjs.utc(pt.start), to: dayjs.utc(pt.start + pt.ms) };
console.log("Called");
console.log(pt);
const range = { from: moment.utc(pt.start), to: moment.utc(pt.start + pt.ms) };
console.log(range);
this.timeSrv.setTime(range);
this.clear();
}
Expand Down

0 comments on commit dc4e674

Please sign in to comment.