mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
add column alias when add aggregate function
This commit is contained in:
@ -29,6 +29,8 @@ function columnRenderer(part, innerExpr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replaceAggregationAddStrategy(selectParts, partModel) {
|
function replaceAggregationAddStrategy(selectParts, partModel) {
|
||||||
|
var hasAlias = false;
|
||||||
|
|
||||||
// look for existing aggregation
|
// look for existing aggregation
|
||||||
for (var i = 0; i < selectParts.length; i++) {
|
for (var i = 0; i < selectParts.length; i++) {
|
||||||
var part = selectParts[i];
|
var part = selectParts[i];
|
||||||
@ -36,6 +38,15 @@ function replaceAggregationAddStrategy(selectParts, partModel) {
|
|||||||
selectParts[i] = partModel;
|
selectParts[i] = partModel;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (part.def.type === 'alias') {
|
||||||
|
hasAlias = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add alias if none exists yet
|
||||||
|
if (!hasAlias) {
|
||||||
|
var aliasModel = createPart({ type: 'alias', params: [selectParts[0].params[0]] });
|
||||||
|
selectParts.push(aliasModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectParts.splice(1, 0, partModel);
|
selectParts.splice(1, 0, partModel);
|
||||||
@ -117,7 +128,7 @@ register({
|
|||||||
|
|
||||||
register({
|
register({
|
||||||
type: 'macro',
|
type: 'macro',
|
||||||
style: 'function',
|
style: 'label',
|
||||||
label: 'Macro:',
|
label: 'Macro:',
|
||||||
addStrategy: addExpressionStrategy,
|
addStrategy: addExpressionStrategy,
|
||||||
params: [],
|
params: [],
|
||||||
|
Reference in New Issue
Block a user