Graphite: Fixed issue with functions with multiple required params and no defaults caused params that could not be edited (groupByNodes groupByTags) (#21814)

* Graphite: Fixed issue functions with multiple required params and no defaults

* removed some prev changes

* Update public/app/plugins/datasource/graphite/func_editor.ts

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
Torkel Ödegaard 2020-01-30 08:06:23 +00:00 committed by GitHub
parent 7638156666
commit 0fd088c757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View File

@ -172,7 +172,7 @@ export function sqlPartEditorDirective(templateSrv: any) {
}
const paramValue = templateSrv.highlightVariablesAsHtml(part.params[index]);
const $paramLink = $('<a class="graphite-func-param-link pointer">' + paramValue + '</a>');
const $paramLink = $('<a class="query-part__link">' + paramValue + '</a>');
const $input = $(paramTemplate);
$paramLink.appendTo($paramsContainer);

View File

@ -184,24 +184,27 @@ export function graphiteFuncEditor($compile: any, templateSrv: TemplateSrv) {
}
let paramValue = templateSrv.highlightVariablesAsHtml(func.params[index]);
const hasValue = paramValue !== null && paramValue !== undefined;
const hasValue = paramValue !== null && paramValue !== undefined && paramValue !== '';
const last = index >= func.params.length - 1 && param.optional && !hasValue;
let linkClass = 'query-part__link';
if (last) {
linkClass += ' query-part__last';
}
if (last && param.multiple) {
paramValue = '+';
} else if (!hasValue) {
// for params with no value default to param name
paramValue = param.name;
linkClass += ' query-part__link--no-value';
}
if (index > 0) {
$('<span class="comma' + (last ? ' query-part__last' : '') + '">, </span>').appendTo(elem);
}
const $paramLink = $(
'<a ng-click="" class="graphite-func-param-link' +
(last ? ' query-part__last' : '') +
'">' +
(hasValue ? paramValue : '&nbsp;') +
'</a>'
);
const $paramLink = $(`<a ng-click="" class="${linkClass}">${paramValue}</a>`);
const $input = $(paramTemplate);
$input.attr('placeholder', param.name);
@ -232,7 +235,7 @@ export function graphiteFuncEditor($compile: any, templateSrv: TemplateSrv) {
$scope.func.added = false;
setTimeout(() => {
elem
.find('.graphite-func-param-link')
.find('.query-part__link')
.first()
.click();
}, 10);

View File

@ -15,3 +15,11 @@
display: inline;
}
}
.query-part__link {
cursor: pointer;
&--no-value {
color: $text-muted;
}
}