do not allow registation of undefined indexpatterns in dashboard state (#12628)

This commit is contained in:
Nathan Reese 2017-07-05 16:40:11 -06:00 committed by GitHub
parent 580e0d2964
commit 4bb759cde2
2 changed files with 25 additions and 1 deletions

View file

@ -11,6 +11,7 @@ describe('DashboardState', function () {
let timefilter;
let quickTimeRanges;
let dashboardConfig;
const mockIndexPattern = { id: 'index1' };
function initDashboardState() {
dashboardState = new DashboardState(savedDashboard, AppState, dashboardConfig);
@ -78,4 +79,25 @@ describe('DashboardState', function () {
expect(timefilter.time.from).to.equal(savedDashboard.timeFrom);
});
});
describe('panelIndexPatternMapping', function () {
it('registers index pattern', function () {
const state = new DashboardState(savedDashboard, AppState, dashboardConfig);
state.registerPanelIndexPatternMap('panel1', mockIndexPattern);
expect(state.getPanelIndexPatterns().length).to.equal(1);
});
it('registers unique index patterns', function () {
const state = new DashboardState(savedDashboard, AppState, dashboardConfig);
state.registerPanelIndexPatternMap('panel1', mockIndexPattern);
state.registerPanelIndexPatternMap('panel2', mockIndexPattern);
expect(state.getPanelIndexPatterns().length).to.equal(1);
});
it('does not register undefined index pattern for panels with no index pattern', function () {
const state = new DashboardState(savedDashboard, AppState, dashboardConfig);
state.registerPanelIndexPatternMap('markdownPanel1', undefined);
expect(state.getPanelIndexPatterns().length).to.equal(0);
});
});
});

View file

@ -94,7 +94,9 @@ export class DashboardState {
}
registerPanelIndexPatternMap(panelIndex, indexPattern) {
this.panelIndexPatternMapping[panelIndex] = indexPattern;
if (indexPattern) {
this.panelIndexPatternMapping[panelIndex] = indexPattern;
}
}
getPanelIndexPatterns() {