2016-12-23 18:40:16 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
|
|
|
|
import kolideLogo from '../../../../assets/images/kolide-logo.svg';
|
|
|
|
|
|
|
|
|
|
class OrgLogoIcon extends Component {
|
|
|
|
|
static propTypes = {
|
2016-12-29 14:40:08 +00:00
|
|
|
className: PropTypes.string,
|
2016-12-23 18:40:16 +00:00
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
|
src: kolideLogo,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constructor (props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = { imageSrc: kolideLogo };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
|
const { src } = this.props;
|
|
|
|
|
|
|
|
|
|
this.setState({ imageSrc: src });
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
|
const { src } = nextProps;
|
2017-01-06 18:45:37 +00:00
|
|
|
const { unchangedSourceProp } = this;
|
|
|
|
|
|
|
|
|
|
if (unchangedSourceProp(nextProps)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-12-23 18:40:16 +00:00
|
|
|
|
|
|
|
|
this.setState({ imageSrc: src });
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 18:45:37 +00:00
|
|
|
shouldComponentUpdate (nextProps) {
|
|
|
|
|
const { imageSrc } = this.state;
|
|
|
|
|
const { unchangedSourceProp } = this;
|
|
|
|
|
|
|
|
|
|
if (unchangedSourceProp(nextProps) && (imageSrc === kolideLogo)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 18:40:16 +00:00
|
|
|
onError = () => {
|
|
|
|
|
this.setState({ imageSrc: kolideLogo });
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 18:45:37 +00:00
|
|
|
unchangedSourceProp = (nextProps) => {
|
|
|
|
|
const { src: nextSrcProp } = nextProps;
|
|
|
|
|
const { src } = this.props;
|
|
|
|
|
|
|
|
|
|
return src === nextSrcProp;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 18:40:16 +00:00
|
|
|
render () {
|
2016-12-29 14:40:08 +00:00
|
|
|
const { className } = this.props;
|
2016-12-23 18:40:16 +00:00
|
|
|
const { imageSrc } = this.state;
|
|
|
|
|
const { onError } = this;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<img
|
|
|
|
|
alt="Organization Logo"
|
2016-12-29 14:40:08 +00:00
|
|
|
className={className}
|
2016-12-23 18:40:16 +00:00
|
|
|
onError={onError}
|
|
|
|
|
src={imageSrc}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default OrgLogoIcon;
|