diff --git a/public/app/plugins/panel/alertlist/AlertListMigration.test.ts b/public/app/plugins/panel/alertlist/AlertListMigration.test.ts index 45301afe55b..886d405867a 100644 --- a/public/app/plugins/panel/alertlist/AlertListMigration.test.ts +++ b/public/app/plugins/panel/alertlist/AlertListMigration.test.ts @@ -107,4 +107,30 @@ describe('AlertList Panel Migration', () => { expect(panel).not.toHaveProperty('dashboardTags'); expect(panel).not.toHaveProperty('stateFilter'); }); + + it('should handle config with no options or stateFilter', () => { + const panel: Omit & Record = { + id: 7, + links: [], + pluginVersion: '7.4.0', + targets: [], + title: 'Usage', + type: 'alertlist', + onlyAlertsOnDashboard: false, + options: {}, + }; + + const newOptions = alertListPanelMigrationHandler(panel as PanelModel); + expect(newOptions).toMatchObject({ + showOptions: ShowOption.Current, + maxItems: 10, + sortOrder: SortOrder.AlphaAsc, + dashboardAlerts: false, + alertName: '', + dashboardTitle: '', + tags: [], + stateFilter: {}, + folderId: undefined, + }); + }); }); diff --git a/public/app/plugins/panel/alertlist/AlertListMigrationHandler.ts b/public/app/plugins/panel/alertlist/AlertListMigrationHandler.ts index 2dd52edb08f..5c6ba77c527 100644 --- a/public/app/plugins/panel/alertlist/AlertListMigrationHandler.ts +++ b/public/app/plugins/panel/alertlist/AlertListMigrationHandler.ts @@ -1,21 +1,22 @@ import { PanelModel } from '@grafana/data'; -import { AlertListOptions } from './types'; +import { AlertListOptions, ShowOption, SortOrder } from './types'; export const alertListPanelMigrationHandler = ( panel: PanelModel & Record ): Partial => { const newOptions: AlertListOptions = { - showOptions: panel.options.showOptions ?? panel.show, - maxItems: panel.options.maxItems ?? panel.limit, - sortOrder: panel.options.sortOrder ?? panel.sortOrder, - dashboardAlerts: panel.options.dashboardAlerts ?? panel.onlyAlertsOnDashboard, - alertName: panel.options.alertName ?? panel.nameFilter, - dashboardTitle: panel.options.dashboardTitle ?? panel.dashboardFilter, + showOptions: panel.options.showOptions ?? panel.show ?? ShowOption.Current, + maxItems: panel.options.maxItems ?? panel.limit ?? 10, + sortOrder: panel.options.sortOrder ?? panel.sortOrder ?? SortOrder.AlphaAsc, + dashboardAlerts: panel.options.dashboardAlerts ?? panel.onlyAlertsOnDashboard ?? false, + alertName: panel.options.alertName ?? panel.nameFilter ?? '', + dashboardTitle: panel.options.dashboardTitle ?? panel.dashboardFilter ?? '', folderId: panel.options.folderId ?? panel.folderId, - tags: panel.options.tags ?? panel.dashboardTags, + tags: panel.options.tags ?? panel.dashboardTags ?? [], stateFilter: panel.options.stateFilter ?? - panel.stateFilter.reduce((filterObj: any, curFilter: any) => ({ ...filterObj, [curFilter]: true }), {}), + panel.stateFilter?.reduce((filterObj: any, curFilter: any) => ({ ...filterObj, [curFilter]: true }), {}) ?? + {}, }; const previousVersion = parseFloat(panel.pluginVersion || '7.4');