mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graph: Preseve existing data links in field config when loading dashboard (#27295)
* Graph: Preseve existing data links in field config * ts fix
This commit is contained in:
parent
06323b8e52
commit
4b8f4df18d
@ -203,6 +203,7 @@ export class PanelModel implements DataConfigSource {
|
||||
getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
getFieldConfig() {
|
||||
return this.fieldConfig;
|
||||
}
|
||||
@ -309,6 +310,7 @@ export class PanelModel implements DataConfigSource {
|
||||
if (plugin.angularConfigCtrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.options = _.mergeWith({}, plugin.defaults, this.options || {}, (objValue: any, srcValue: any): any => {
|
||||
if (_.isArray(srcValue)) {
|
||||
return srcValue;
|
||||
|
@ -126,4 +126,25 @@ describe('Graph Panel Migrations', () => {
|
||||
const link = fieldSource.defaults.links![0];
|
||||
expect(link.url).toEqual('THE DRILLDOWN URL');
|
||||
});
|
||||
|
||||
it('from 7.1 it should preserve existing fieldConfig', () => {
|
||||
const panel = ({
|
||||
id: 1,
|
||||
fieldConfig: {
|
||||
defaults: {
|
||||
links: [
|
||||
{
|
||||
title: 'Details',
|
||||
url: '/link',
|
||||
},
|
||||
],
|
||||
},
|
||||
overrides: [],
|
||||
},
|
||||
} as unknown) as PanelModel;
|
||||
|
||||
graphPanelMigrationHandler(panel as PanelModel);
|
||||
const fieldConfig = (panel as any).fieldConfig as FieldConfigSource;
|
||||
expect(fieldConfig.defaults.links).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ import { PanelModel, FieldConfigSource, DataLink } from '@grafana/data';
|
||||
* Called when upgrading from a previously saved versoin
|
||||
*/
|
||||
export const graphPanelMigrationHandler = (panel: PanelModel<any>): Partial<any> => {
|
||||
const fieldOptions: FieldConfigSource = {
|
||||
const fieldConfig: FieldConfigSource = panel.fieldConfig ?? {
|
||||
defaults: {},
|
||||
overrides: [],
|
||||
};
|
||||
@ -13,12 +13,12 @@ export const graphPanelMigrationHandler = (panel: PanelModel<any>): Partial<any>
|
||||
|
||||
// Move <7.1 dataLinks to the field section
|
||||
if (options.dataLinks) {
|
||||
fieldOptions.defaults.links = options.dataLinks as DataLink[];
|
||||
fieldConfig.defaults.links = options.dataLinks as DataLink[];
|
||||
delete options.dataLinks;
|
||||
}
|
||||
|
||||
// Mutate the original panel state (only necessary because it is angular)
|
||||
panel.options = options;
|
||||
panel.fieldConfig = fieldOptions;
|
||||
panel.fieldConfig = fieldConfig;
|
||||
return options;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user