mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scenes: Add PDF tab in share modal (#85541)
This commit is contained in:
parent
03114e7602
commit
8e8bfae761
@ -1,4 +1,5 @@
|
||||
import { UrlQueryMap } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
|
||||
import { VariableRefresh } from './types';
|
||||
import {
|
||||
@ -7,9 +8,17 @@ import {
|
||||
findTemplateVarChanges,
|
||||
getCurrentText,
|
||||
getVariableRefresh,
|
||||
getVariablesFromUrl,
|
||||
isAllVariable,
|
||||
} from './utils';
|
||||
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
...jest.requireActual('@grafana/runtime'),
|
||||
getTemplateSrv: () => ({
|
||||
getVariables: () => [{ name: 'query0' }, { name: 'query1' }],
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('isAllVariable', () => {
|
||||
it.each`
|
||||
variable | expected
|
||||
@ -202,3 +211,22 @@ describe('containsVariable', () => {
|
||||
expect(containsVariable(value, 'var')).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getVariablesFromUrl', () => {
|
||||
it('when called with simple var values for a var, then it returns just the value', () => {
|
||||
locationService.push('/test?orgId=1&var-query0=1&var-query1=value1');
|
||||
const expected = {
|
||||
query0: '1',
|
||||
query1: 'value1',
|
||||
};
|
||||
expect(getVariablesFromUrl()).toEqual(expected);
|
||||
});
|
||||
it('when called with multiple var values for the same var, then it returns the correct array', () => {
|
||||
locationService.push('/test?orgId=1&var-query0=1&var-query1=value1&var-query1=value2&var-query1=value3');
|
||||
const expected = {
|
||||
query0: '1',
|
||||
query1: ['value1', 'value2', 'value3'],
|
||||
};
|
||||
expect(getVariablesFromUrl()).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
VariableWithOptions,
|
||||
QueryVariableModel,
|
||||
} from '@grafana/data';
|
||||
import { getTemplateSrv } from '@grafana/runtime';
|
||||
import { getTemplateSrv, locationService } from '@grafana/runtime';
|
||||
import { safeStringifyValue } from 'app/core/utils/explore';
|
||||
|
||||
import { getState } from '../../store/store';
|
||||
@ -292,3 +292,19 @@ export function toVariablePayload<T extends any = undefined>(
|
||||
): VariablePayload<T> {
|
||||
return { type: obj.type, id: obj.id, data: data as T };
|
||||
}
|
||||
|
||||
export function getVariablesFromUrl() {
|
||||
const variables = getTemplateSrv().getVariables();
|
||||
const queryParams = locationService.getSearchObject();
|
||||
|
||||
return Object.keys(queryParams)
|
||||
.filter(
|
||||
(key) => key.indexOf(VARIABLE_PREFIX) !== -1 && variables.some((v) => v.name === key.replace(VARIABLE_PREFIX, ''))
|
||||
)
|
||||
.reduce<UrlQueryMap>((obj, key) => {
|
||||
const variableName = key.replace(VARIABLE_PREFIX, '');
|
||||
obj[variableName] = queryParams[key];
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user