A small translation system (the English text is its own key, so anything without a Swedish entry stays English) and a Language switch in the user menu, saved on the account (users.language) and following the browser when no choice has been made. Swedish covers the menu, shared parts (search, tables, dialogs, relative times), the sign-in page and the everyday pages: Dashboard, Alerts, Servers, Updates, Maintenance, My work, Coming up, To do, Integrations and the display settings. Server-written messages stay English for now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
3.2 KiB
TypeScript
80 lines
3.2 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { IconAlertTriangle, IconCircleCheck, IconEdit, IconTool } from "@tabler/icons-react";
|
|
import { api, type ServerActivityEvent } from "../api/client";
|
|
import { formatDateTime } from "../utils/date";
|
|
import { formatAgo } from "../utils/duration";
|
|
import { BlockSkeleton } from "./Skeleton";
|
|
import { t } from "../i18n";
|
|
|
|
const TONE_CLASS: Record<ServerActivityEvent["tone"], string> = {
|
|
good: "text-green",
|
|
bad: "text-red",
|
|
info: "text-blue",
|
|
neutral: "text-secondary",
|
|
};
|
|
|
|
function EventIcon({ event }: { event: ServerActivityEvent }) {
|
|
const cls = TONE_CLASS[event.tone];
|
|
if (event.kind === "maintenance") return <IconTool size={18} className={cls} aria-hidden="true" />;
|
|
if (event.kind === "health") return event.tone === "good" ? <IconCircleCheck size={18} className={cls} aria-hidden="true" /> : <IconAlertTriangle size={18} className={cls} aria-hidden="true" />;
|
|
return <IconEdit size={18} className={cls} aria-hidden="true" />;
|
|
}
|
|
|
|
/** What has happened to a server, newest first. For operators and admins, since it draws on the audit log. */
|
|
export default function ServerActivity({ serverId }: { serverId: number }) {
|
|
const [events, setEvents] = useState<ServerActivityEvent[] | null>(null);
|
|
const [failed, setFailed] = useState(false);
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
api.servers
|
|
.activity(serverId)
|
|
.then((res) => alive && setEvents(res.events))
|
|
.catch(() => alive && setFailed(true));
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [serverId]);
|
|
|
|
return (
|
|
<div className="card mb-3">
|
|
<div className="card-header">
|
|
<h3 className="card-title">Activity</h3>
|
|
<div className="card-actions">
|
|
<Link to={`/changes?serverId=${serverId}&days=90`} className="small">
|
|
{t("Everything about this server in the change log")}
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div className="card-body">
|
|
{failed ? (
|
|
<div className="text-secondary">{t("Couldn't load the activity.")}</div>
|
|
) : events === null ? (
|
|
<BlockSkeleton lines={4} />
|
|
) : events.length === 0 ? (
|
|
<div className="text-secondary">{t("Nothing recorded yet. Changes to this server, times it stopped reporting, and its maintenance windows will be listed here.")}</div>
|
|
) : (
|
|
<ol className="activity-list">
|
|
{events.map((e, i) => (
|
|
<li key={`${e.at}-${i}`}>
|
|
<EventIcon event={e} />
|
|
<div className="flex-fill" style={{ minWidth: 0 }}>
|
|
<div>
|
|
{e.title}
|
|
{e.actor && <span className="text-secondary"> · {e.actor === "system" ? "automatic" : e.actor}</span>}
|
|
</div>
|
|
{e.detail && <div className="text-secondary small">{e.detail}</div>}
|
|
</div>
|
|
<time className="text-secondary small text-nowrap" dateTime={e.at} title={formatDateTime(new Date(e.at))}>
|
|
{Date.parse(e.at) > Date.now() ? `at ${formatDateTime(new Date(e.at))}` : formatAgo(e.at)}
|
|
</time>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|