-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathConsoleLogger.jsx
More file actions
97 lines (83 loc) · 2.39 KB
/
ConsoleLogger.jsx
File metadata and controls
97 lines (83 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import './ConsoleLogger.scss';
import React, {Component} from 'react';
import { connect } from 'react-redux';
import Terminal from 'terminal-in-react';
import { CardHeaderStyled } from 'styled';
import { panelSet, logReset } from 'reducers/errorlog';
class ConsoleLogger extends Component {
constructor(props){
super(props);
this.setWrapperRef = this.setWrapperRef.bind(this);
this.handleClickOutside = this.handleClickOutside.bind(this);
}
componentDidMount() {
document.addEventListener('mousedown', this.handleClickOutside);
}
componentWillUnmount() {
if (this.props.errorlog.data.unseen > 0) {
this.props.logReset();
}
document.removeEventListener('mousedown', this.handleClickOutside);
}
/**
* Set the wrapper ref
*/
setWrapperRef(node) {
this.wrapperRef = node;
}
/**
* Alert if clicked on outside of element
*/
handleClickOutside(event) {
if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
this.props.panelSet("UNOPEN");
}
}
render(){
let { errorlog } = this.props;
let { data: { unseen, status }} = errorlog;
return (
<div ref={this.setWrapperRef} className={`ConsoleLogger ${ status.toLowerCase() }`}>
<CardHeaderStyled
className="console-title"
onClick={()=>{
status !== "OPEN"
? this.props.panelSet("OPEN")
: this.props.panelSet("MINIMISE")
}}
>
<div>
<div className="left-section">
<i className="fa fa-times-circle" onClick={(e)=>{e.stopPropagation(); this.props.panelSet("CLOSE")}}></i>
{
status === "OPEN"
? <i className="fa fa-window-minimize"></i>
: <i className="fa fa-window-maximize"></i>
}
<span>Console Log</span>
</div>
{ !!unseen && <span className="badge">{unseen}</span> }
</div>
</CardHeaderStyled>
<div className="terminal-wrapper">
<Terminal
color={"red"}
barColor={"red"}
hideTopBar={true}
backgroundColor={"white"}
watchConsoleLogging={true}
allowTabs={false}
/>
</div>
</div>)
}
}
export default connect(
({ errorlog }) => ({
errorlog
}),
{
panelSet,
logReset,
}
)(ConsoleLogger);