mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Correctly display __text in multi-values variable (#17840)
Fixes #17839: __value is displayed instead of __text when single item is selected
This commit is contained in:
committed by
Torkel Ödegaard
parent
0833f26b43
commit
d94bdb930f
@@ -601,7 +601,7 @@ describe('VariableSrv', function(this: any) {
|
|||||||
it('sets single value as array if multi choice', async () => {
|
it('sets single value as array if multi choice', async () => {
|
||||||
const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx, { multi: true });
|
const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx, { multi: true });
|
||||||
await setFromUrl('one');
|
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 () => {
|
it('sets both text and value as array if multiple values in url', async () => {
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ export class VariableSrv {
|
|||||||
if (variable.multi) {
|
if (variable.multi) {
|
||||||
// In case variable is multiple choice, we cast to array to preserve the same behaviour as when selecting
|
// 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.
|
// 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);
|
return variable.setValue(option);
|
||||||
|
|||||||
Reference in New Issue
Block a user