Commit 295bc425 by Torkel Ödegaard Committed by GitHub

Merge pull request #15337 from grafana/time-range-to-angular-query-controllers

provide time range to angular query controllers
parents 89c153d4 a0729b9b
...@@ -7,10 +7,11 @@ import _ from 'lodash'; ...@@ -7,10 +7,11 @@ import _ from 'lodash';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader'; import { AngularComponent, getAngularLoader } from 'app/core/services/AngularLoader';
import { Emitter } from 'app/core/utils/emitter'; import { Emitter } from 'app/core/utils/emitter';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
// Types // Types
import { PanelModel } from '../state/PanelModel'; import { PanelModel } from '../state/PanelModel';
import { DataQuery, DataSourceApi } from '@grafana/ui'; import { DataQuery, DataSourceApi, TimeRange } from '@grafana/ui';
interface Props { interface Props {
panel: PanelModel; panel: PanelModel;
...@@ -43,8 +44,15 @@ export class QueryEditorRow extends PureComponent<Props, State> { ...@@ -43,8 +44,15 @@ export class QueryEditorRow extends PureComponent<Props, State> {
componentDidMount() { componentDidMount() {
this.loadDatasource(); this.loadDatasource();
this.props.panel.events.on('refresh', this.onPanelRefresh);
} }
onPanelRefresh = () => {
if (this.state.angularScope) {
this.state.angularScope.range = getTimeSrv().timeRange();
}
};
getAngularQueryComponentScope(): AngularQueryComponentScope { getAngularQueryComponentScope(): AngularQueryComponentScope {
const { panel, query } = this.props; const { panel, query } = this.props;
const { datasource } = this.state; const { datasource } = this.state;
...@@ -56,6 +64,7 @@ export class QueryEditorRow extends PureComponent<Props, State> { ...@@ -56,6 +64,7 @@ export class QueryEditorRow extends PureComponent<Props, State> {
refresh: () => panel.refresh(), refresh: () => panel.refresh(),
render: () => panel.render(), render: () => panel.render(),
events: panel.events, events: panel.events,
range: getTimeSrv().timeRange(),
}; };
} }
...@@ -97,6 +106,8 @@ export class QueryEditorRow extends PureComponent<Props, State> { ...@@ -97,6 +106,8 @@ export class QueryEditorRow extends PureComponent<Props, State> {
} }
componentWillUnmount() { componentWillUnmount() {
this.props.panel.events.off('refresh', this.onPanelRefresh);
if (this.angularQueryEditor) { if (this.angularQueryEditor) {
this.angularQueryEditor.destroy(); this.angularQueryEditor.destroy();
} }
...@@ -250,4 +261,5 @@ export interface AngularQueryComponentScope { ...@@ -250,4 +261,5 @@ export interface AngularQueryComponentScope {
datasource: DataSourceApi; datasource: DataSourceApi;
toggleEditorMode?: () => void; toggleEditorMode?: () => void;
getCollapsedText?: () => string; getCollapsedText?: () => string;
range: TimeRange;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment