Skip to content

Commit

Permalink
Fix filtering from visualizations
Browse files Browse the repository at this point in the history
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: elastic#7501
Related: elastic#6835 (added the new
param)

Former-commit-id: 20cb910
  • Loading branch information
Bargs committed Jul 21, 2016
1 parent 4921bdd commit 1c8890f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/core_plugins/kbn_vislib_vis_types/public/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions src/ui/public/vislib/__tests__/lib/handler/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});
});
2 changes: 1 addition & 1 deletion src/ui/public/vislib/lib/handler/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
});
}
Expand Down

0 comments on commit 1c8890f

Please sign in to comment.