-
Notifications
You must be signed in to change notification settings - Fork 15
/
UptimeRobot.js
70 lines (64 loc) · 2.04 KB
/
UptimeRobot.js
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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { ReactComponent as IconError } from '../../assets/svg/exclamation-triangle-solid.svg';
import { ReactComponent as IconSuccess } from '../../assets/svg/check-circle-solid.svg';
import { ReactComponent as IconPaused } from '../../assets/svg/circle-solid.svg';
const constants = {
STATUS_DOWN: 9,
STATUS_UP: 2,
STATUS_PAUSED: 0
};
export default class UptimeRobot extends PureComponent {
static propTypes = {
data: PropTypes.shape({
monitors: PropTypes.arrayOf(
PropTypes.shape({
friendly_name: PropTypes.string,
status: PropTypes.number,
url: PropTypes.string
})
)
})
};
getStatusIcon = status => {
if (status === constants.STATUS_UP) {
return <IconSuccess className="w-4" />;
} else if (status === constants.STATUS_DOWN) {
return <IconError className="w-4" />;
} else {
return <IconPaused className="w-4" />;
}
};
getStatusText = status => {
if (status === constants.STATUS_UP) {
return 'Up';
} else if (status === constants.STATUS_DOWN) {
return 'Down';
} else {
return 'Paused';
}
};
render = () => (
<ul className="box mb-8 flex lg:flex-col flex-wrap">
{this.props.data.monitors.map(({ friendly_name, status, url }) => (
<li className="flex items-center w-1/2 lg:w-full mb-1" key={friendly_name}>
<div
className={classNames({
'mr-2': true,
'text-gray-600': status === constants.STATUS_PAUSED,
'text-green-600': status === constants.STATUS_UP,
'text-red-600': status === constants.STATUS_DOWN
})}
title={this.getStatusText(status)}
>
{this.getStatusIcon(status)}
</div>
<a className="hover:underline" href={url} rel="noopener noreferrer" target="_blank">
{friendly_name}
</a>
</li>
))}
</ul>
);
}