fix(): fix for cleaning up repeat panel scope for orphaned panels or duplicated panels

This commit is contained in:
Torkel Ödegaard 2015-08-04 15:15:03 +02:00
parent 0586dbaf8b
commit 775a805959
4 changed files with 20 additions and 1 deletions

View File

@ -174,6 +174,11 @@ function (angular, $, kbn, _, moment) {
var newPanel = angular.copy(panel);
newPanel.id = this.getNextPanelId();
delete newPanel.repeat;
delete newPanel.repeatIteration;
delete newPanel.repeatPanelId;
delete newPanel.scopedVars;
var currentRow = this.rows[rowIndex];
currentRow.panels.push(newPanel);
return newPanel;

View File

@ -53,6 +53,10 @@ function (angular, _) {
row.panels = _.without(row.panels, panel);
j = j - 1;
}
// clean up left over scoped vars
else if (panel.scopedVars && panel.repeatIteration !== this.iteration) {
delete panel.scopedVars;
}
}
}
};
@ -116,6 +120,7 @@ function (angular, _) {
panel = copy.panels[i];
panel.scopedVars = {};
panel.scopedVars[variable.name] = option;
panel.repeatIteration = self.iteration;
}
});
};

View File

@ -136,7 +136,7 @@ function (angular, _, InfluxQueryBuilder) {
$scope.addTemplateVariableSegments = function(segments) {
_.each(templateSrv.variables, function(variable) {
segments.unshift(new MetricSegment({ type: 'template', value: '$' + variable.name, expandable: true }));
segments.unshift(new MetricSegment({ type: 'template', value: '/$' + variable.name + '/', expandable: true }));
});
return segments;
};

View File

@ -81,6 +81,15 @@ define([
expect(dashboard.rows[0].panels[1].id).to.be(11);
});
it('duplicate panel should remove repeat data', function() {
var panel = { span: 4, attr: '123', id: 10, repeat: 'asd', scopedVars: { test: 'asd' }};
dashboard.rows = [{ panels: [panel] }];
dashboard.duplicatePanel(panel, dashboard.rows[0]);
expect(dashboard.rows[0].panels[1].repeat).to.be(null);
expect(dashboard.rows[0].panels[1].scopedVars.test).to.be(undefined);
});
});
describe('when creating dashboard with editable false', function() {