mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 06:42:52 +08:00
Postgres: Fix aggregate dropdown when TimescaleDB is enabled (#45993)
* add timescaleDB checker function * use existing fn findAggregateIndex * build options from empty list * refactor fn and handle state for existing elem * remove newline
This commit is contained in:
@ -111,10 +111,27 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
|
||||
timescaleAggCheck() {
|
||||
const aggIndex = this.findAggregateIndex(this.selectParts[0]);
|
||||
|
||||
// add or remove TimescaleDB aggregate functions as needed
|
||||
if (aggIndex !== -1) {
|
||||
const baseOpts = this.selectParts[0][aggIndex].def.params[0].baseOptions;
|
||||
const timescaleOpts = baseOpts.concat(this.selectParts[0][aggIndex].def.params[0].timescaleOptions);
|
||||
|
||||
if (this.datasource.jsonData.timescaledb === true) {
|
||||
this.selectParts[0][aggIndex].def.params[0].options = timescaleOpts;
|
||||
} else {
|
||||
this.selectParts[0][aggIndex].def.params[0].options = baseOpts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateProjection() {
|
||||
this.selectParts = map(this.target.select, (parts: any) => {
|
||||
return map(parts, sqlPart.create).filter((n) => n);
|
||||
});
|
||||
this.timescaleAggCheck();
|
||||
this.whereParts = map(this.target.where, sqlPart.create).filter((n) => n);
|
||||
this.groupParts = map(this.target.group, sqlPart.create).filter((n) => n);
|
||||
}
|
||||
@ -125,6 +142,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
return { type: part.def.type, datatype: part.datatype, params: part.params };
|
||||
});
|
||||
});
|
||||
this.timescaleAggCheck();
|
||||
this.target.where = map(this.whereParts, (part: any) => {
|
||||
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
|
||||
});
|
||||
|
Reference in New Issue
Block a user