mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TextPanel: Fixes problems where text panel would show old content (#28643)
This commit is contained in:
parent
5a83fc574a
commit
16a1d2f744
@ -8,12 +8,30 @@ describe('textPanelMigrationHandler', () => {
|
|||||||
const panel: any = {
|
const panel: any = {
|
||||||
content: '<span>Hello World<span>',
|
content: '<span>Hello World<span>',
|
||||||
mode: 'html',
|
mode: 'html',
|
||||||
|
options: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = textPanelMigrationHandler(panel);
|
const result = textPanelMigrationHandler(panel);
|
||||||
|
|
||||||
expect(result.content).toEqual('<span>Hello World<span>');
|
expect(result.content).toEqual('<span>Hello World<span>');
|
||||||
expect(result.mode).toEqual('html');
|
expect(result.mode).toEqual('html');
|
||||||
|
expect(panel.content).toBeUndefined();
|
||||||
|
expect(panel.mode).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when invoked and previous version 7.1 or later', () => {
|
||||||
|
it('then not migrate options', () => {
|
||||||
|
const panel: any = {
|
||||||
|
content: '<span>Hello World<span>',
|
||||||
|
mode: 'html',
|
||||||
|
options: { content: 'New content' },
|
||||||
|
pluginVersion: '7.1.0',
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = textPanelMigrationHandler(panel);
|
||||||
|
|
||||||
|
expect(result.content).toEqual('New content');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,19 +2,27 @@ import { PanelModel } from '@grafana/data';
|
|||||||
import { TextMode, TextOptions } from './types';
|
import { TextMode, TextOptions } from './types';
|
||||||
|
|
||||||
export const textPanelMigrationHandler = (panel: PanelModel<TextOptions>): Partial<TextOptions> => {
|
export const textPanelMigrationHandler = (panel: PanelModel<TextOptions>): Partial<TextOptions> => {
|
||||||
|
const previousVersion = parseFloat(panel.pluginVersion || '6.1');
|
||||||
|
let options = panel.options;
|
||||||
|
|
||||||
// Migrates old Angular based text panel props to new props
|
// Migrates old Angular based text panel props to new props
|
||||||
if (panel.hasOwnProperty('content') && panel.hasOwnProperty('mode')) {
|
if (panel.hasOwnProperty('content') && panel.hasOwnProperty('mode')) {
|
||||||
const oldTextPanel: { content: string; mode: string } = (panel as unknown) as any;
|
const oldTextPanel: any = panel as any;
|
||||||
const content = oldTextPanel.content;
|
const content = oldTextPanel.content;
|
||||||
const mode = (oldTextPanel.mode as unknown) as TextMode;
|
const mode = oldTextPanel.mode as TextMode;
|
||||||
|
|
||||||
return { content, mode };
|
delete oldTextPanel.content;
|
||||||
|
delete oldTextPanel.mode;
|
||||||
|
|
||||||
|
if (previousVersion < 7.1) {
|
||||||
|
options = { content, mode };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The 'text' mode has been removed so we need to update any panels still using it to markdown
|
// The 'text' mode has been removed so we need to update any panels still using it to markdown
|
||||||
if (panel.options.mode !== 'html' && panel.options.mode !== 'markdown') {
|
if (options.mode !== 'html' && options.mode !== 'markdown') {
|
||||||
return { content: panel.options.content, mode: 'markdown' };
|
options = { ...options, mode: 'markdown' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return panel.options;
|
return options;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user