From 2f18444a436daf3e9de35b3af6264c72ebb0403d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 15 Dec 2014 15:15:30 +0100 Subject: [PATCH] Graphite: alt node suggestions will now not include wildcard or template variables if the node is empty, Closes #1230 --- src/app/controllers/graphiteTarget.js | 6 ++++++ src/test/specs/graphiteTargetCtrl-specs.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index 3d899ac152f..480d7023ed4 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -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) { diff --git a/src/test/specs/graphiteTargetCtrl-specs.js b/src/test/specs/graphiteTargetCtrl-specs.js index 27be0d92b26..3e321c9e4a4 100644 --- a/src/test/specs/graphiteTargetCtrl-specs.js +++ b/src/test/specs/graphiteTargetCtrl-specs.js @@ -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}]));