2020-06-10 14:35:30 +02:00
|
|
|
import { PanelModel } from '@grafana/data';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2023-05-15 23:07:54 -04:00
|
|
|
import { TextMode, Options } from './panelcfg.gen';
|
2020-06-10 14:35:30 +02:00
|
|
|
|
2023-05-15 23:07:54 -04:00
|
|
|
export const textPanelMigrationHandler = (panel: PanelModel<Options>): Partial<Options> => {
|
2020-10-30 08:22:04 +01:00
|
|
|
const previousVersion = parseFloat(panel.pluginVersion || '6.1');
|
|
|
|
|
let options = panel.options;
|
|
|
|
|
|
2020-06-10 14:35:30 +02:00
|
|
|
// Migrates old Angular based text panel props to new props
|
|
|
|
|
if (panel.hasOwnProperty('content') && panel.hasOwnProperty('mode')) {
|
2020-10-30 08:22:04 +01:00
|
|
|
const oldTextPanel: any = panel as any;
|
2020-06-10 14:35:30 +02:00
|
|
|
const content = oldTextPanel.content;
|
2020-10-30 08:22:04 +01:00
|
|
|
const mode = oldTextPanel.mode as TextMode;
|
|
|
|
|
|
|
|
|
|
delete oldTextPanel.content;
|
|
|
|
|
delete oldTextPanel.mode;
|
2020-06-10 14:35:30 +02:00
|
|
|
|
2020-10-30 08:22:04 +01:00
|
|
|
if (previousVersion < 7.1) {
|
|
|
|
|
options = { content, mode };
|
|
|
|
|
}
|
2020-06-10 14:35:30 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-09 21:38:22 -07:00
|
|
|
// The 'text' mode has been removed so we need to update any panels still using it to markdown
|
2022-09-02 15:38:35 -07:00
|
|
|
const modes = [TextMode.Code, TextMode.HTML, TextMode.Markdown];
|
|
|
|
|
if (!modes.find((f) => f === options.mode)) {
|
2021-04-29 20:12:37 -07:00
|
|
|
options = { ...options, mode: TextMode.Markdown };
|
2020-06-15 10:17:46 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-30 08:22:04 +01:00
|
|
|
return options;
|
2020-06-10 14:35:30 +02:00
|
|
|
};
|