Skip to content

Commit

Permalink
fixes split chart with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Dec 10, 2018
1 parent 7b68806 commit 83fb00e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
40 changes: 4 additions & 36 deletions src/ui/public/vis/__tests__/response_handlers/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,26 @@
import ngMock from 'ng_mock';
import expect from 'expect.js';
import { VislibSeriesResponseHandlerProvider } from '../../response_handlers/vislib';
import { VisProvider } from '../..';
import fixtures from 'fixtures/fake_hierarchical_data';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

const rowAgg = [
{ id: 'agg_1', type: 'avg', schema: 'metric', params: { field: 'bytes' } },
{ id: 'agg_2', type: 'terms', schema: 'split', params: { field: 'extension', rows: true } },
{ id: 'agg_3', type: 'terms', schema: 'segment', params: { field: 'machine.os' } },
{ id: 'agg_4', type: 'terms', schema: 'segment', params: { field: 'geo.src' } }
];


describe('Basic Response Handler', function () {
let basicResponseHandler;
let indexPattern;
let Vis;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
basicResponseHandler = Private(VislibSeriesResponseHandlerProvider).handler;
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

it('calls hierarchical converter if isHierarchical is set to true', () => {
const vis = new Vis(indexPattern, {
type: 'pie',
aggs: rowAgg
});
basicResponseHandler(vis, fixtures.threeTermBuckets).then(data => {
expect(data).to.not.be.an('undefined');
expect(data.rows[0].slices).to.not.be.an('undefined');
expect(data.rows[0].series).to.be.an('undefined');
});
});

it('returns empty object if conversion failed', () => {
basicResponseHandler({}, {}).then(data => {
basicResponseHandler({}).then(data => {
expect(data).to.not.be.an('undefined');
expect(data.rows).to.equal([]);
});
});

it('returns converted data', () => {
const vis = new Vis(indexPattern, {
type: 'histogram',
aggs: rowAgg.slice(0, 3)
});
basicResponseHandler(vis, fixtures.threeTermBuckets).then(data => {
it('returns empty object if no data was found', () => {
basicResponseHandler({ columns: [{ id: '1', title: '1', aggConfig: {} }], rows: [] }).then(data => {
expect(data).to.not.be.an('undefined');
expect(data.rows[0].slices).to.be.an('undefined');
expect(data.rows[0].series).to.not.be.an('undefined');
expect(data.rows).to.equal([]);
});
});

Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/vis/response_handlers/vislib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ function convertTableGroup(tableGroup, convertTable) {
const tables = tableGroup.tables;
const firstChild = tables[0];

if (firstChild.columns) {
if (!tables.length) return;

if (firstChild.columns) {
const chart = convertTable(firstChild);
// if chart is within a split, assign group title to its label
if (tableGroup.$parent) {
Expand All @@ -36,8 +37,6 @@ function convertTableGroup(tableGroup, convertTable) {
return chart;
}

if (!tables.length) return;

const out = {};
let outList;

Expand Down

0 comments on commit 83fb00e

Please sign in to comment.