Skip to content

Commit

Permalink
[Lens] Fixes error on table when there is no data (elastic#161953)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#161948

Fixes the bug described in the issue. The bug is happening only for the
table viz.

<img width="1664" alt="image"
src="https://github.com/elastic/kibana/assets/17003240/9646edcc-005d-4d2c-919a-097a673d730e">

### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit 6550793)
  • Loading branch information
stratoula committed Jul 17, 2023
1 parent 782c3b4 commit 516c494
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Expand Up @@ -11,7 +11,7 @@ import { DatatableArgs } from './datatable';

import { transposeTable } from './transpose_helpers';

describe('transpose_helpes', () => {
describe('transpose_helpers', () => {
function buildTable(): Datatable {
// 3 buckets, 2 metrics
// first bucket goes A/B/C
Expand Down Expand Up @@ -290,4 +290,26 @@ describe('transpose_helpes', () => {
1 + 18 - 2
);
});

it('should not fail for no data', () => {
const table = buildTable();
const updatedTable = {
...table,
rows: [],
};
const args = buildArgs();
const updatedArgs = {
...args,
columns: [
{
type: 'lens_datatable_column',
columnId: 'bucket1',
isTransposed: true,
transposable: false,
},
],
} as DatatableArgs;
transposeTable(updatedArgs, updatedTable, buildFormatters());
expect(args.columns.length).toEqual(5);
});
});
Expand Up @@ -118,7 +118,7 @@ function updateColumnArgs(
) {
args.columns = [...bucketsColumnArgs];
// add first column from each group, then add second column for each group, ...
transposedColumnGroups[0].forEach((_, index) => {
transposedColumnGroups[0]?.forEach((_, index) => {
transposedColumnGroups.forEach((transposedColumnGroup) => {
args.columns.push(transposedColumnGroup[index]);
});
Expand Down

0 comments on commit 516c494

Please sign in to comment.