-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
cloud_services.jsx
63 lines (60 loc) · 1.76 KB
/
cloud_services.jsx
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
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
})[state.status] || state.status;
const className = "badge " +
(status === OPERATIONAL ? "badge--success" : "badge--warning")
useEffect(() => {
void (async () => {
try {
const parsed = (await (await fetch(api)).json()).status;
const status = typeof parsed === "object" ? parsed.description : parsed;
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>
);
}