From b9cf15786d037f3904483553d9da8ec45f71f377 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 21 Dec 2018 23:21:55 +0100 Subject: [PATCH] use ds template srv reference --- .../stackdriver/angular_wrappers.ts | 1 - .../stackdriver/components/Aggregations.tsx | 2 +- .../stackdriver/components/Alignments.tsx | 6 +---- .../stackdriver/components/QueryEditor.tsx | 25 +++++++++---------- .../stackdriver/partials/query.editor.html | 1 - .../datasource/stackdriver/query_ctrl.ts | 5 +--- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/angular_wrappers.ts b/public/app/plugins/datasource/stackdriver/angular_wrappers.ts index 537b03f9c99..b5e18c77d03 100644 --- a/public/app/plugins/datasource/stackdriver/angular_wrappers.ts +++ b/public/app/plugins/datasource/stackdriver/angular_wrappers.ts @@ -9,6 +9,5 @@ export function registerAngularDirectives() { ['events', { watchDepth: 'reference' }], ['uiSegmentSrv', { watchDepth: 'reference' }], ['datasource', { watchDepth: 'reference' }], - ['templateSrv', { watchDepth: 'reference' }], ]); } diff --git a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx index 22bd2d268cb..7b84450635b 100644 --- a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx @@ -37,7 +37,7 @@ export class Aggregations extends React.Component { setAggOptions({ metricDescriptor }: Props) { let aggOptions = []; - if (metricDescriptor !== null) { + if (metricDescriptor) { aggOptions = getAggregationOptionsByMetric(metricDescriptor.valueType, metricDescriptor.metricKind).map(a => ({ ...a, label: a.text, diff --git a/public/app/plugins/datasource/stackdriver/components/Alignments.tsx b/public/app/plugins/datasource/stackdriver/components/Alignments.tsx index bf26d3347d0..5f90a604d7a 100644 --- a/public/app/plugins/datasource/stackdriver/components/Alignments.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Alignments.tsx @@ -4,13 +4,9 @@ import _ from 'lodash'; import { StackdriverPicker } from './StackdriverPicker'; export interface Props { - onChange: (metricDescriptor) => void; + onChange: (perSeriesAligner) => void; templateSrv: any; alignOptions: any[]; - metricDescriptor: { - valueType: string; - metricKind: string; - }; perSeriesAligner: string; } diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx index 632ea3c8ac9..d57e33dfa0e 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx @@ -17,7 +17,6 @@ export interface Props { target: Target; events: any; datasource: any; - templateSrv: any; uiSegmentSrv: any; } @@ -51,10 +50,10 @@ export class QueryEditor extends React.Component { state: State = DefaultTarget; componentDidMount() { - const { events } = this.props; + const { events, target, datasource } = this.props; events.on('data-received', this.onDataReceived.bind(this)); events.on('data-error', this.onDataError.bind(this)); - const { perSeriesAligner, alignOptions } = getAlignmentPickerData(this.props.target, this.props.templateSrv); + const { perSeriesAligner, alignOptions } = getAlignmentPickerData(target, datasource.templateSrv); this.setState({ ...this.props.target, alignOptions, @@ -89,9 +88,10 @@ export class QueryEditor extends React.Component { } handleMetricTypeChange({ valueType, metricKind, type, unit }) { + const { datasource, onQueryChange, onExecuteQuery } = this.props; const { perSeriesAligner, alignOptions } = getAlignmentPickerData( { valueType, metricKind, perSeriesAligner: this.state.perSeriesAligner }, - this.props.templateSrv + datasource.templateSrv ); this.setState( { @@ -103,8 +103,8 @@ export class QueryEditor extends React.Component { metricKind, }, () => { - this.props.onQueryChange(this.state); - this.props.onExecuteQuery(); + onQueryChange(this.state); + onExecuteQuery(); } ); } @@ -129,14 +129,14 @@ export class QueryEditor extends React.Component { lastQuery, lastQueryError, } = this.state; - const { templateSrv, datasource, uiSegmentSrv } = this.props; + const { datasource, uiSegmentSrv } = this.props; return ( this.handleMetricTypeChange(value)} > @@ -147,13 +147,13 @@ export class QueryEditor extends React.Component { groupBysChanged={value => this.handleChange('groupBys', value)} target={this.state} uiSegmentSrv={uiSegmentSrv} - templateSrv={templateSrv} + templateSrv={datasource.templateSrv} datasource={datasource} metricType={metric ? metric.type : ''} /> this.handleChange('crossSeriesReducer', value)} @@ -162,8 +162,7 @@ export class QueryEditor extends React.Component { displayAdvancedOptions && ( this.handleChange('perSeriesAligner', value)} /> @@ -173,7 +172,7 @@ export class QueryEditor extends React.Component { this.handleChange('aliasBy', value)} /> this.handleChange('alignmentPeriod', value)} /> diff --git a/public/app/plugins/datasource/stackdriver/partials/query.editor.html b/public/app/plugins/datasource/stackdriver/partials/query.editor.html index f27b08609b4..58aa1ae8d99 100755 --- a/public/app/plugins/datasource/stackdriver/partials/query.editor.html +++ b/public/app/plugins/datasource/stackdriver/partials/query.editor.html @@ -2,7 +2,6 @@