/** * HistoryDiff — Visual diff table of field changes for an entity history entry. * Shows old value (red strikethrough) → new value (green) per field. */ import React from 'react'; import clsx from 'clsx'; import { ArrowRight } from 'lucide-react'; import { useTranslation } from 'react-i18next'; export interface HistoryDiffProps { changes: Record; className?: string; } /** * Format a value for display, handling null/undefined gracefully. */ function formatValue(value: any): string { if (value === null || value === undefined) { return '—'; } if (typeof value === 'boolean') { return value ? 'true' : 'false'; } if (typeof value === 'object') { try { return JSON.stringify(value); } catch { return String(value); } } return String(value); } export function HistoryDiff({ changes, className }: HistoryDiffProps) { const { t } = useTranslation(); const entries = Object.entries(changes); if (entries.length === 0) { return (

{t('entityHistory.noChanges', 'Keine Änderungen')}

); } return (
{entries.map(([field, change]) => { const oldDisplay = formatValue(change.old); const newDisplay = formatValue(change.new); const isOldEmpty = change.old === null || change.old === undefined; const isNewEmpty = change.new === null || change.new === undefined; return ( ); })}
{t('entityHistory.field', 'Feld')} {t('entityHistory.oldValue', 'Alter Wert')} {t('entityHistory.newValue', 'Neuer Wert')}
{field} {oldDisplay} {newDisplay}
); }