From 240e65f69300bce3bf5f536ded40b01cc8cd4152 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Mon, 15 Mar 2021 14:11:43 +0100 Subject: [PATCH] Loki: Fix autocomplete when re-editing Loki label values (#31828) * Allow re-editing of labels in Loki queries * Update public/app/plugins/datasource/loki/language_provider.ts --- .../datasource/loki/language_provider.test.ts | 19 +++++++++++++++++++ .../datasource/loki/language_provider.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/loki/language_provider.test.ts b/public/app/plugins/datasource/loki/language_provider.test.ts index 7def3786888..9eb3c234390 100644 --- a/public/app/plugins/datasource/loki/language_provider.test.ts +++ b/public/app/plugins/datasource/loki/language_provider.test.ts @@ -167,6 +167,25 @@ describe('Language completion provider', () => { }, ]); }); + it('returns label values suggestions from Loki when re-editing', async () => { + const datasource = makeMockLokiDatasource({ label1: ['label1_val1', 'label1_val2'], label2: [] }); + const provider = await getLanguageProvider(datasource); + const input = createTypeaheadInput('{label1="label1_v"}', 'label1_v', 'label1', 17, [ + 'attr-value', + 'context-labels', + ]); + let result = await provider.provideCompletionItems(input); + expect(result.context).toBe('context-label-values'); + expect(result.suggestions).toEqual([ + { + items: [ + { label: 'label1_val1', filterText: '"label1_val1"' }, + { label: 'label1_val2', filterText: '"label1_val2"' }, + ], + label: 'Label values for "label1"', + }, + ]); + }); }); describe('label values', () => { diff --git a/public/app/plugins/datasource/loki/language_provider.ts b/public/app/plugins/datasource/loki/language_provider.ts index 57f516a7b11..fc2e720ccd6 100644 --- a/public/app/plugins/datasource/loki/language_provider.ts +++ b/public/app/plugins/datasource/loki/language_provider.ts @@ -280,7 +280,7 @@ export default class LokiLanguageProvider extends LanguageProvider { selector = EMPTY_SELECTOR; } - if (!isValueStart && selector === EMPTY_SELECTOR) { + if (!labelKey && selector === EMPTY_SELECTOR) { // start task gets all labels await this.start(); const allLabels = this.getLabelKeys();