From 7a31076f0932edae267b4744f77f88174b89f9f9 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 20 Dec 2018 13:27:47 +0100 Subject: [PATCH] cleanup aggregation picker --- .../stackdriver/components/Aggregations.tsx | 45 ++++--------------- .../stackdriver/components/QueryEditor.tsx | 17 +++---- 2 files changed, 18 insertions(+), 44 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx index 2fa3b9b9f7d..22bd2d268cb 100644 --- a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx @@ -27,50 +27,23 @@ export class Aggregations extends React.Component { displayAdvancedOptions: false, }; - constructor(props) { - super(props); - } - componentDidMount() { - if (this.props.metricDescriptor !== null) { - this.setAggOptions(this.props); - } + this.setAggOptions(this.props); } componentWillReceiveProps(nextProps: Props) { - if (nextProps.metricDescriptor !== null) { - this.setAggOptions(nextProps); - } + this.setAggOptions(nextProps); } - setAggOptions({ metricDescriptor, crossSeriesReducer, groupBys, templateSrv }) { - let aggregations = getAggregationOptionsByMetric(metricDescriptor.valueType, metricDescriptor.metricKind).map( - a => ({ + setAggOptions({ metricDescriptor }: Props) { + let aggOptions = []; + if (metricDescriptor !== null) { + aggOptions = getAggregationOptionsByMetric(metricDescriptor.valueType, metricDescriptor.metricKind).map(a => ({ ...a, label: a.text, - }) - ); - - if (aggregations.length > 0 && !aggregations.find(o => o.value === templateSrv.replace(crossSeriesReducer))) { - this.deselectAggregationOption('REDUCE_NONE'); + })); } - - if (groupBys.length > 0) { - aggregations = aggregations.filter(o => o.value !== 'REDUCE_NONE'); - if (crossSeriesReducer === 'REDUCE_NONE') { - this.deselectAggregationOption('REDUCE_NONE'); - } - } - this.setState({ aggOptions: aggregations }); - } - - deselectAggregationOption(notValidOptionValue: string) { - const aggregations = getAggregationOptionsByMetric( - this.props.metricDescriptor.valueType, - this.props.metricDescriptor.metricKind - ); - const newValue = aggregations.find(o => o.value !== notValidOptionValue); - this.props.onChange(newValue ? newValue.value : ''); + this.setState({ aggOptions }); } handleToggleDisplayAdvanced() { @@ -80,7 +53,7 @@ export class Aggregations extends React.Component { } render() { - const { aggOptions, displayAdvancedOptions } = this.state; + const { displayAdvancedOptions, aggOptions } = this.state; const { templateSrv, onChange, crossSeriesReducer } = this.props; return ( diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx index b661166e2a2..b08ecd55fe9 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx @@ -65,7 +65,7 @@ export class QueryEditor extends React.Component { metricKind, }, () => { - // this.props.onQueryChange(this.state); + this.props.onQueryChange(this.state); this.props.onExecuteQuery(); } ); @@ -77,7 +77,7 @@ export class QueryEditor extends React.Component { filters: value, }, () => { - // this.props.onQueryChange(this.state); + this.props.onQueryChange(this.state); this.props.onExecuteQuery(); } ); @@ -89,7 +89,7 @@ export class QueryEditor extends React.Component { groupBys: value, }, () => { - // this.props.onQueryChange(this.state); + this.props.onQueryChange(this.state); this.props.onExecuteQuery(); } ); @@ -97,21 +97,22 @@ export class QueryEditor extends React.Component { handleAggregationChange(value) { this.setState({ crossSeriesReducer: value }, () => { - // this.props.onQueryChange(this.state); + this.props.onQueryChange(this.state); this.props.onExecuteQuery(); }); } handleAlignmentChange(value) { this.setState({ perSeriesAligner: value }, () => { - // this.props.onQueryChange(this.state); + this.props.onQueryChange(this.state); this.props.onExecuteQuery(); }); } - componentDidUpdate(prevProps: Props, prevState: Target) { - this.props.onQueryChange(this.state); - } + // componentDidUpdate(prevProps: Props, prevState: Target) { + // this.props.onQueryChange(this.state); + + // } render() { const { defaultProject, metricType, crossSeriesReducer, groupBys, perSeriesAligner, alignOptions } = this.state;