mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(graphite): minor fix to graphite query editor so it does not issue render requests for incomplete queries, fixes #3510
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
<li ng-if="dashboardMeta.canEdit"><a class="pointer" ng-click="openEditView('templating');">Templating</a></li>
|
||||
<li><a class="pointer" ng-click="exportDashboard();">Export</a></li>
|
||||
<li><a class="pointer" ng-click="editJson();">View JSON</a></li>
|
||||
<li ng-if="contextSrv.isEditor && !dashboard.editable"><a class="pointer" ng-click="makeEditable();">Make Editable</a></li>
|
||||
<li ng-if="contextSrv.isEditor"><a class="pointer" ng-click="saveDashboardAs();">Save As...</a></li>
|
||||
<li ng-if="dashboardMeta.canSave"><a class="pointer" ng-click="deleteDashboard();">Delete dashboard</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -11,7 +11,7 @@ function (angular, _, $, kbn, dateMath, rangeUtil) {
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
|
||||
module.service('panelHelper', function(timeSrv, $rootScope) {
|
||||
module.service('panelHelper', function(timeSrv, $rootScope, $q) {
|
||||
var self = this;
|
||||
|
||||
this.setTimeQueryStart = function(scope) {
|
||||
@@ -103,6 +103,10 @@ function (angular, _, $, kbn, dateMath, rangeUtil) {
|
||||
};
|
||||
|
||||
this.issueMetricQuery = function(scope, datasource) {
|
||||
if (!scope.panel.targets || scope.panel.targets.length === 0) {
|
||||
return $q.when([]);
|
||||
}
|
||||
|
||||
var metricsQuery = {
|
||||
range: scope.range,
|
||||
rangeRaw: scope.rangeRaw,
|
||||
|
||||
@@ -37,6 +37,9 @@ function (angular, _, $, config, dateMath) {
|
||||
};
|
||||
|
||||
var params = this.buildGraphiteParams(graphOptions, options.scopedVars);
|
||||
if (params.length === 0) {
|
||||
return $q.when([]);
|
||||
}
|
||||
|
||||
if (options.format === 'png') {
|
||||
return $q.when(this.url + '/render' + '?' + params.join('&'));
|
||||
@@ -235,6 +238,7 @@ function (angular, _, $, config, dateMath) {
|
||||
var target, targetValue, i;
|
||||
var regex = /\#([A-Z])/g;
|
||||
var intervalFormatFixRegex = /'(\d+)m'/gi;
|
||||
var hasTargets = false;
|
||||
|
||||
if (options.format !== 'png') {
|
||||
options['format'] = 'json';
|
||||
@@ -274,6 +278,7 @@ function (angular, _, $, config, dateMath) {
|
||||
targets[target.refId] = targetValue;
|
||||
|
||||
if (!target.hide) {
|
||||
hasTargets = true;
|
||||
clean_options.push("target=" + encodeURIComponent(targetValue));
|
||||
}
|
||||
}
|
||||
@@ -285,6 +290,10 @@ function (angular, _, $, config, dateMath) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasTargets) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return clean_options;
|
||||
};
|
||||
|
||||
|
||||
@@ -132,9 +132,7 @@ function (angular, _, config, gfunc, Parser) {
|
||||
$scope.segments = $scope.segments.splice(0, fromIndex);
|
||||
$scope.segments.push(uiSegmentSrv.newSelectMetric());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (segments[0].expandable) {
|
||||
} else if (segments[0].expandable) {
|
||||
if ($scope.segments.length === fromIndex) {
|
||||
$scope.segments.push(uiSegmentSrv.newSelectMetric());
|
||||
}
|
||||
@@ -195,8 +193,7 @@ function (angular, _, config, gfunc, Parser) {
|
||||
}
|
||||
|
||||
if (segment.expandable) {
|
||||
return checkOtherSegments(segmentIndex + 1)
|
||||
.then(function () {
|
||||
return checkOtherSegments(segmentIndex + 1).then(function() {
|
||||
setSegmentFocus(segmentIndex + 1);
|
||||
$scope.targetChanged();
|
||||
});
|
||||
@@ -220,13 +217,14 @@ function (angular, _, config, gfunc, Parser) {
|
||||
}
|
||||
|
||||
var oldTarget = $scope.target.target;
|
||||
|
||||
var target = getSegmentPathUpTo($scope.segments.length);
|
||||
$scope.target.target = _.reduce($scope.functions, wrapFunction, target);
|
||||
|
||||
if ($scope.target.target !== oldTarget) {
|
||||
if ($scope.segments[$scope.segments.length - 1].value !== 'select metric') {
|
||||
$scope.$parent.get_data();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.removeFunction = function(func) {
|
||||
|
||||
@@ -66,6 +66,12 @@ describe('graphiteDatasource', function() {
|
||||
});
|
||||
|
||||
describe('building graphite params', function() {
|
||||
it('should return empty array if no targets', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{}]
|
||||
});
|
||||
expect(results.length).to.be(0);
|
||||
});
|
||||
|
||||
it('should uri escape targets', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
|
||||
Reference in New Issue
Block a user