mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06: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:
parent
1fef87fbcc
commit
c863676b65
@ -111,10 +111,27 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
|||||||
this.panelCtrl.refresh();
|
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() {
|
updateProjection() {
|
||||||
this.selectParts = map(this.target.select, (parts: any) => {
|
this.selectParts = map(this.target.select, (parts: any) => {
|
||||||
return map(parts, sqlPart.create).filter((n) => n);
|
return map(parts, sqlPart.create).filter((n) => n);
|
||||||
});
|
});
|
||||||
|
this.timescaleAggCheck();
|
||||||
this.whereParts = map(this.target.where, sqlPart.create).filter((n) => n);
|
this.whereParts = map(this.target.where, sqlPart.create).filter((n) => n);
|
||||||
this.groupParts = map(this.target.group, 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 };
|
return { type: part.def.type, datatype: part.datatype, params: part.params };
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
this.timescaleAggCheck();
|
||||||
this.target.where = map(this.whereParts, (part: any) => {
|
this.target.where = map(this.whereParts, (part: any) => {
|
||||||
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
|
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
|
||||||
});
|
});
|
||||||
|
@ -49,7 +49,9 @@ register({
|
|||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
options: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
|
options: [],
|
||||||
|
baseOptions: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
|
||||||
|
timescaleOptions: ['first', 'last'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
defaultParams: ['avg'],
|
defaultParams: ['avg'],
|
||||||
|
Loading…
Reference in New Issue
Block a user