Commit e67d3df1 by Simon Podlipsky

Fix array display from url

parent abbb6f93
......@@ -76,8 +76,8 @@ describe('VariableSrv init', function(this: any) {
{
name: 'apps',
type: type,
current: { text: 'test', value: 'test' },
options: [{ text: 'test', value: 'test' }],
current: { text: 'Test', value: 'test' },
options: [{ text: 'Test', value: 'test' }],
},
];
scenario.urlParams['var-apps'] = 'new';
......@@ -160,11 +160,11 @@ describe('VariableSrv init', function(this: any) {
name: 'apps',
type: 'query',
multi: true,
current: { text: 'val1', value: 'val1' },
current: { text: 'Val1', value: 'val1' },
options: [
{ text: 'val1', value: 'val1' },
{ text: 'val2', value: 'val2' },
{ text: 'val3', value: 'val3', selected: true },
{ text: 'Val1', value: 'val1' },
{ text: 'Val2', value: 'val2' },
{ text: 'Val3', value: 'val3', selected: true },
],
},
];
......@@ -176,7 +176,7 @@ describe('VariableSrv init', function(this: any) {
expect(variable.current.value.length).toBe(2);
expect(variable.current.value[0]).toBe('val2');
expect(variable.current.value[1]).toBe('val1');
expect(variable.current.text).toBe('val2 + val1');
expect(variable.current.text).toBe('Val2 + Val1');
expect(variable.options[0].selected).toBe(true);
expect(variable.options[1].selected).toBe(true);
});
......@@ -187,6 +187,30 @@ describe('VariableSrv init', function(this: any) {
});
});
describeInitScenario(
'when template variable is present in url multiple times and variables have no text',
scenario => {
scenario.setup(() => {
scenario.variables = [
{
name: 'apps',
type: 'query',
multi: true,
},
];
scenario.urlParams['var-apps'] = ['val1', 'val2'];
});
it('should display concatenated values in text', () => {
const variable = ctx.variableSrv.variables[0];
expect(variable.current.value.length).toBe(2);
expect(variable.current.value[0]).toBe('val1');
expect(variable.current.value[1]).toBe('val2');
expect(variable.current.text).toBe('val1 + val2');
});
}
);
describeInitScenario('when template variable is present in url multiple times using key/values', scenario => {
scenario.setup(() => {
scenario.variables = [
......
......@@ -236,8 +236,10 @@ export class VariableSrv {
setOptionAsCurrent(variable, option) {
variable.current = _.cloneDeep(option);
if (_.isArray(variable.current.text)) {
if (_.isArray(variable.current.text) && variable.current.text.length > 0) {
variable.current.text = variable.current.text.join(' + ');
} else if (_.isArray(variable.current.value) && variable.current.value[0] !== '$__all') {
variable.current.text = variable.current.value.join(' + ');
}
this.selectOptionsForCurrentValue(variable);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment