mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
add defaults to alert list migration handler (#36547)
This commit is contained in:
parent
f308ba91e3
commit
27b7c35ccc
@ -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<PanelModel, 'fieldConfig'> & Record<string, any> = {
|
||||
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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,21 +1,22 @@
|
||||
import { PanelModel } from '@grafana/data';
|
||||
import { AlertListOptions } from './types';
|
||||
import { AlertListOptions, ShowOption, SortOrder } from './types';
|
||||
|
||||
export const alertListPanelMigrationHandler = (
|
||||
panel: PanelModel<AlertListOptions> & Record<string, any>
|
||||
): Partial<AlertListOptions> => {
|
||||
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');
|
||||
|
Loading…
Reference in New Issue
Block a user