Skip to content

Commit

Permalink
fix(printing): Adding compat for older preview versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mickr committed Feb 29, 2020
1 parent 172833f commit 543f555
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/elements/content-preview/ContentPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,24 @@ class ContentPreview extends React.PureComponent<Props, State> {
return !!showAnnotations && (this.canAnnotate() || hasViewAllPermissions || hasViewSelfPermissions);
}

/**
* Returns whether a preview viewer supports printing
*
* @return {boolean}
*/
handleCanPrint() {
/*
Setting this as default so older preview versions can still print documents without having the
default state have the print icon.
*/
let canPrint = true;
const preview = this.getPreview();

if (preview && typeof preview.canPrint === 'function') {
this.setState({ canPrint: preview.canPrint() });
canPrint = preview.canPrint();
}

return this.setState({ canPrint });
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/elements/content-preview/__tests__/ContentPreview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ describe('elements/content-preview/ContentPreview', () => {
expect(canPrintMock).toBeCalled();
expect(wrapper.state('canPrint')).toEqual(expected);
});

it('should show print icon if printCheck is not available', () => {
const wrapper = getWrapper();
const instance = wrapper.instance();

wrapper.setState({ file });
instance.handleCanPrint();

expect(wrapper.state('canPrint')).toEqual(true);
});
});

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

0 comments on commit 543f555

Please sign in to comment.