tabify responeHandler for table (#13877)
* adding tabify response handler * tabify should be the default response handler * asAggResultConfig should be configurable for BWC * update table to work with new tabify response handler * region map needs to define responseHandler: none * fixing tests * markdown should set responseHandler to none
This commit is contained in:
parent
bdcafa0c8c
commit
7bcc7435e2
|
@ -38,6 +38,7 @@ function MarkdownVisProvider(Private) {
|
|||
showTimePicker: false,
|
||||
},
|
||||
requestHandler: 'none',
|
||||
responseHandler: 'none',
|
||||
implementsRenderComplete: true,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ VisTypesRegistryProvider.register(function RegionMapProvider(Private, regionmaps
|
|||
aggFilter: ['terms']
|
||||
}
|
||||
])
|
||||
}
|
||||
},
|
||||
responseHandler: 'none'
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -17,10 +17,12 @@ describe('Controller', function () {
|
|||
let Vis;
|
||||
let fixtures;
|
||||
let AppState;
|
||||
let tabify;
|
||||
|
||||
beforeEach(ngMock.module('kibana', 'kibana/table_vis'));
|
||||
beforeEach(ngMock.inject(function ($injector) {
|
||||
Private = $injector.get('Private');
|
||||
tabify = Private(AggResponseTabifyProvider);
|
||||
$rootScope = $injector.get('$rootScope');
|
||||
$compile = $injector.get('$compile');
|
||||
fixtures = require('fixtures/fake_hierarchical_data');
|
||||
|
@ -70,7 +72,7 @@ describe('Controller', function () {
|
|||
|
||||
// put a response into the controller
|
||||
function attachEsResponseToScope(resp) {
|
||||
$rootScope.esResponse = resp || fixtures.oneRangeBucket;
|
||||
$rootScope.esResponse = resp;
|
||||
$rootScope.$apply();
|
||||
}
|
||||
|
||||
|
@ -81,12 +83,13 @@ describe('Controller', function () {
|
|||
}
|
||||
|
||||
it('exposes #tableGroups and #hasSomeRows when a response is attached to scope', function () {
|
||||
initController(new OneRangeVis());
|
||||
const vis = new OneRangeVis();
|
||||
initController(vis);
|
||||
|
||||
expect(!$scope.tableGroups).to.be.ok();
|
||||
expect(!$scope.hasSomeRows).to.be.ok();
|
||||
|
||||
attachEsResponseToScope(fixtures.oneRangeBucket);
|
||||
attachEsResponseToScope(tabify(vis, fixtures.oneRangeBucket));
|
||||
|
||||
expect($scope.hasSomeRows).to.be(true);
|
||||
expect($scope.tableGroups).to.have.property('tables');
|
||||
|
@ -96,9 +99,10 @@ describe('Controller', function () {
|
|||
});
|
||||
|
||||
it('clears #tableGroups and #hasSomeRows when the response is removed', function () {
|
||||
initController(new OneRangeVis());
|
||||
const vis = new OneRangeVis();
|
||||
initController(vis);
|
||||
|
||||
attachEsResponseToScope(fixtures.oneRangeBucket);
|
||||
attachEsResponseToScope(tabify(vis, fixtures.oneRangeBucket));
|
||||
removeEsResponseFromScope();
|
||||
|
||||
expect(!$scope.hasSomeRows).to.be.ok();
|
||||
|
@ -110,26 +114,28 @@ describe('Controller', function () {
|
|||
columnIndex: 1,
|
||||
direction: 'asc'
|
||||
};
|
||||
initController(new OneRangeVis({ sort: sortObj }));
|
||||
const vis = new OneRangeVis({ sort: sortObj });
|
||||
initController(vis);
|
||||
|
||||
// modify the data to not have any buckets
|
||||
const resp = _.cloneDeep(fixtures.oneRangeBucket);
|
||||
resp.aggregations.agg_2.buckets = {};
|
||||
|
||||
attachEsResponseToScope(resp);
|
||||
attachEsResponseToScope(tabify(vis, resp));
|
||||
|
||||
expect($scope.sort.columnIndex).to.equal(sortObj.columnIndex);
|
||||
expect($scope.sort.direction).to.equal(sortObj.direction);
|
||||
});
|
||||
|
||||
it('sets #hasSomeRows properly if the table group is empty', function () {
|
||||
initController(new OneRangeVis());
|
||||
const vis = new OneRangeVis();
|
||||
initController(vis);
|
||||
|
||||
// modify the data to not have any buckets
|
||||
const resp = _.cloneDeep(fixtures.oneRangeBucket);
|
||||
resp.aggregations.agg_2.buckets = {};
|
||||
|
||||
attachEsResponseToScope(resp);
|
||||
attachEsResponseToScope(tabify(vis, resp));
|
||||
|
||||
expect($scope.hasSomeRows).to.be(false);
|
||||
expect(!$scope.tableGroups).to.be.ok();
|
||||
|
@ -142,10 +148,10 @@ describe('Controller', function () {
|
|||
|
||||
const vis = new OneRangeVis({ showPartialRows: true });
|
||||
initController(vis);
|
||||
attachEsResponseToScope(fixtures.oneRangeBucket);
|
||||
attachEsResponseToScope(spiedTabify(vis, fixtures.oneRangeBucket));
|
||||
|
||||
expect(spiedTabify).to.have.property('callCount', 1);
|
||||
expect(spiedTabify.firstCall.args[2]).to.have.property('partialRows', true);
|
||||
expect(spiedTabify.firstCall.args[0].isHierarchical()).to.equal(true);
|
||||
});
|
||||
|
||||
it('passes partialRows:false to tabify based on the vis params', function () {
|
||||
|
@ -155,9 +161,9 @@ describe('Controller', function () {
|
|||
|
||||
const vis = new OneRangeVis({ showPartialRows: false });
|
||||
initController(vis);
|
||||
attachEsResponseToScope(fixtures.oneRangeBucket);
|
||||
attachEsResponseToScope(spiedTabify(vis, fixtures.oneRangeBucket));
|
||||
|
||||
expect(spiedTabify).to.have.property('callCount', 1);
|
||||
expect(spiedTabify.firstCall.args[2]).to.have.property('partialRows', false);
|
||||
expect(spiedTabify.firstCall.args[0].isHierarchical()).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -78,6 +78,9 @@ function TableVisTypeProvider(Private) {
|
|||
}
|
||||
])
|
||||
},
|
||||
responseHandlerConfig: {
|
||||
asAggConfigResults: true
|
||||
},
|
||||
hierarchicalData: function (vis) {
|
||||
return Boolean(vis.params.showPartialRows || vis.params.showMeticsAtAllLevels);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { AggResponseTabifyProvider } from 'ui/agg_response/tabify/tabify';
|
||||
import { uiModules } from 'ui/modules';
|
||||
import { assign } from 'lodash';
|
||||
|
||||
|
@ -8,9 +7,7 @@ const module = uiModules.get('kibana/table_vis', ['kibana']);
|
|||
|
||||
// add a controller to tha module, which will transform the esResponse into a
|
||||
// tabular format that we can pass to the table directive
|
||||
module.controller('KbnTableVisController', function ($scope, $element, Private) {
|
||||
const tabifyAggResponse = Private(AggResponseTabifyProvider);
|
||||
|
||||
module.controller('KbnTableVisController', function ($scope) {
|
||||
const uiStateSort = ($scope.uiState) ? $scope.uiState.get('vis.params.sort') : {};
|
||||
assign($scope.vis.params.sort, uiStateSort);
|
||||
|
||||
|
@ -24,20 +21,13 @@ module.controller('KbnTableVisController', function ($scope, $element, Private)
|
|||
* - the underlying data changes (esResponse)
|
||||
* - one of the view options changes (vis.params)
|
||||
*/
|
||||
$scope.$watchMulti(['esResponse', 'vis.params'], function ([resp]) {
|
||||
$scope.$watch('esResponse', function (resp) {
|
||||
|
||||
let tableGroups = $scope.tableGroups = null;
|
||||
let hasSomeRows = $scope.hasSomeRows = null;
|
||||
|
||||
if (resp) {
|
||||
const vis = $scope.vis;
|
||||
const params = vis.params;
|
||||
|
||||
tableGroups = tabifyAggResponse(vis, resp, {
|
||||
partialRows: params.showPartialRows,
|
||||
minimalColumns: vis.isHierarchical() && !params.showMeticsAtAllLevels,
|
||||
asAggConfigResults: true
|
||||
});
|
||||
tableGroups = resp;
|
||||
|
||||
hasSomeRows = tableGroups.tables.some(function haveRows(table) {
|
||||
if (table.tables) return table.tables.some(haveRows);
|
||||
|
|
26
src/ui/public/vis/response_handlers/tabify.js
Normal file
26
src/ui/public/vis/response_handlers/tabify.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import _ from 'lodash';
|
||||
import { AggResponseIndexProvider } from 'ui/agg_response/index';
|
||||
import { VisResponseHandlersRegistryProvider } from 'ui/registry/vis_response_handlers';
|
||||
|
||||
const TabifyResponseHandlerProvider = function (Private) {
|
||||
const aggResponse = Private(AggResponseIndexProvider);
|
||||
|
||||
return {
|
||||
name: 'tabify',
|
||||
handler: function (vis, response) {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
const tableGroup = aggResponse.tabify(vis, response, {
|
||||
canSplit: true,
|
||||
asAggConfigResults: _.get(vis, 'type.responseHandlerConfig.asAggConfigResults', false)
|
||||
});
|
||||
|
||||
resolve(tableGroup);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
VisResponseHandlersRegistryProvider.register(TabifyResponseHandlerProvider);
|
||||
|
||||
export { TabifyResponseHandlerProvider };
|
|
@ -20,7 +20,7 @@ export function VisTypeProvider() {
|
|||
defaults: {}, // default configuration
|
||||
},
|
||||
requestHandler: 'courier', // select one from registry or pass a function
|
||||
responseHandler: 'none',
|
||||
responseHandler: 'tabify',
|
||||
editor: 'default',
|
||||
editorConfig: {
|
||||
collections: {}, // collections used for configuration (list of positions, ...)
|
||||
|
|
|
@ -16,7 +16,8 @@ export default class UiExports {
|
|||
],
|
||||
visResponseHandlers: [
|
||||
'ui/vis/response_handlers/basic',
|
||||
'ui/vis/response_handlers/none'
|
||||
'ui/vis/response_handlers/none',
|
||||
'ui/vis/response_handlers/tabify'
|
||||
],
|
||||
visEditorTypes: [
|
||||
'ui/vis/editors/default/default',
|
||||
|
|
Loading…
Reference in a new issue