Skip to content

Commit

Permalink
fix: Handling no columns (#1170)
Browse files Browse the repository at this point in the history
Added graceful handling to IrisGrid for tables with no columns.

fixes #1169
  • Loading branch information
bmingles authored Mar 22, 2023
1 parent e314be6 commit 2ac25ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions packages/iris-grid/src/IrisGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MockPath2D {
addPath = jest.fn();
}

window.Path2D = MockPath2D;
window.Path2D = (MockPath2D as unknown) as new () => Path2D;

const VIEW_SIZE = 5000;

Expand Down Expand Up @@ -61,7 +61,8 @@ function makeComponent(
createNodeMock,
}
);
return testRenderer.getInstance();
return testRenderer.getInstance() as TestRenderer.ReactTestInstance &
IrisGrid;
}

function keyDown(key, component, extraArgs?) {
Expand Down Expand Up @@ -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('');
});
2 changes: 1 addition & 1 deletion packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ export class IrisGrid extends Component<IrisGridProps, IrisGridState> {
gotoRowError: '',
gotoValueError: '',

gotoValueSelectedColumnName: model.columns[0].name,
gotoValueSelectedColumnName: model.columns[0]?.name ?? '',
gotoValueSelectedFilter: FilterType.eq,
gotoValue: '',
columnHeaderGroups: columnHeaderGroups ?? model.initialColumnHeaderGroups,
Expand Down

0 comments on commit 2ac25ae

Please sign in to comment.