stackdriver: adds remove group by option

Adds a -- remove group by -- option to the group by
segment. When chosen it removes the group by.
This commit is contained in:
Daniel Lee 2018-09-14 00:13:23 +02:00
parent d0a565d853
commit e2e95589e3
2 changed files with 28 additions and 6 deletions

View File

@ -67,6 +67,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
lastQueryError?: string;
metricLabels: LabelType[];
resourceLabels: LabelType[];
removeSegment: any;
/** @ngInject */
constructor($scope, $injector, private uiSegmentSrv, private timeSrv) {
@ -83,6 +84,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
this.groupBySegments = this.target.aggregation.groupBys.map(groupBy => {
return uiSegmentSrv.getSegmentForValue(groupBy);
});
this.removeSegment = uiSegmentSrv.newSegment({ fake: true, value: '-- remove group by --' });
this.ensurePlusButton(this.groupBySegments);
}
@ -174,11 +176,15 @@ export class StackdriverQueryCtrl extends QueryCtrl {
});
});
return Promise.resolve([...metricLabels, ...resourceLabels]);
return Promise.resolve([...metricLabels, ...resourceLabels, this.removeSegment]);
}
groupByChanged(segment) {
segment.type = 'value';
groupByChanged(segment, index) {
if (segment.value === this.removeSegment.value) {
this.groupBySegments.splice(index, 1);
} else {
segment.type = 'value';
}
const reducer = (memo, seg) => {
if (!seg.fake) {

View File

@ -17,9 +17,10 @@ describe('StackdriverQueryCtrl', () => {
});
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[1].value).toBe('resource.label.resource-key-1');
expect(result[2].value).toBe('-- remove group by --');
});
});
@ -39,16 +40,18 @@ describe('StackdriverQueryCtrl', () => {
});
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[1].value).toBe('resource.label.resource-key-2');
expect(result[2].value).toBe('-- remove group by --');
});
});
describe('when a group by is selected', () => {
beforeEach(() => {
const removeSegment = { fake: true, value: '-- remove group by --' };
const segment = { value: 'groupby1' };
ctrl.groupBySegments = [segment];
ctrl.groupBySegments = [segment, removeSegment];
ctrl.groupByChanged(segment);
});
@ -56,6 +59,19 @@ describe('StackdriverQueryCtrl', () => {
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() {