Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Fixes error on table when there is no data #161953

Merged
merged 3 commits into from Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly why we enabled noUncheckedIndexedAccess in elastic/elastic-charts#2006

I don't know why typescript excluded this flag from strict mode when this is clearly an undefined union.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider adding this setting just for our code... it makes sense to me

transposedColumnGroups.forEach((transposedColumnGroup) => {
args.columns.push(transposedColumnGroup[index]);
});
Expand Down