Show the to-do list down the dashboard's right-hand side

A To do card lists every open job beside the attention, since-you-last-looked
and getting-started cards on wide screens (under them on narrow ones): soonest
due first, a box to tick one off with an undo, and for operators a line to add
one. It is as tall as the cards beside it and scrolls when the list is long.
Same jobs as the To do page.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 01:30:12 +01:00
1 parent a15bbf1303
commit 2b0623531a
5 files changed
+173 -2

No files matched your search

+133
View File
@@ -0,0 +1,133 @@
import { useCallback, useEffect, useState, type FormEvent } from "react";
import { Link } from "react-router-dom";
import { api, type TodoItem } from "../api/client";
import { dueWords } from "../pages/Todo";
import { BlockSkeleton } from "./Skeleton";
import { refreshMyWork } from "../hooks/useMyWork";
import { readableError } from "../utils/errors";
import { toast } from "../utils/toast";
/**
* Every open job on the to-do list, soonest due first, beside the cards at the top of the dashboard: a box to tick one off (with an undo) and, for operators, a line to add another. It is the
* same list as the To do page — which has who each is handed to, the details and the finished ones — and is read again every minute, and after anything done here.
*/
export default function DashboardTodos({ canEdit }: { canEdit: boolean }) {
const [jobs, setJobs] = useState<TodoItem[] | null>(null);
const [failed, setFailed] = useState(false);
const [title, setTitle] = useState("");
const [due, setDue] = useState("");
const [busy, setBusy] = useState(false);
const load = useCallback(
() =>
api.todos
.list()
.then((res) => {
setJobs(res.todos.filter((t) => !t.doneAt));
setFailed(false);
})
.catch(() => setFailed(true)),
[],
);
useEffect(() => {
void load();
const t = setInterval(() => void load(), 60_000);
return () => clearInterval(t);
}, [load]);
async function add(e: FormEvent) {
e.preventDefault();
if (title.trim() === "" || busy) return;
setBusy(true);
try {
await api.todos.create({ title: title.trim(), dueDate: due || null });
setTitle("");
setDue("");
await load();
refreshMyWork();
} catch (err) {
toast.error(readableError(err));
} finally {
setBusy(false);
}
}
async function tick(t: TodoItem) {
try {
await api.todos.update(t.id, { done: true });
toast.success(`Done: ${t.title}`, {
label: "Undo",
onClick: async () => {
try {
await api.todos.update(t.id, { done: false });
} catch (err) {
toast.error(readableError(err));
} finally {
void load();
refreshMyWork();
}
},
});
await load();
refreshMyWork();
} catch (err) {
toast.error(readableError(err));
}
}
return (
<div className="card dash-todos">
<div className="card-header">
<h3 className="card-title">To do{jobs && jobs.length > 0 ? ` (${jobs.length})` : ""}</h3>
<div className="card-actions small">
<Link to="/todo">All jobs</Link>
</div>
</div>
<div className="dash-todos-list">
{failed && jobs === null ? (
<div className="card-body text-secondary">Couldn&rsquo;t load the jobs.</div>
) : jobs === null ? (
<div className="card-body">
<BlockSkeleton lines={3} />
</div>
) : jobs.length === 0 ? (
<div className="card-body text-secondary">Nothing to do.{canEdit ? " Add a job below." : ""}</div>
) : (
<ul className="list-group list-group-flush">
{jobs.map((t) => {
const d = dueWords(t);
return (
<li key={t.id} className="list-group-item d-flex gap-3 align-items-start">
<input type="checkbox" className="form-check-input mt-1" aria-label={`Done: ${t.title}`} disabled={!canEdit} checked={false} onChange={() => void tick(t)} />
<div className="me-auto">
<div className="fw-bold">{t.title}</div>
{t.detail && (
<div className="text-secondary small" style={{ whiteSpace: "pre-wrap" }}>
{t.detail}
</div>
)}
<div className="small d-flex flex-wrap gap-2 mt-1">
{d && <span className={d.className}>{d.text}</span>}
{t.assignee && <span className="badge bg-blue-lt text-blue">{t.assignee.name}</span>}
{t.target && <Link to={t.target.type === "server" ? `/servers/${t.target.id}` : "/network/devices"}>{t.target.name}</Link>}
</div>
</div>
</li>
);
})}
</ul>
)}
</div>
{canEdit && (
<form className="card-footer d-flex flex-wrap gap-2" onSubmit={(e) => void add(e)}>
<input className="form-control flex-fill" style={{ minWidth: "10rem", width: "auto" }} maxLength={160} value={title} onChange={(e) => setTitle(e.target.value)} placeholder="Add a job…" aria-label="A job to add" />
<input type="date" className="form-control w-auto" value={due} onChange={(e) => setDue(e.target.value)} aria-label="Due day (optional)" />
<button type="submit" className="btn btn-primary" disabled={busy || title.trim() === ""}>
Add
</button>
</form>
)}
</div>
);
}
+9
View File
@@ -3,6 +3,7 @@ import { Fragment, isValidElement, useEffect, useState, type ReactNode } from "r
import { IconArrowLeft, IconArrowRight, IconEye, IconEyeOff } from "@tabler/icons-react";
import TimeAgo from "../components/TimeAgo";
import WhatChanged from "../components/WhatChanged";
import DashboardTodos from "../components/DashboardTodos";
import { setProblemsFirst, useProblemsFirst } from "../utils/problemsFirst";
import { UNPLACED, moveCard, resetDashboardLayout, setCardHidden, setEditingDashboard, useDashboardLayout } from "../utils/dashboardLayout";
import { Link } from "react-router-dom";
@@ -730,6 +731,11 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
<p className="text-secondary">
Welcome back, {user.name ?? user.email ?? user.sub}.
</p>
</div>
</div>
<div className="row row-cards mb-3">
<div className="col-xl-6">
<StatusStrip />
{(user.role === "admin" || user.role === "operator") && <MyWorkStrip />}
<WhatChanged role={user.role} />
@@ -737,6 +743,9 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
<SetupGuide steps={setupSteps} />
)}
</div>
<div className="col-xl-6 dash-side">
<DashboardTodos canEdit={user.role === "admin" || user.role === "operator"} />
</div>
</div>
<SectionHeader title="Overview" hint="DNS, Secrets, Servers and Domains are built into this app rather than connected integrations, but get the same at-a-glance treatment." />
+29
View File
@@ -1986,3 +1986,32 @@ tr.alert-row-child > td:first-child {
font-size: 0.875rem;
color: var(--tblr-secondary);
}
/* ── The dashboard's right-hand column: the to-do list as tall as the cards beside it (wide screens), a scrolling card of its own under them (narrow ones). ── */
.dash-side {
min-height: 24rem;
}
.dash-todos {
max-height: 32rem;
margin-bottom: 1rem;
}
.dash-todos-list {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
}
@media (min-width: 1200px) {
.dash-side {
position: relative;
}
.dash-todos {
position: absolute;
inset: 0 calc(var(--tblr-gutter-x, 1.5rem) / 2) 0;
max-height: none;
margin-bottom: 0;
}
}