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