GaugeMigrations.ts 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import { PanelModel } from '@grafana/data';
  2. import { sharedSingleStatPanelChangedHandler, sharedSingleStatMigrationHandler } from '@grafana/ui';
  3. import { GaugeOptions } from './types';
  4. // This is called when the panel first loads
  5. export const gaugePanelMigrationHandler = (panel: PanelModel<GaugeOptions>): Partial<GaugeOptions> => {
  6. return sharedSingleStatMigrationHandler(panel);
  7. };
  8. // This is called when the panel changes from another panel
  9. export const gaugePanelChangedHandler = (
  10. panel: PanelModel<Partial<GaugeOptions>> | any,
  11. prevPluginId: string,
  12. prevOptions: any
  13. ) => {
  14. // This handles most config changes
  15. const opts = sharedSingleStatPanelChangedHandler(panel, prevPluginId, prevOptions) as GaugeOptions;
  16. // Changing from angular singlestat
  17. if (prevPluginId === 'singlestat' && prevOptions.angular) {
  18. const gauge = prevOptions.angular.gauge;
  19. if (gauge) {
  20. opts.showThresholdMarkers = gauge.thresholdMarkers;
  21. opts.showThresholdLabels = gauge.thresholdLabels;
  22. }
  23. }
  24. return opts;
  25. };