From 1c8890fbd6a976f7da3d162784426556602c231c Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Thu, 21 Jul 2016 14:30:22 -0400 Subject: [PATCH] Fix filtering from visualizations The ability to create filters by clicking on visualizations was broken between 5.0 alpha3 and alpha4. The root cause was the addition of a new parameter being sent to all visualization event handlers, which was added to support persistence of tilemap position and zoom level. The filter_bar_click_handler (which enables the vis filtering behavior) already expected a different kind of second parameter, so the addition of this new parameter threw off the click handler's internal logic. It turns out that the new parameter is unnecessary, because the object it's passing is already available on the event object. So to fix this, I removed the new parameter from the emitter and updated the tilemap handlers to grab the object off of the event. Fixes: https://github.com/elastic/kibana/issues/7501 Related: https://github.com/elastic/kibana/pull/6835 (added the new param) Former-commit-id: 20cb910f563dfd0f7b30d63317ced57051e03230 --- .../kbn_vislib_vis_types/public/tile_map.js | 14 ++++++++---- .../vislib/__tests__/lib/handler/handler.js | 22 +++++++++++++++++++ src/ui/public/vislib/lib/handler/handler.js | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/core_plugins/kbn_vislib_vis_types/public/tile_map.js b/src/core_plugins/kbn_vislib_vis_types/public/tile_map.js index cb6ae028cf2bc..8c2e18ed3e2b5 100644 --- a/src/core_plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/core_plugins/kbn_vislib_vis_types/public/tile_map.js @@ -48,11 +48,17 @@ export default function TileMapVisType(Private, getAppState, courier, config) { pushFilter(filter, false, indexPatternName); }, - mapMoveEnd: function (event, uiState) { - uiState.set('mapCenter', event.center); + mapMoveEnd: function (event) { + const vis = _.get(event, 'chart.geohashGridAgg.vis'); + if (vis && vis.hasUiState()) { + vis.getUiState().set('mapCenter', event.center); + } }, - mapZoomEnd: function (event, uiState) { - uiState.set('mapZoom', event.zoom); + mapZoomEnd: function (event) { + const vis = _.get(event, 'chart.geohashGridAgg.vis'); + if (vis && vis.hasUiState()) { + vis.getUiState().set('mapZoom', event.zoom); + } const autoPrecision = _.get(event, 'chart.geohashGridAgg.params.autoPrecision'); if (autoPrecision) { diff --git a/src/ui/public/vislib/__tests__/lib/handler/handler.js b/src/ui/public/vislib/__tests__/lib/handler/handler.js index ea933bf8d89e0..6953e3ebef2e0 100644 --- a/src/ui/public/vislib/__tests__/lib/handler/handler.js +++ b/src/ui/public/vislib/__tests__/lib/handler/handler.js @@ -134,5 +134,27 @@ dateHistogramArray.forEach(function (data, i) { expect(vis.handler.charts.length).to.be(0); }); }); + + describe('event proxying', function () { + + it('should only pass the original event object to downstream handlers', function (done) { + const event = {}; + const chart = vis.handler.charts[0]; + + const mockEmitter = function () { + const args = Array.from(arguments); + expect(args.length).to.be(2); + expect(args[0]).to.be('click'); + expect(args[1]).to.be(event); + done(); + }; + + vis.emit = mockEmitter; + vis.handler.enable('click', chart); + chart.events.emit('click', event); + }); + + }); + }); }); diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index e496c1b39271f..a74c627931860 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -55,7 +55,7 @@ export default function HandlerBaseClass(Private) { this.getProxyHandler = _.memoize(function (event) { let self = this; return function (e) { - self.vis.emit(event, e, vis.uiState); + self.vis.emit(event, e); }; }); }