Skip to content

Commit

Permalink
feat(controls): Add option for react controls to CSV viewer (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoffan authored Dec 9, 2020
1 parent f9b07fd commit e34cc02
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/lib/viewers/text/CSVViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ class CSVViewer extends TextBaseViewer {
this.csvComponent = new BoxCSV(this.csvEl, this.data);
this.csvComponent.renderCSV();

this.loadUI();
if (this.options.useReactControls) {
this.loadUIReact();
} else {
this.loadUI();
}

this.loaded = true;
this.emit(VIEWER_EVENT.load);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/text/MarkdownViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class MarkdownViewer extends PlainTextViewer {
}

renderUI() {
if (this.options.useReactControls) {
if (this.controls && this.options.useReactControls) {
this.controls.render(<MarkdownControls onFullscreenToggle={this.toggleFullscreen} />);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/text/TextBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class TextBaseViewer extends BaseViewer {
this.zoomControls.setCurrentScale(this.scale);
}

if (this.options.useReactControls) {
if (this.controls && this.options.useReactControls) {
this.controls.render(
<TextControls
maxScale={ZOOM_MAX}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/viewers/text/__tests__/CSVViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,27 @@ describe('lib/viewers/text/CSVViewer', () => {
});
/* eslint-enable react/prefer-es6-class */
jest.spyOn(csv, 'loadUI');
jest.spyOn(csv, 'loadUIReact');
jest.spyOn(csv, 'emit');

csv.finishLoading();

expect(csv.loadUI).toBeCalled();
expect(csv.loadUIReact).not.toBeCalled();
expect(csv.loaded).toBe(true);
expect(csv.emit).toBeCalledWith(VIEWER_EVENT.load);
});

test('should finish loading and render react ui if option is enabled', () => {
jest.spyOn(csv, 'loadUI');
jest.spyOn(csv, 'loadUIReact');

csv.options.useReactControls = true;
csv.finishLoading();

expect(csv.loadUI).not.toBeCalled();
expect(csv.loadUIReact).toBeCalled();
});
});

describe('checkForParseErrors()', () => {
Expand Down

0 comments on commit e34cc02

Please sign in to comment.