triggers: fix adding new panel
This commit is contained in:
@@ -6,6 +6,7 @@ export const CURRENT_SCHEMA_VERSION = 5;
|
||||
|
||||
export function migratePanelSchema(panel) {
|
||||
if (isEmptyPanel(panel)) {
|
||||
delete panel.targets;
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -47,5 +48,9 @@ function getSchemaVersion(panel) {
|
||||
}
|
||||
|
||||
function isEmptyPanel(panel) {
|
||||
return !panel.datasource && !panel.datasources && !panel.triggers && !panel.targets;
|
||||
return !panel.datasource && !panel.datasources && !panel.triggers && isEmptyTargets(panel.targets);
|
||||
}
|
||||
|
||||
function isEmptyTargets(targets) {
|
||||
return !targets || (_.isArray(targets) && (targets.length === 0 || targets.length === 1 && _.isEmpty(targets[0])));
|
||||
}
|
||||
|
||||
@@ -74,4 +74,20 @@ describe('Triggers Panel schema migration', () => {
|
||||
}, PANEL_DEFAULTS);
|
||||
expect(updatedPanelCtrl.panel).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should set default targets for new panel with empty targets', () => {
|
||||
ctx.scope.panel = {
|
||||
targets: [{}]
|
||||
};
|
||||
let updatedPanelCtrl = new TriggerPanelCtrl(ctx.scope, {}, timeoutMock, datasourceSrvMock, {}, {}, {});
|
||||
|
||||
let expected = _.defaultsDeep({
|
||||
datasources: ['zabbix_default'],
|
||||
targets: {
|
||||
'zabbix_default': DEFAULT_TARGET
|
||||
},
|
||||
}, PANEL_DEFAULTS);
|
||||
|
||||
expect(updatedPanelCtrl.panel).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user