mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
save as should only delete threshold for panels with alerts
closes #9681
This commit is contained in:
@@ -49,7 +49,10 @@ export class SaveDashboardAsModalCtrl {
|
||||
if (dashboard.id > 0) {
|
||||
this.clone.rows.forEach(row => {
|
||||
row.panels.forEach(panel => {
|
||||
if (panel.type === "graph" && panel.alert) {
|
||||
delete panel.thresholds;
|
||||
}
|
||||
|
||||
delete panel.alert;
|
||||
});
|
||||
});
|
||||
|
||||
67
public/app/features/dashboard/specs/save_as_modal.jest.ts
Normal file
67
public/app/features/dashboard/specs/save_as_modal.jest.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import {SaveDashboardAsModalCtrl} from '../save_as_modal';
|
||||
import {describe, expect} from 'test/lib/common';
|
||||
|
||||
describe('saving dashboard as', () => {
|
||||
function scenario(name, panel, verify) {
|
||||
describe(name, () => {
|
||||
var json = {
|
||||
title: "name",
|
||||
rows: [ { panels: [
|
||||
panel
|
||||
]}]
|
||||
};
|
||||
|
||||
var mockDashboardSrv = {
|
||||
getCurrent: function() {
|
||||
return {
|
||||
id: 5,
|
||||
getSaveModelClone: function() {
|
||||
return json;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var ctrl = new SaveDashboardAsModalCtrl(mockDashboardSrv);
|
||||
var ctx: any = {
|
||||
clone: ctrl.clone,
|
||||
ctrl: ctrl,
|
||||
panel: {}
|
||||
};
|
||||
for (let row of ctrl.clone.rows) {
|
||||
for (let panel of row.panels) {
|
||||
ctx.panel = panel;
|
||||
}
|
||||
}
|
||||
it("verify", () => {
|
||||
verify(ctx);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
scenario("default values", {}, (ctx) => {
|
||||
var clone = ctx.clone;
|
||||
expect(clone.id).toBe(null);
|
||||
expect(clone.title).toBe("name Copy");
|
||||
expect(clone.editable).toBe(true);
|
||||
expect(clone.hideControls).toBe(false);
|
||||
});
|
||||
|
||||
var graphPanel = { id: 1, type: "graph", alert: { rule: 1}, thresholds: { value: 3000} };
|
||||
|
||||
scenario("should remove alert from graph panel", graphPanel , (ctx) => {
|
||||
expect(ctx.panel.alert).toBe(undefined);
|
||||
});
|
||||
|
||||
scenario("should remove threshold from graph panel", graphPanel, (ctx) => {
|
||||
expect(ctx.panel.thresholds).toBe(undefined);
|
||||
});
|
||||
|
||||
scenario("singlestat should keep threshold", { id: 1, type: "singlestat", thresholds: { value: 3000} }, (ctx) => {
|
||||
expect(ctx.panel.thresholds).not.toBe(undefined);
|
||||
});
|
||||
|
||||
scenario("table should keep threshold", { id: 1, type: "table", thresholds: { value: 3000} }, (ctx) => {
|
||||
expect(ctx.panel.thresholds).not.toBe(undefined);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user