Commit ad870c07 by Dominik Prokop Committed by GitHub

DataLinks: Bring back variables interpolation in title (#24970)

parent 8c1307e7
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
setFieldConfigDefaults, setFieldConfigDefaults,
setDynamicConfigValue, setDynamicConfigValue,
applyFieldOverrides, applyFieldOverrides,
getLinksSupplier,
} from './fieldOverrides'; } from './fieldOverrides';
import { MutableDataFrame, toDataFrame } from '../dataframe'; import { MutableDataFrame, toDataFrame } from '../dataframe';
import { import {
...@@ -20,7 +21,7 @@ import { mockStandardProperties } from '../utils/tests/mockStandardProperties'; ...@@ -20,7 +21,7 @@ import { mockStandardProperties } from '../utils/tests/mockStandardProperties';
import { FieldMatcherID } from '../transformations'; import { FieldMatcherID } from '../transformations';
import { FieldConfigOptionsRegistry } from './FieldConfigOptionsRegistry'; import { FieldConfigOptionsRegistry } from './FieldConfigOptionsRegistry';
import { getFieldDisplayName } from './fieldState'; import { getFieldDisplayName } from './fieldState';
import { locationUtil } from '../utils';
const property1 = { const property1 = {
id: 'custom.property1', // Match field properties id: 'custom.property1', // Match field properties
path: 'property1', // Match field properties path: 'property1', // Match field properties
...@@ -418,3 +419,40 @@ describe('setDynamicConfigValue', () => { ...@@ -418,3 +419,40 @@ describe('setDynamicConfigValue', () => {
expect(config.displayName).toBeUndefined(); expect(config.displayName).toBeUndefined();
}); });
}); });
describe('getLinksSupplier', () => {
it('will replace variables in url and title of the data link', () => {
locationUtil.initialize({
getConfig: () => ({} as any),
buildParamsFromVariables: (() => {}) as any,
getTimeRangeForUrl: (() => {}) as any,
});
const f0 = new MutableDataFrame({
name: 'A',
fields: [
{
name: 'message',
type: FieldType.string,
values: [10, 20],
config: {
links: [
{
url: 'url to be interpolated',
title: 'title to be interpolated',
},
],
},
},
],
});
const replaceSpy = jest.fn();
const supplier = getLinksSupplier(f0, f0.fields[0], {}, replaceSpy, { theme: {} as GrafanaTheme });
supplier({});
expect(replaceSpy).toBeCalledTimes(2);
expect(replaceSpy.mock.calls[0][0]).toEqual('url to be interpolated');
expect(replaceSpy.mock.calls[1][0]).toEqual('title to be interpolated');
});
});
...@@ -343,7 +343,7 @@ export function validateFieldConfig(config: FieldConfig) { ...@@ -343,7 +343,7 @@ export function validateFieldConfig(config: FieldConfig) {
} }
} }
const getLinksSupplier = ( export const getLinksSupplier = (
frame: DataFrame, frame: DataFrame,
field: Field, field: Field,
fieldScopedVars: ScopedVars, fieldScopedVars: ScopedVars,
...@@ -366,7 +366,7 @@ const getLinksSupplier = ( ...@@ -366,7 +366,7 @@ const getLinksSupplier = (
const info: LinkModel<Field> = { const info: LinkModel<Field> = {
href: locationUtil.assureBaseUrl(href.replace(/\n/g, '')), href: locationUtil.assureBaseUrl(href.replace(/\n/g, '')),
title: replaceVariables(link.title || ''), title: link.title || '',
target: link.targetBlank ? '_blank' : '_self', target: link.targetBlank ? '_blank' : '_self',
origin: field, origin: field,
}; };
...@@ -402,7 +402,7 @@ const getLinksSupplier = ( ...@@ -402,7 +402,7 @@ const getLinksSupplier = (
} }
} }
info.href = replaceVariables(info.href, { const variables = {
...fieldScopedVars, ...fieldScopedVars,
__value: { __value: {
text: 'Value', text: 'Value',
...@@ -417,8 +417,10 @@ const getLinksSupplier = ( ...@@ -417,8 +417,10 @@ const getLinksSupplier = (
text: variablesQuery, text: variablesQuery,
value: variablesQuery, value: variablesQuery,
}, },
}); };
info.href = replaceVariables(info.href, variables);
info.title = replaceVariables(info.title, variables);
info.href = locationUtil.processUrl(info.href); info.href = locationUtil.processUrl(info.href);
return info; return info;
......
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