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

fix(csv): Base CSV viewer column count on longest row #1056

Merged
merged 1 commit into from
Aug 28, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/viewers/text/BoxCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class BoxCSV {
*/
renderCSV() {
const rowCount = this.data.length;
const columnCount = this.data[0].length;
const rowSample = this.data.sort((a, b) => b.length - a.length)[0]; // Find the row with the most columns
const columnCount = rowSample.length;

const maxWidth = this.csvEl.clientWidth;
const maxHeight = this.csvEl.clientHeight;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/viewers/text/__tests__/BoxCSV-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ describe('lib/viewers/text/BoxCSV', () => {
expect(gridComponent.props.rowCount).to.equal(3);
expect(renderStub).to.be.calledWith(gridComponent, csvComponent.csvEl);
});

it('should base its column count on the longest available row', () => {
const renderStub = sandbox.stub(ReactDOM, 'render');
csvComponent.data = [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2]];
csvComponent.renderCSV();

const gridComponent = renderStub.firstCall.args[0];
expect(gridComponent.props.columnCount).to.equal(4);
});
});
});