From 2ac25aed8afb51272c46050a1a0d278da9a87bc6 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Wed, 22 Mar 2023 14:57:02 -0500 Subject: [PATCH] fix: Handling no columns (#1170) Added graceful handling to IrisGrid for tables with no columns. fixes #1169 --- packages/iris-grid/src/IrisGrid.test.tsx | 17 +++++++++++++++-- packages/iris-grid/src/IrisGrid.tsx | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/iris-grid/src/IrisGrid.test.tsx b/packages/iris-grid/src/IrisGrid.test.tsx index c9d7d606a4..fbb5ed45aa 100644 --- a/packages/iris-grid/src/IrisGrid.test.tsx +++ b/packages/iris-grid/src/IrisGrid.test.tsx @@ -10,7 +10,7 @@ class MockPath2D { addPath = jest.fn(); } -window.Path2D = MockPath2D; +window.Path2D = (MockPath2D as unknown) as new () => Path2D; const VIEW_SIZE = 5000; @@ -61,7 +61,8 @@ function makeComponent( createNodeMock, } ); - return testRenderer.getInstance(); + return testRenderer.getInstance() as TestRenderer.ReactTestInstance & + IrisGrid; } function keyDown(key, component, extraArgs?) { @@ -193,3 +194,15 @@ it('handles undefined operator, should default to eq', () => { 'any' ); }); + +it('should set gotoValueSelectedColumnName to empty string if no columns are given', () => { + const component = makeComponent( + IrisGridTestUtils.makeModel( + IrisGridTestUtils.makeTable({ + columns: [], + }) + ) + ); + + expect(component.state.gotoValueSelectedColumnName).toEqual(''); +}); diff --git a/packages/iris-grid/src/IrisGrid.tsx b/packages/iris-grid/src/IrisGrid.tsx index a8154e20a5..13c381ef25 100644 --- a/packages/iris-grid/src/IrisGrid.tsx +++ b/packages/iris-grid/src/IrisGrid.tsx @@ -850,7 +850,7 @@ export class IrisGrid extends Component { gotoRowError: '', gotoValueError: '', - gotoValueSelectedColumnName: model.columns[0].name, + gotoValueSelectedColumnName: model.columns[0]?.name ?? '', gotoValueSelectedFilter: FilterType.eq, gotoValue: '', columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups,