Skip to content
Snippets Groups Projects
Commit b3cccc7d authored by Reinoud Bokhorst's avatar Reinoud Bokhorst
Browse files

OSB-35: fixed bug with img ref (use closure)

parent b82006af
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
...@@ -24,32 +24,27 @@ import {connect} from "react-redux"; ...@@ -24,32 +24,27 @@ import {connect} from "react-redux";
class ModalPicture extends Component { class ModalPicture extends Component {
constructor(props){
super(props) state = {
this.state = { modal: false,
modal: false, modalUrl: ''
modalUrl: ''
};
this.img = React.createRef();
this.toggleModal = this.toggleModal.bind(this);
this.onImgError = this.onImgError.bind(this);
} }
toggleModal(e){ toggleModal = (e) => {
this.setState({ this.setState({
modal: !this.state.modal, modal: !this.state.modal,
modalUrl: e.currentTarget.src modalUrl: e.currentTarget.src
}); });
} }
onImgError(e){ onImgError = (e) => {
const img = e.currentTarget; const img = e.currentTarget;
img.alt = 'Reloading in 2 sec..'; img.alt = 'Reloading in 2 sec..';
// let the window figure out if the timeout id is still valid // let the window figure out if the timeout id is still valid
if(this.timeout){ if(this.timeout){
clearTimeout(this.timeout); clearTimeout(this.timeout);
} }
this.timeout = setTimeout(() => { this.img.current.src = this.img.current.src; }, 2000 ); this.timeout = setTimeout(() => { img.src = img.src; }, 2000 );
} }
clearTimeouts() { clearTimeouts() {
...@@ -61,7 +56,7 @@ class ModalPicture extends Component { ...@@ -61,7 +56,7 @@ class ModalPicture extends Component {
this.clearTimeouts(); this.clearTimeouts();
return ( return (
<React.Fragment> <React.Fragment>
<img ref={this.img} src={this.props.url} onClick={this.toggleModal} onError={this.onImgError} title="Click to enlarge" alt="Not present"/> <img src={this.props.url} onClick={this.toggleModal} onError={this.onImgError} title="Click to enlarge" alt="Not present"/>
<Modal isOpen={this.state.modal} fade={false} size="lg" toggle={this.toggle} className={this.props.className}> <Modal isOpen={this.state.modal} fade={false} size="lg" toggle={this.toggle} className={this.props.className}>
<ModalHeader toggle={this.toggleModal}></ModalHeader> <ModalHeader toggle={this.toggleModal}></ModalHeader>
<ModalBody> <ModalBody>
......
...@@ -15,20 +15,14 @@ import {renderDateRange} from '../utils/utils'; ...@@ -15,20 +15,14 @@ import {renderDateRange} from '../utils/utils';
import './StationTestView.css'; import './StationTestView.css';
class GenericStatusC extends Component { class GenericStatusC extends Component {
constructor(props) {
super(props);
this.mouseOver = this.mouseOver.bind(this); mouseOver = () => {
this.mouseOut = this.mouseOut.bind(this);
}
mouseOver() {
if (this.props.data !== undefined && this.props.isPinned === false) { if (this.props.data !== undefined && this.props.isPinned === false) {
this.props.selectAntennaError(this.props.data); this.props.selectAntennaError(this.props.data);
} }
} }
mouseOut() { mouseOut = () => {
if (this.props.data !== undefined && this.props.isPinned === false) { if (this.props.data !== undefined && this.props.isPinned === false) {
this.props.selectAntennaError({}); this.props.selectAntennaError({});
} }
...@@ -78,23 +72,25 @@ class GenericStatusC extends Component { ...@@ -78,23 +72,25 @@ class GenericStatusC extends Component {
} }
} }
mouseClick(e) { mouseClick = (e) => {
this.props.selectAntennaError(this.props.data); this.props.selectAntennaError(this.props.data);
this.props.pinAntennaError(!this.props.isPinned); this.props.pinAntennaError(!this.props.isPinned);
} }
onContextMenu = (e) => {
e.preventDefault();
};
render() { render() {
const color = this.props.isGood ? "so-good" : "so-serious"; const color = this.props.isGood ? "so-good" : "so-serious";
const label = this.props.isGood ? "" : this.renderError(); const label = this.props.isGood ? "" : this.renderError();
return ( return (
<td className={"stv-component-status " + color} <td className={"stv-component-status " + color}
onContextMenu={this.onContextMenu}
onMouseOver={this.mouseOver} onMouseOver={this.mouseOver}
onMouseOut={this.mouseOut} onMouseOut={this.mouseOut}
onClick={e => { onClick={this.mouseClick} >
this.mouseClick(e)
}}>
{label} {label}
</td>); </td>);
} }
...@@ -113,11 +109,9 @@ const GenericStatus = connect(state => { ...@@ -113,11 +109,9 @@ const GenericStatus = connect(state => {
class AntennaErrorLineC extends Component { class AntennaErrorLineC extends Component {
constructor(props) {
super(props); state = {
this.state = { isCollapsed: true
isCollapsed: true
}
} }
static composeHeaderLine(data) { static composeHeaderLine(data) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment