From d94bdb930f3772d118970b477682a0c877185077 Mon Sep 17 00:00:00 2001 From: Eduard Sergeev Date: Mon, 1 Jul 2019 17:42:36 +1000 Subject: [PATCH] Templating: Correctly display __text in multi-values variable (#17840) Fixes #17839: __value is displayed instead of __text when single item is selected --- public/app/features/templating/specs/variable_srv.test.ts | 2 +- public/app/features/templating/variable_srv.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/features/templating/specs/variable_srv.test.ts b/public/app/features/templating/specs/variable_srv.test.ts index 1dcaa242dfe..b9ab0bd887f 100644 --- a/public/app/features/templating/specs/variable_srv.test.ts +++ b/public/app/features/templating/specs/variable_srv.test.ts @@ -601,7 +601,7 @@ describe('VariableSrv', function(this: any) { it('sets single value as array if multi choice', async () => { const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx, { multi: true }); await setFromUrl('one'); - expect(setValueMock).toHaveBeenCalledWith({ text: 'one', value: ['one'] }); + expect(setValueMock).toHaveBeenCalledWith({ text: ['one'], value: ['one'] }); }); it('sets both text and value as array if multiple values in url', async () => { diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index d33e100f276..784e9c1ebd1 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -261,7 +261,7 @@ export class VariableSrv { if (variable.multi) { // In case variable is multiple choice, we cast to array to preserve the same behaviour as when selecting // the option directly, which will return even single value in an array. - option = { ...option, value: _.castArray(option.value) }; + option = { text: _.castArray(option.text), value: _.castArray(option.value) }; } return variable.setValue(option);