HR reported it from testing: change someone's address and their history shows "Geänderte Felder: Adresse, Ort" — the new address is on the Stammdaten tab, the old one is nowhere. It was recorded, but only in the audit log, which is a different page sorted by time and actor rather than by person. So you had to already know what you were looking for to find out whether an address had ever changed, let alone what it used to be. The field-by-field diff was being built anyway and written to the audit log. employee_history now carries the same list, and the person's history renders it as an expandable Feld / Vorher / Nachher table — the same table the audit log uses, lifted into a shared component so the two views don't drift into reading differently. It expands with <details>, so the values are in the page: findable with Ctrl+F, present when printed, no script involved. The duplication with audit_log is deliberate. A person's history should be readable on its own, including after the log is eventually thinned by a retention rule. Rows written before today stay without values. They could only be reconstructed from the audit log, and the link is not reliable — no key, only a timestamp and a person. Honestly empty beats plausibly wrong. The migration was generated from the live function definition rather than retyped, and the diff is four lines: two column lists, two value lists. It carries a self-check that raises if either insert failed to pick up the new column, and it was rehearsed inside a rolled-back transaction against real data first — the probe confirmed the old street name lands in the history row. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import type { AuditChange } from "@/lib/supabase/types";
|
|
|
|
// Was sich geändert hat, feldweise — im Protokoll und in der Historie einer
|
|
// Person dieselbe Darstellung. Zwei Ansichten derselben Sache verschieden zu
|
|
// setzen, hiesse dass jemand sie zweimal lesen lernen muss.
|
|
|
|
/** Leerer Wert heisst „war nicht gesetzt“ — und das ist eine Aussage. */
|
|
function Wert({ text, art }: { text: string | null; art: "vorher" | "nachher" }) {
|
|
if (text === null || text === "") {
|
|
return <span className="text-ink-muted italic">leer</span>;
|
|
}
|
|
return <span className={art === "vorher" ? "text-ink-muted line-through decoration-ink-muted/40" : "text-ink"}>{text}</span>;
|
|
}
|
|
|
|
export function AenderungsTabelle({ changes }: { changes: AuditChange[] }) {
|
|
return (
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-sm">
|
|
<thead>
|
|
<tr className="border-b border-border text-left text-[11px] font-bold uppercase tracking-wider text-ink-muted">
|
|
<th className="py-2 pr-4">Feld</th>
|
|
<th className="py-2 pr-4">Vorher</th>
|
|
<th className="py-2">Nachher</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{changes.map((c, i) => (
|
|
<tr key={`${c.feld}-${i}`} className="border-b border-border-subtle align-top last:border-0">
|
|
<td className="py-2 pr-4 font-semibold text-ink-body">{c.feld}</td>
|
|
<td className="py-2 pr-4">
|
|
<Wert text={c.vorher} art="vorher" />
|
|
</td>
|
|
<td className="py-2">
|
|
<Wert text={c.nachher} art="nachher" />
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
);
|
|
}
|