mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
CloudWatch: dimension_values templating fix (#21401)
* Handle dimension value if passed as array * Break out dimension value loading into its own func
This commit is contained in:
parent
d22e53bba8
commit
cf2dd51827
@ -419,6 +419,13 @@ func (e *CloudWatchExecutor) handleGetDimensionValues(ctx context.Context, param
|
||||
Name: aws.String(k),
|
||||
Value: aws.String(vv),
|
||||
})
|
||||
} else if vv, ok := v.([]interface{}); ok {
|
||||
for _, v := range vv {
|
||||
dimensions = append(dimensions, &cloudwatch.DimensionFilter{
|
||||
Name: aws.String(k),
|
||||
Value: aws.String(v.(string)),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,21 @@ export class QueryEditor extends PureComponent<Props, State> {
|
||||
onRunQuery();
|
||||
}
|
||||
|
||||
// Load dimension values based on current selected dimensions.
|
||||
// Remove the new dimension key and all dimensions that has a wildcard as selected value
|
||||
loadDimensionValues = (newKey: string) => {
|
||||
const { datasource, query } = this.props;
|
||||
const { [newKey]: value, ...dim } = query.dimensions;
|
||||
const newDimensions = Object.entries(dim).reduce(
|
||||
(result, [key, value]) => (value === '*' ? result : { ...result, [key]: value }),
|
||||
{}
|
||||
);
|
||||
return datasource
|
||||
.getDimensionValues(query.region, query.namespace, query.metricName, newKey, newDimensions)
|
||||
.then(values => (values.length ? [{ value: '*', text: '*', label: '*' }, ...values] : values))
|
||||
.then(this.appendTemplateVariables);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { query, datasource, onChange, onRunQuery, data } = this.props;
|
||||
const { regions, namespaces, variableOptionGroup: variableOptionGroup, showMeta } = this.state;
|
||||
@ -160,13 +175,7 @@ export class QueryEditor extends PureComponent<Props, State> {
|
||||
loadKeys={() =>
|
||||
datasource.getDimensionKeys(query.namespace, query.region).then(this.appendTemplateVariables)
|
||||
}
|
||||
loadValues={newKey => {
|
||||
const { [newKey]: value, ...newDimensions } = query.dimensions;
|
||||
return datasource
|
||||
.getDimensionValues(query.region, query.namespace, query.metricName, newKey, newDimensions)
|
||||
.then(values => (values.length ? [{ value: '*', text: '*', label: '*' }, ...values] : values))
|
||||
.then(this.appendTemplateVariables);
|
||||
}}
|
||||
loadValues={this.loadDimensionValues}
|
||||
/>
|
||||
</QueryInlineField>
|
||||
</>
|
||||
|
Loading…
Reference in New Issue
Block a user