DocumentHtml improvement and Enzyme

This commit is contained in:
Jori Lallo
2016-09-16 00:06:33 -07:00
parent 441c66b13f
commit 5d08cf22c8
9 changed files with 154 additions and 125 deletions

View File

@ -3,48 +3,14 @@ import { toJS } from 'mobx';
import { observer } from 'mobx-react';
import PublishingInfo from 'components/PublishingInfo';
import DocumentHtml from './components/DocumentHtml';
import styles from './Document.scss';
@observer
class DocumentHtml extends React.Component {
static propTypes = {
html: PropTypes.string.isRequired,
}
componentDidMount = () => {
this.setExternalLinks();
}
componentDidUpdate = () => {
this.setExternalLinks();
}
setExternalLinks = () => {
const links = this.refs.content.querySelectorAll('a');
links.forEach(link => {
if (link.hostname !== window.location.hostname) {
link.target = '_blank'; // eslint-disable-line no-param-reassign
}
});
}
render() {
return (
<div
ref="content"
className={ styles.document }
dangerouslySetInnerHTML={{ __html: this.props.html }}
{ ...this.props }
/>
);
}
}
@observer
class Document extends React.Component {
static propTypes = {
document: React.PropTypes.object.isRequired,
document: PropTypes.object.isRequired,
}
render() {
@ -64,6 +30,3 @@ class Document extends React.Component {
}
export default Document;
export {
DocumentHtml,
};