grafana/public/app/plugins/panel/text/textPanelMigrationHandler.ts
sam boyer 33fd83f7e3
kindsys: Adapt to new PanelCfg schema interface (#65297)
* kindsys: Adapt to new PanelCfg schema interface

* building locally

* Remove Panel prefix in cue files

* Regenerate

* Update imports

* fixup! Merge branch 'remove-panel-prefix' into sdboyer/redundant-panelcfg-prefixes

* Fix formatting

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Tania B <yalyna.ts@gmail.com>
2023-05-15 23:07:54 -04:00

31 lines
997 B
TypeScript

import { PanelModel } from '@grafana/data';
import { TextMode, Options } from './panelcfg.gen';
export const textPanelMigrationHandler = (panel: PanelModel<Options>): Partial<Options> => {
const previousVersion = parseFloat(panel.pluginVersion || '6.1');
let options = panel.options;
// Migrates old Angular based text panel props to new props
if (panel.hasOwnProperty('content') && panel.hasOwnProperty('mode')) {
const oldTextPanel: any = panel as any;
const content = oldTextPanel.content;
const mode = oldTextPanel.mode as TextMode;
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
const modes = [TextMode.Code, TextMode.HTML, TextMode.Markdown];
if (!modes.find((f) => f === options.mode)) {
options = { ...options, mode: TextMode.Markdown };
}
return options;
};