Commit e2e95589 by Daniel Lee

stackdriver: adds remove group by option

Adds a -- remove group by -- option to the group by
segment. When chosen it removes the group by.
parent d0a565d8
...@@ -67,6 +67,7 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -67,6 +67,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
lastQueryError?: string; lastQueryError?: string;
metricLabels: LabelType[]; metricLabels: LabelType[];
resourceLabels: LabelType[]; resourceLabels: LabelType[];
removeSegment: any;
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private uiSegmentSrv, private timeSrv) { constructor($scope, $injector, private uiSegmentSrv, private timeSrv) {
...@@ -83,6 +84,7 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -83,6 +84,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
this.groupBySegments = this.target.aggregation.groupBys.map(groupBy => { this.groupBySegments = this.target.aggregation.groupBys.map(groupBy => {
return uiSegmentSrv.getSegmentForValue(groupBy); return uiSegmentSrv.getSegmentForValue(groupBy);
}); });
this.removeSegment = uiSegmentSrv.newSegment({ fake: true, value: '-- remove group by --' });
this.ensurePlusButton(this.groupBySegments); this.ensurePlusButton(this.groupBySegments);
} }
...@@ -174,11 +176,15 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -174,11 +176,15 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}); });
}); });
return Promise.resolve([...metricLabels, ...resourceLabels]); return Promise.resolve([...metricLabels, ...resourceLabels, this.removeSegment]);
} }
groupByChanged(segment) { groupByChanged(segment, index) {
if (segment.value === this.removeSegment.value) {
this.groupBySegments.splice(index, 1);
} else {
segment.type = 'value'; segment.type = 'value';
}
const reducer = (memo, seg) => { const reducer = (memo, seg) => {
if (!seg.fake) { if (!seg.fake) {
......
...@@ -17,9 +17,10 @@ describe('StackdriverQueryCtrl', () => { ...@@ -17,9 +17,10 @@ describe('StackdriverQueryCtrl', () => {
}); });
it('should populate group bys segments', () => { it('should populate group bys segments', () => {
expect(result.length).toBe(2); expect(result.length).toBe(3);
expect(result[0].value).toBe('metric.label.metric-key-1'); expect(result[0].value).toBe('metric.label.metric-key-1');
expect(result[1].value).toBe('resource.label.resource-key-1'); expect(result[1].value).toBe('resource.label.resource-key-1');
expect(result[2].value).toBe('-- remove group by --');
}); });
}); });
...@@ -39,16 +40,18 @@ describe('StackdriverQueryCtrl', () => { ...@@ -39,16 +40,18 @@ describe('StackdriverQueryCtrl', () => {
}); });
it('should not be used to populate group bys segments', () => { it('should not be used to populate group bys segments', () => {
expect(result.length).toBe(2); expect(result.length).toBe(3);
expect(result[0].value).toBe('metric.label.metric-key-2'); expect(result[0].value).toBe('metric.label.metric-key-2');
expect(result[1].value).toBe('resource.label.resource-key-2'); expect(result[1].value).toBe('resource.label.resource-key-2');
expect(result[2].value).toBe('-- remove group by --');
}); });
}); });
describe('when a group by is selected', () => { describe('when a group by is selected', () => {
beforeEach(() => { beforeEach(() => {
const removeSegment = { fake: true, value: '-- remove group by --' };
const segment = { value: 'groupby1' }; const segment = { value: 'groupby1' };
ctrl.groupBySegments = [segment]; ctrl.groupBySegments = [segment, removeSegment];
ctrl.groupByChanged(segment); ctrl.groupByChanged(segment);
}); });
...@@ -56,6 +59,19 @@ describe('StackdriverQueryCtrl', () => { ...@@ -56,6 +59,19 @@ describe('StackdriverQueryCtrl', () => {
expect(ctrl.target.aggregation.groupBys.length).toBe(1); expect(ctrl.target.aggregation.groupBys.length).toBe(1);
}); });
}); });
describe('when a selected group by is removed', () => {
beforeEach(() => {
const removeSegment = { fake: true, value: '-- remove group by --' };
const segment = { value: 'groupby1' };
ctrl.groupBySegments = [segment, removeSegment];
ctrl.groupByChanged(removeSegment);
});
it('should be added to group bys list', () => {
expect(ctrl.target.aggregation.groupBys.length).toBe(0);
});
});
}); });
function createCtrlWithFakes() { function createCtrlWithFakes() {
......
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