textPanelMigrationHandler.ts 959 B

1234567891011121314151617181920212223242526272829
  1. import { PanelModel } from '@grafana/data';
  2. import { TextMode, PanelOptions } from './models.gen';
  3. export const textPanelMigrationHandler = (panel: PanelModel<PanelOptions>): Partial<PanelOptions> => {
  4. const previousVersion = parseFloat(panel.pluginVersion || '6.1');
  5. let options = panel.options;
  6. // Migrates old Angular based text panel props to new props
  7. if (panel.hasOwnProperty('content') && panel.hasOwnProperty('mode')) {
  8. const oldTextPanel: any = panel as any;
  9. const content = oldTextPanel.content;
  10. const mode = oldTextPanel.mode as TextMode;
  11. delete oldTextPanel.content;
  12. delete oldTextPanel.mode;
  13. if (previousVersion < 7.1) {
  14. options = { content, mode };
  15. }
  16. }
  17. // The 'text' mode has been removed so we need to update any panels still using it to markdown
  18. if (options.mode !== 'html' && options.mode !== 'markdown') {
  19. options = { ...options, mode: TextMode.Markdown };
  20. }
  21. return options;
  22. };