About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
3.4 KiB
TypeScript
80 lines
3.4 KiB
TypeScript
import { useEffect, useMemo, useState } from "react";
|
|
import { api, type UptimeReport } from "../api/client";
|
|
import RangeSelect from "./RangeSelect";
|
|
import TimeChart from "./TimeChart";
|
|
import { BlockSkeleton } from "./Skeleton";
|
|
import { useChartRange } from "../utils/chartRanges";
|
|
import { t } from "../i18n";
|
|
|
|
const DAY_MS = 24 * 3600_000;
|
|
/** A day of uptime is drawn green when nothing was wrong, amber for some time down, red for most of the day. */
|
|
const dayColor = (v: number) => (v >= 99.9 ? "#2fb344" : v >= 50 ? "#f59f00" : "#f03e3e");
|
|
|
|
/**
|
|
* How a server (or an integration) has done, a day at a time, as far back as the record goes: the share of each day it was up. The thin ribbon on the lists is the
|
|
* last 30 days of the same thing; this is the chart, with a value for any day and a range up to a year.
|
|
*/
|
|
export default function UptimeHistory({ kind, id, name }: { kind: "servers" | "integrations"; id: number; name: string }) {
|
|
const [chosen, setDays] = useChartRange(30);
|
|
// A day is the smallest thing recorded, so 24 hours is not offered here: a chart of a single bar says nothing.
|
|
const days = chosen < 30 ? 30 : chosen;
|
|
const [report, setReport] = useState<UptimeReport | null>(null);
|
|
const [failed, setFailed] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setFailed(false);
|
|
api.uptime
|
|
.get(days)
|
|
.then((res) => alive && setReport(res))
|
|
.catch(() => alive && setFailed(true));
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [days]);
|
|
|
|
const series = report?.[kind][id];
|
|
const to = report ? Date.parse(report.endsAt) : Date.now();
|
|
const lines = useMemo(() => {
|
|
if (!report || !series) return [];
|
|
const end = Date.parse(report.endsAt);
|
|
return [
|
|
{
|
|
name: "Up",
|
|
color: "#2fb344",
|
|
// One point per day with something known about it, in the middle of that day.
|
|
points: series.buckets.flatMap((b, i) => (b.k === 0 ? [] : [{ t: new Date(end - (report.days - i - 0.5) * DAY_MS).toISOString(), v: Math.round((1 - b.d / b.k) * 1000) / 10 }])),
|
|
},
|
|
];
|
|
}, [report, series]);
|
|
|
|
return (
|
|
<div className="card mb-3">
|
|
<div className="card-header d-flex flex-wrap gap-2">
|
|
<h3 className="card-title me-auto">{t("Availability")}</h3>
|
|
<RangeSelect value={days} onChange={setDays} only={[30, 90, 365]} />
|
|
</div>
|
|
<div className="card-body">
|
|
{failed ? (
|
|
<div className="text-secondary">{t("Couldn't load the record.")}</div>
|
|
) : !report ? (
|
|
<BlockSkeleton lines={3} />
|
|
) : !series ? (
|
|
<div className="text-secondary">Nothing is known about {name} in this stretch yet.</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-2">
|
|
<span className="h3 me-2">{series.percent}%</span>
|
|
<span className="text-secondary">{t("up over the last {days} days", { days })}</span>
|
|
</div>
|
|
<TimeChart series={lines} from={to - days * DAY_MS} to={to} bars barColor={dayColor} label={`${name}: share of each day it was up, over the last ${days} days. ${series.percent}% in all.`} />
|
|
<div className="text-secondary small mt-2">
|
|
Worked out from when it stopped reporting and reported again, so it goes back as far as the change log does; days before it was known are left blank.
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|