From 111b32290a9291900dfb02950b5e71fb76a895c4 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Fri, 9 Feb 2018 18:20:30 +0300 Subject: [PATCH] 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 --- public/app/core/components/form_dropdown/form_dropdown.ts | 6 ++++++ .../app/core/components/query_part/query_part_editor.ts | 6 ++++++ public/app/core/directives/metric_segment.js | 6 ++++++ .../datasource/graphite/partials/query.editor.html | 8 +++----- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/public/app/core/components/form_dropdown/form_dropdown.ts b/public/app/core/components/form_dropdown/form_dropdown.ts index cf9c6b5efe0..7ac55e54cf1 100644 --- a/public/app/core/components/form_dropdown/form_dropdown.ts +++ b/public/app/core/components/form_dropdown/form_dropdown.ts @@ -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: '@', }, }; } diff --git a/public/app/core/components/query_part/query_part_editor.ts b/public/app/core/components/query_part/query_part_editor.ts index 138da186238..5fd6e16c466 100644 --- a/public/app/core/components/query_part/query_part_editor.ts +++ b/public/app/core/components/query_part/query_part_editor.ts @@ -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() { diff --git a/public/app/core/directives/metric_segment.js b/public/app/core/directives/metric_segment.js index 2754f8d8c6e..7ba4a5a5259 100644 --- a/public/app/core/directives/metric_segment.js +++ b/public/app/core/directives/metric_segment.js @@ -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) { diff --git a/public/app/plugins/datasource/graphite/partials/query.editor.html b/public/app/plugins/datasource/graphite/partials/query.editor.html index 6414a39c94f..51c25100c1e 100755 --- a/public/app/plugins/datasource/graphite/partials/query.editor.html +++ b/public/app/plugins/datasource/graphite/partials/query.editor.html @@ -13,9 +13,9 @@