Commit b3d494d4 by Torkel Ödegaard

feat(influxdb): minor fixes to new editor

parent 72d9fcdc
...@@ -44,20 +44,34 @@ class InfluxQuery { ...@@ -44,20 +44,34 @@ class InfluxQuery {
} }
hasGroupByTime() { hasGroupByTime() {
return false; return _.find(this.target.groupBy, (g: any) => g.type === 'time');
} }
hasFill() { hasFill() {
return false; return _.find(this.target.groupBy, (g: any) => g.type === 'fill');
} }
addGroupBy(value) { addGroupBy(value) {
var stringParts = value.match(/^(\w+)\((.*)\)$/); var stringParts = value.match(/^(\w+)\((.*)\)$/);
var typePart = stringParts[1]; var typePart = stringParts[1];
var arg = stringParts[2]; var arg = stringParts[2];
console.log(value, stringParts);
var partModel = queryPart.create({type: typePart, params: [arg]}); var partModel = queryPart.create({type: typePart, params: [arg]});
this.target.groupBy.push(partModel.part); var partCount = this.target.groupBy.length;
if (partCount === 0) {
this.target.groupBy.push(partModel.part);
} else if (typePart === 'time') {
this.target.groupBy.splice(0, 0, partModel.part);
} else if (typePart === 'tag') {
if (this.target.groupBy[partCount-1].type === 'fill') {
this.target.groupBy.splice(partCount-1, 0, partModel.part);
} else {
this.target.groupBy.push(partModel.part);
}
} else {
this.target.groupBy.push(partModel.part);
}
this.updateProjection(); this.updateProjection();
} }
......
...@@ -186,7 +186,7 @@ QueryPartDef.register({ ...@@ -186,7 +186,7 @@ QueryPartDef.register({
QueryPartDef.register({ QueryPartDef.register({
type: 'time', type: 'time',
category: groupByTimeFunctions, category: groupByTimeFunctions,
params: [{ name: "rate", type: "interval", options: ['$interval', '1s', '10s', '1m', '5min', '10m', '15m', '1h'] }], params: [{ name: "rate", type: "interval", options: ['$interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'] }],
defaultParams: ['$interval'], defaultParams: ['$interval'],
renderer: functionRenderer, renderer: functionRenderer,
}); });
......
...@@ -58,6 +58,34 @@ describe.only('InfluxQuery', function() { ...@@ -58,6 +58,34 @@ describe.only('InfluxQuery', function() {
}); });
}); });
describe('when adding group by part', function() {
it('should add tag before fill', function() {
var query = new InfluxQuery({
measurement: 'cpu',
groupBy: [{type: 'time'}, {type: 'fill'}]
});
query.addGroupBy('tag(host)');
expect(query.target.groupBy.length).to.be(3);
expect(query.target.groupBy[1].type).to.be('tag');
expect(query.target.groupBy[1].params[0]).to.be('host');
expect(query.target.groupBy[2].type).to.be('fill');
});
it('should add tag last if no fill', function() {
var query = new InfluxQuery({
measurement: 'cpu',
groupBy: []
});
query.addGroupBy('tag(host)');
expect(query.target.groupBy.length).to.be(1);
expect(query.target.groupBy[0].type).to.be('tag');
});
});
describe('when adding select part', function() { describe('when adding select part', function() {
it('should add mean after after field', function() { it('should add mean after after field', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment