From 3d6e9076c93741da0990de2a7dfe3d1694026245 Mon Sep 17 00:00:00 2001 From: Connor Lindsey Date: Mon, 10 Jan 2022 07:37:35 -0700 Subject: [PATCH] Tempo: Provide tag value completion items consistently (#43773) --- .../datasource/tempo/language_provider.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/tempo/language_provider.ts b/public/app/plugins/datasource/tempo/language_provider.ts index 556c51e9114..7b9f0c1e2a3 100644 --- a/public/app/plugins/datasource/tempo/language_provider.ts +++ b/public/app/plugins/datasource/tempo/language_provider.ts @@ -37,7 +37,10 @@ export default class TempoLanguageProvider extends LanguageProvider { if (!value) { return emptyResult; } - if (text === '=') { + + const query = value.endText.getText(); + const isValue = query[query.indexOf(text) - 1] === '='; + if (isValue || text === '=') { return this.getTagValueCompletionItems(value); } return this.getTagsCompletionItems(); @@ -58,19 +61,17 @@ export default class TempoLanguageProvider extends LanguageProvider { }; async getTagValueCompletionItems(value: Value) { - const tagNames = value.endText.getText().split(' '); - let tagName = tagNames[0]; - // Get last item if multiple tags - if (tagNames.length > 1) { - tagName = tagNames[tagNames.length - 1]; - } - tagName = tagName.slice(0, -1); + const tags = value.endText.getText().split(' '); + + let tagName = tags[tags.length - 1] ?? ''; + tagName = tagName.split('=')[0]; + const response = await this.request(`/api/search/tag/${tagName}/values`, []); const suggestions: CompletionItemGroup[] = []; if (response && response.tagValues) { suggestions.push({ - label: `TagValues`, + label: `Tag Values`, items: response.tagValues.map((tagValue: string) => ({ label: tagValue })), }); }