From 3ce4287e8cec87f3040834c2e0034cafea5a1a46 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 3 Jan 2019 09:15:49 +0100 Subject: [PATCH] fix template variable bug --- .../datasource/stackdriver/components/AliasBy.tsx | 6 ++++++ .../datasource/stackdriver/components/Metrics.tsx | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx b/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx index ae397a2c4d8..486a051fdc1 100644 --- a/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx +++ b/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx @@ -22,6 +22,12 @@ export class AliasBy extends Component { this.setState({ value: this.props.value }); } + componentWillReceiveProps(nextProps: Props) { + if (nextProps.value !== this.props.value) { + this.setState({ value: nextProps.value }); + } + } + handleChange(e) { this.setState({ value: e.target.value }); this.onChange(e.target.value); diff --git a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx index 4ea09245408..c2993e30bee 100644 --- a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx @@ -119,7 +119,7 @@ export class Metrics extends React.Component { handleMetricTypeChange(value) { const metricDescriptor = this.getSelectedMetricDescriptor(value); this.setState({ metricDescriptor }); - this.props.onChange(metricDescriptor); + this.props.onChange({ ...metricDescriptor, type: value }); } getServicesList(metricDescriptors) { @@ -170,7 +170,13 @@ export class Metrics extends React.Component { onChange={value => this.handleMetricTypeChange(value)} value={metricType} variables={templateSrv.variables} - options={metrics} + options={[ + { + label: 'Metrics', + expanded: true, + options: metrics, + }, + ]} placeholder="Select Metric" className="width-15" />