cleanup aggregation picker

This commit is contained in:
Erik Sundell
2018-12-20 13:27:47 +01:00
parent 1452bc2e8a
commit 7a31076f09
2 changed files with 18 additions and 44 deletions

View File

@@ -27,50 +27,23 @@ export class Aggregations extends React.Component<Props, State> {
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<Props, State> {
}
render() {
const { aggOptions, displayAdvancedOptions } = this.state;
const { displayAdvancedOptions, aggOptions } = this.state;
const { templateSrv, onChange, crossSeriesReducer } = this.props;
return (

View File

@@ -65,7 +65,7 @@ export class QueryEditor extends React.Component<Props, State> {
metricKind,
},
() => {
// this.props.onQueryChange(this.state);
this.props.onQueryChange(this.state);
this.props.onExecuteQuery();
}
);
@@ -77,7 +77,7 @@ export class QueryEditor extends React.Component<Props, State> {
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<Props, State> {
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<Props, State> {
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;