mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: DataLinks from data sources override user defined data link (#65996)
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
parent
232834f455
commit
9041e7dfa6
@ -415,6 +415,124 @@ describe('setFieldConfigDefaults', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('applies field config defaults correctly when links property exist in field config and no links are defined in panel', () => {
|
||||
const dsFieldConfig: FieldConfig = {
|
||||
links: [
|
||||
{
|
||||
title: 'Google link',
|
||||
url: 'https://google.com',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const panelFieldConfig: FieldConfig = {};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
|
||||
// we mutate dsFieldConfig
|
||||
// @ts-ignore
|
||||
setFieldConfigDefaults(dsFieldConfig, panelFieldConfig, context);
|
||||
|
||||
expect(dsFieldConfig).toMatchInlineSnapshot(`
|
||||
{
|
||||
"custom": {},
|
||||
"links": [
|
||||
{
|
||||
"title": "Google link",
|
||||
"url": "https://google.com",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('applies field config defaults correctly when links property exist in panel config and no links are defined in ds field config', () => {
|
||||
const dsFieldConfig: FieldConfig = {};
|
||||
|
||||
const panelFieldConfig: FieldConfig = {
|
||||
links: [
|
||||
{
|
||||
title: 'Google link',
|
||||
url: 'https://google.com',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
|
||||
// we mutate dsFieldConfig
|
||||
// @ts-ignore
|
||||
setFieldConfigDefaults(dsFieldConfig, panelFieldConfig, context);
|
||||
|
||||
expect(dsFieldConfig).toMatchInlineSnapshot(`
|
||||
{
|
||||
"custom": {},
|
||||
"links": [
|
||||
{
|
||||
"title": "Google link",
|
||||
"url": "https://google.com",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('applies a merge strategy for links when they exist in ds config and panel', () => {
|
||||
const dsFieldConfig: FieldConfig = {
|
||||
links: [
|
||||
{
|
||||
title: 'Google link',
|
||||
url: 'https://google.com',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const panelFieldConfig: FieldConfig = {
|
||||
links: [
|
||||
{
|
||||
title: 'Grafana',
|
||||
url: 'https://grafana.com',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const context: FieldOverrideEnv = {
|
||||
data: [],
|
||||
field: { type: FieldType.number } as Field,
|
||||
dataFrameIndex: 0,
|
||||
fieldConfigRegistry: customFieldRegistry,
|
||||
};
|
||||
|
||||
// we mutate dsFieldConfig
|
||||
setFieldConfigDefaults(dsFieldConfig, panelFieldConfig, context);
|
||||
|
||||
expect(dsFieldConfig).toMatchInlineSnapshot(`
|
||||
{
|
||||
"custom": {},
|
||||
"links": [
|
||||
{
|
||||
"title": "Google link",
|
||||
"url": "https://google.com",
|
||||
},
|
||||
{
|
||||
"title": "Grafana",
|
||||
"url": "https://grafana.com",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setDynamicConfigValue', () => {
|
||||
|
@ -289,6 +289,11 @@ export function setDynamicConfigValue(config: FieldConfig, value: DynamicConfigV
|
||||
// config -> from DS
|
||||
// defaults -> from Panel config
|
||||
export function setFieldConfigDefaults(config: FieldConfig, defaults: FieldConfig, context: FieldOverrideEnv) {
|
||||
// For cases where we have links on the datasource config and the panel config, we need to merge them
|
||||
if (config.links && defaults.links) {
|
||||
// Combine the data source links and the panel default config links
|
||||
config.links = [...config.links, ...defaults.links];
|
||||
}
|
||||
for (const fieldConfigProperty of context.fieldConfigRegistry.list()) {
|
||||
if (fieldConfigProperty.isCustom && !config.custom) {
|
||||
config.custom = {};
|
||||
|
Loading…
Reference in New Issue
Block a user