Commit 111b3229 by Alexander Zobnin Committed by Torkel Ödegaard

Fixes for graphite tags editor (#10861)

* graphite: don't fetch tags on editor init

* add debounce option to query editor directives

* graphite: debounce tag queries
parent c01b8052
......@@ -34,6 +34,7 @@ export class FormDropdownCtrl {
lookupText: boolean;
placeholder: any;
startOpen: any;
debounce: number;
/** @ngInject **/
constructor(private $scope, $element, private $sce, private templateSrv, private $q) {
......@@ -72,6 +73,10 @@ export class FormDropdownCtrl {
this.source(this.query, this.process.bind(this));
};
if (this.debounce) {
typeahead.lookup = _.debounce(typeahead.lookup, 500, { leading: true });
}
this.linkElement.keydown(evt => {
// trigger typeahead on down arrow or enter key
if (evt.keyCode === 40 || evt.keyCode === 13) {
......@@ -263,6 +268,7 @@ export function formDropdownDirective() {
lookupText: '@',
placeholder: '@',
startOpen: '@',
debounce: '@',
},
};
}
......
......@@ -23,11 +23,13 @@ export function queryPartEditorDirective($compile, templateSrv) {
scope: {
part: '=',
handleEvent: '&',
debounce: '@',
},
link: function postLink($scope, elem) {
var part = $scope.part;
var partDef = part.def;
var $paramsContainer = elem.find('.query-part-parameters');
var debounceLookup = $scope.debounce;
$scope.partActions = [];
......@@ -128,6 +130,10 @@ export function queryPartEditorDirective($compile, templateSrv) {
var items = this.source(this.query, $.proxy(this.process, this));
return items ? this.process(items) : items;
};
if (debounceLookup) {
typeahead.lookup = _.debounce(typeahead.lookup, 500, { leading: true });
}
}
$scope.showActionsMenu = function() {
......
......@@ -22,6 +22,7 @@ function (_, $, coreModule) {
segment: "=",
getOptions: "&",
onChange: "&",
debounce: "@",
},
link: function($scope, elem) {
var $input = $(inputTemplate);
......@@ -30,6 +31,7 @@ function (_, $, coreModule) {
var options = null;
var cancelBlur = null;
var linkMode = true;
var debounceLookup = $scope.debounce;
$input.appendTo(elem);
$button.appendTo(elem);
......@@ -135,6 +137,10 @@ function (_, $, coreModule) {
return items ? this.process(items) : items;
};
if (debounceLookup) {
typeahead.lookup = _.debounce(typeahead.lookup, 500, {leading: true});
}
$button.keydown(function(evt) {
// trigger typeahead on down arrow or enter key
if (evt.keyCode === 40 || evt.keyCode === 13) {
......
......@@ -13,9 +13,9 @@
<div ng-if="ctrl.queryModel.seriesByTagUsed" ng-repeat="tag in ctrl.queryModel.tags" class="gf-form">
<gf-form-dropdown
model="tag.key"
lookup-text="false"
allow-custom="true"
label-mode="true"
debounce="true"
placeholder="Tag key"
css-class="query-segment-key"
get-options="ctrl.getTags($index, $query)"
......@@ -23,8 +23,6 @@
/>
<gf-form-dropdown
model="tag.operator"
lookup-text="false"
allow-custom="false"
label-mode="true"
css-class="query-segment-operator"
get-options="ctrl.getTagOperators()"
......@@ -33,9 +31,9 @@
/>
<gf-form-dropdown
model="tag.value"
lookup-text="false"
allow-custom="true"
label-mode="true"
debounce="true"
css-class="query-segment-value"
placeholder="Tag value"
get-options="ctrl.getTagValues(tag, $index, $query)"
......@@ -45,7 +43,7 @@
</div>
<div ng-if="ctrl.queryModel.seriesByTagUsed" ng-repeat="segment in ctrl.addTagSegments" role="menuitem" class="gf-form">
<metric-segment segment="segment" get-options="ctrl.getTagsAsSegments($query)" on-change="ctrl.addNewTag(segment)" />
<metric-segment segment="segment" get-options="ctrl.getTagsAsSegments($query)" on-change="ctrl.addNewTag(segment)" debounce="true" />
</div>
<div ng-if="!ctrl.queryModel.seriesByTagUsed" ng-repeat="segment in ctrl.segments" role="menuitem" class="gf-form">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment