Graphite: alt node suggestions will now not include wildcard or template variables if the node is empty, Closes #1230

This commit is contained in:
Torkel Ödegaard
2014-12-15 15:15:30 +01:00
parent 8a4ff5bddc
commit 2f18444a43
2 changed files with 22 additions and 0 deletions

View File

@@ -162,6 +162,11 @@ function (angular, _, config, gfunc, Parser) {
return new MetricSegment({ value: segment.text, expandable: segment.expandable });
});
if ($scope.altSegments.length === 0) {
return;
}
// add template variables
_.each(templateSrv.variables, function(variable) {
$scope.altSegments.unshift(new MetricSegment({
type: 'template',
@@ -170,6 +175,7 @@ function (angular, _, config, gfunc, Parser) {
}));
});
// add wildcard option
$scope.altSegments.unshift(new MetricSegment('*'));
})
.then(null, function(err) {

View File

@@ -136,6 +136,22 @@ define([
});
});
describe('when getting altSegments and metricFindQuery retuns empty array', function() {
beforeEach(function() {
ctx.scope.target.target = 'test.count';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
ctx.scope.init();
ctx.scope.getAltSegments(1);
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
});
it('should have no segments', function() {
expect(ctx.scope.altSegments.length).to.be(0);
});
});
describe('targetChanged', function() {
beforeEach(function() {
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));