-
-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathcloud_services.jsx
More file actions
69 lines (66 loc) · 1.98 KB
/
cloud_services.jsx
File metadata and controls
69 lines (66 loc) · 1.98 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
import { urls } from "@site/src/constants";
import { React, useEffect, useState } from "react";
import styles from "./styles.module.css";
const OPERATIONAL = "All Systems Operational";
export default function CloudServices({ onLoad, style }) {
useEffect(() => onLoad?.(), []);
return (
<div className="card margin-top--xs" style={style}>
<div className="card__header">
<h3>Cloud Services</h3>
</div>
<div className="card__body">
<table style={{ fontSize: "small" }}>
<tbody>
{Object.keys(urls.cloud).map((service, index) =>
<Status key={index} {...urls.cloud[service]} />
)}
</tbody>
</table>
</div>
</div>
);
}
function Status({ api, link, title }) {
const [state, setState] = useState({ status: "..." });
const status = ({
OPERATIONAL,
"Everything is looking good": OPERATIONAL,
"operational": OPERATIONAL,
"success": OPERATIONAL
})[state.status] || state.status;
const className = "badge " +
(status === OPERATIONAL ? "badge--success" : "badge--warning")
useEffect(() => {
void (async () => {
try {
const json = (await (await fetch(api)).json());
const status =
typeof json.status === "object" // support StatusPage API
? json.status.description
: typeof json.monitor === "object" // support UptimeRobot API
? json.monitor.statusClass
: json.status || "unknown";
setState({ status });
} catch (error) {
console.warn(`error fetching data for ${title} – ${api}`, error);
}
})();
}, []);
return (
<tr>
<td>
<a href={link} style={{ display: "inline-block", minWidth: "100%" }}>
{title}
</a>
</td>
<td>
<span className={className} style={{
display: "inline-block",
minWidth: "100%",
textAlign: "center"
}}>{status}</span>
</td>
</tr>
);
}