Skip to content

Commit 2ac25ae

Browse files
authored
fix: Handling no columns (#1170)
Added graceful handling to IrisGrid for tables with no columns. fixes #1169
1 parent e314be6 commit 2ac25ae

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

packages/iris-grid/src/IrisGrid.test.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MockPath2D {
1010
addPath = jest.fn();
1111
}
1212

13-
window.Path2D = MockPath2D;
13+
window.Path2D = (MockPath2D as unknown) as new () => Path2D;
1414

1515
const VIEW_SIZE = 5000;
1616

@@ -61,7 +61,8 @@ function makeComponent(
6161
createNodeMock,
6262
}
6363
);
64-
return testRenderer.getInstance();
64+
return testRenderer.getInstance() as TestRenderer.ReactTestInstance &
65+
IrisGrid;
6566
}
6667

6768
function keyDown(key, component, extraArgs?) {
@@ -193,3 +194,15 @@ it('handles undefined operator, should default to eq', () => {
193194
'any'
194195
);
195196
});
197+
198+
it('should set gotoValueSelectedColumnName to empty string if no columns are given', () => {
199+
const component = makeComponent(
200+
IrisGridTestUtils.makeModel(
201+
IrisGridTestUtils.makeTable({
202+
columns: [],
203+
})
204+
)
205+
);
206+
207+
expect(component.state.gotoValueSelectedColumnName).toEqual('');
208+
});

packages/iris-grid/src/IrisGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
850850
gotoRowError: '',
851851
gotoValueError: '',
852852

853-
gotoValueSelectedColumnName: model.columns[0].name,
853+
gotoValueSelectedColumnName: model.columns[0]?.name ?? '',
854854
gotoValueSelectedFilter: FilterType.eq,
855855
gotoValue: '',
856856
columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups,

0 commit comments

Comments
 (0)