GraphMigrations.ts 705 B

123456789101112131415161718192021222324
  1. import { PanelModel, FieldConfigSource, DataLink } from '@grafana/data';
  2. /**
  3. * Called when upgrading from a previously saved versoin
  4. */
  5. export const graphPanelMigrationHandler = (panel: PanelModel<any>): Partial<any> => {
  6. const fieldConfig: FieldConfigSource = panel.fieldConfig ?? {
  7. defaults: {},
  8. overrides: [],
  9. };
  10. const options = panel.options || {};
  11. // Move <7.1 dataLinks to the field section
  12. if (options.dataLinks) {
  13. fieldConfig.defaults.links = options.dataLinks as DataLink[];
  14. delete options.dataLinks;
  15. }
  16. // Mutate the original panel state (only necessary because it is angular)
  17. panel.options = options;
  18. panel.fieldConfig = fieldConfig;
  19. return options;
  20. };