Racks, notes and to-do, OS support, suggested dependencies, Nginx Proxy Manager and Home Assistant
- Racks page and a network diagram (UniFi tree with servers, printable) - Notes on servers and devices; To do list shown in Coming up and My work - Agents report the operating system (Linux 7, Windows 6); end-of-life badge and alert - Suggested dependencies from where a service is reached - Nginx Proxy Manager integration: proxy hosts page, certificate and host alerts, suggested checks - Home Assistant integration: watch chosen entities, history chart, limit and unavailable alerts - TimeChart gets a "value" scale that fits negatives; docs updated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
68b41b5586
commit
18ceed62e8
77 files changed
+20432
-35
No files matched your search
@@ -0,0 +1,99 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type NoteItem } from "../api/client";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import RunbookText from "./RunbookText";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/**
|
||||
* Free-form notes about a server or a network device — what it is, where it sits, what was done to it last time. One text, written with the same small formatting
|
||||
* as a runbook (lists, **bold**, `code`, links). Everyone signed in reads it; operators write it. Emptying it takes the note away.
|
||||
*/
|
||||
export default function NotesCard({ targetType, targetId, canEdit, bare = false }: { targetType: "server" | "device"; targetId: number; canEdit: boolean; /** Without the card round it (inside a drawer). */ bare?: boolean }) {
|
||||
const [note, setNote] = useState<NoteItem | null | undefined>(undefined);
|
||||
const [draft, setDraft] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setNote(undefined);
|
||||
setDraft(null);
|
||||
api.notes
|
||||
.get(targetType, targetId)
|
||||
.then((res) => alive && setNote(res.note))
|
||||
.catch(() => alive && setFailed(true));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [targetType, targetId]);
|
||||
|
||||
async function save() {
|
||||
if (draft === null) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await api.notes.save(targetType, targetId, draft);
|
||||
setNote(res.note);
|
||||
setDraft(null);
|
||||
toast.success(res.note ? "Saved." : "Note removed.");
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const body = failed ? (
|
||||
<div className="text-secondary">Couldn’t load the note.</div>
|
||||
) : note === undefined ? (
|
||||
<BlockSkeleton lines={2} />
|
||||
) : draft !== null ? (
|
||||
<>
|
||||
<textarea className="form-control mb-2" rows={8} maxLength={8000} value={draft} onChange={(e) => setDraft(e.target.value)} aria-label="The note" placeholder={"What is it, where does it sit, what was done to it last time?\n\n- lists, **bold**, `code` and links work"} autoFocus />
|
||||
<div className="d-flex gap-2">
|
||||
<button type="button" className="btn btn-primary" disabled={busy} onClick={() => void save()}>
|
||||
{busy ? "Saving…" : "Save"}
|
||||
</button>
|
||||
<button type="button" className="btn" disabled={busy} onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : note ? (
|
||||
<>
|
||||
<RunbookText text={note.body} />
|
||||
<div className="text-secondary small mt-2">
|
||||
{note.updatedBy ? `${note.updatedBy}, ` : ""}
|
||||
<TimeAgo value={note.updatedAt} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="text-secondary">Nothing written down yet.{canEdit ? " Add what is worth knowing about it." : ""}</div>
|
||||
);
|
||||
|
||||
const edit =
|
||||
canEdit && draft === null && note !== undefined && !failed ? (
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => setDraft(note?.body ?? "")}>
|
||||
{note ? "Edit" : "Write a note"}
|
||||
</button>
|
||||
) : null;
|
||||
|
||||
if (bare) {
|
||||
return (
|
||||
<>
|
||||
{body}
|
||||
{edit && <div className="mt-3">{edit}</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Notes</h3>
|
||||
{edit && <div className="card-actions">{edit}</div>}
|
||||
</div>
|
||||
<div className="card-body">{body}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user