Drafts of every record, previewed on the real page

Migration 077 keeps one draft per record of any entity. Saving a draft
checks it by applying it in a transaction that is rolled back; Preview
opens the record's page in a tab that sends X-Draft-Preview, and the
server answers those reads from a second connection holding the applied
draft, then rolls back, so nobody else sees it. Publish is the ordinary
save, which drops the draft. tx() now nests as a savepoint.

Also commits TODO.md: the answered questions, and parts 1 to 3 moved to
Done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-16 18:21:53 -05:00
parent e4c7e165d1
commit a6c66d4607
13 changed files with 576 additions and 65 deletions

View file

@ -29,6 +29,8 @@ export default function EntityList() {
const [params, setParams] = useSearchParams();
const [rows, setRows] = useState<any[]>([]);
const [total, setTotal] = useState(0);
// Ids with a draft waiting (server/src/drafts.js), marked in the list.
const [drafts, setDrafts] = useState<Set<string>>(() => new Set());
const [loadingMore, setLoadingMore] = useState(false);
const [options, setOptions] = useState<any>({});
const [loading, setLoading] = useState(true);
@ -57,6 +59,7 @@ export default function EntityList() {
]);
setRows(list.rows);
setTotal(list.total);
setDrafts(new Set((list.drafts ?? []).map(String)));
setOptions(opts.options);
} catch (err) {
if (isUnauthorized(err)) return navigate("/admin/login", { replace: true });
@ -203,13 +206,18 @@ export default function EntityList() {
}`}
>
{column.key === linkKey ? (
<Link
to={`/admin/${manifest.key}/${row.id}`}
onClick={(e) => e.stopPropagation()}
className="hover:underline"
>
{row[column.key] || row.id}
</Link>
<>
<Link
to={`/admin/${manifest.key}/${row.id}`}
onClick={(e) => e.stopPropagation()}
className="hover:underline"
>
{row[column.key] || row.id}
</Link>
{drafts.has(String(row.id)) && (
<span className="ml-2 bg-tint px-2 py-0.5 text-xs font-medium text-link">Draft</span>
)}
</>
) : column.widget === "bool" ? (
row[column.key] ? (
"Yes"