Forráskód Böngészése

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

Torkel Ödegaard 11 éve
szülő
commit
2f18444a43

+ 6 - 0
src/app/controllers/graphiteTarget.js

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

+ 16 - 0
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() {
     describe('targetChanged', function() {
       beforeEach(function() {
       beforeEach(function() {
         ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));
         ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));