AlertListMigrationHandler.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { PanelModel } from '@grafana/data';
  2. import { AlertListOptions, ShowOption, SortOrder } from './types';
  3. export const alertListPanelMigrationHandler = (
  4. panel: PanelModel<AlertListOptions> & Record<string, any>
  5. ): Partial<AlertListOptions> => {
  6. const newOptions: AlertListOptions = {
  7. showOptions: panel.options.showOptions ?? panel.show ?? ShowOption.Current,
  8. maxItems: panel.options.maxItems ?? panel.limit ?? 10,
  9. sortOrder: panel.options.sortOrder ?? panel.sortOrder ?? SortOrder.AlphaAsc,
  10. dashboardAlerts: panel.options.dashboardAlerts ?? panel.onlyAlertsOnDashboard ?? false,
  11. alertName: panel.options.alertName ?? panel.nameFilter ?? '',
  12. dashboardTitle: panel.options.dashboardTitle ?? panel.dashboardFilter ?? '',
  13. folderId: panel.options.folderId ?? panel.folderId,
  14. tags: panel.options.tags ?? panel.dashboardTags ?? [],
  15. stateFilter:
  16. panel.options.stateFilter ??
  17. panel.stateFilter?.reduce((filterObj: any, curFilter: any) => ({ ...filterObj, [curFilter]: true }), {}) ??
  18. {},
  19. };
  20. const previousVersion = parseFloat(panel.pluginVersion || '7.4');
  21. if (previousVersion < 7.5) {
  22. const oldProps = [
  23. 'show',
  24. 'limit',
  25. 'sortOrder',
  26. 'onlyAlertsOnDashboard',
  27. 'nameFilter',
  28. 'dashboardFilter',
  29. 'folderId',
  30. 'dashboardTags',
  31. 'stateFilter',
  32. ];
  33. oldProps.forEach((prop) => delete panel[prop]);
  34. }
  35. return newOptions;
  36. };