Fix founded year/date handling

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 17:48:52 +00:00
parent 5feee9f4bc
commit b3ffb60ffb
4 changed files with 79 additions and 47 deletions

View File

@@ -6,8 +6,8 @@ import { ArrayFieldDiff } from './ArrayFieldDiff';
import { SpecialFieldDisplay } from './SpecialFieldDisplay';
// Helper to format compact values (truncate long strings)
function formatCompactValue(value: any, maxLength = 30): string {
const formatted = formatFieldValue(value);
function formatCompactValue(value: any, precision?: 'day' | 'month' | 'year', maxLength = 30): string {
const formatted = formatFieldValue(value, precision);
if (formatted.length > maxLength) {
return formatted.substring(0, maxLength) + '...';
}
@@ -20,7 +20,12 @@ interface FieldDiffProps {
}
export function FieldDiff({ change, compact = false }: FieldDiffProps) {
const { field, oldValue, newValue, changeType } = change;
const { field, oldValue, newValue, changeType, metadata } = change;
// Extract precision for date fields
const precision = metadata?.precision;
const oldPrecision = metadata?.oldPrecision;
const newPrecision = metadata?.newPrecision;
// Check if this is an array field that needs special handling
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
@@ -55,7 +60,7 @@ export function FieldDiff({ change, compact = false }: FieldDiffProps) {
if (changeType === 'added') {
return (
<Badge variant="outline" className={getChangeColor()}>
{fieldName}: + {formatCompactValue(newValue)}
{fieldName}: + {formatCompactValue(newValue, precision)}
</Badge>
);
}
@@ -63,7 +68,7 @@ export function FieldDiff({ change, compact = false }: FieldDiffProps) {
if (changeType === 'removed') {
return (
<Badge variant="outline" className={getChangeColor()}>
{fieldName}: <span className="line-through">{formatCompactValue(oldValue)}</span>
{fieldName}: <span className="line-through">{formatCompactValue(oldValue, precision)}</span>
</Badge>
);
}
@@ -71,7 +76,7 @@ export function FieldDiff({ change, compact = false }: FieldDiffProps) {
if (changeType === 'modified') {
return (
<Badge variant="outline" className={getChangeColor()}>
{fieldName}: {formatCompactValue(oldValue)} {formatCompactValue(newValue)}
{fieldName}: {formatCompactValue(oldValue, oldPrecision || precision)} {formatCompactValue(newValue, newPrecision || precision)}
</Badge>
);
}
@@ -89,24 +94,24 @@ export function FieldDiff({ change, compact = false }: FieldDiffProps) {
{changeType === 'added' && (
<div className="text-sm text-green-600 dark:text-green-400">
+ {formatFieldValue(newValue)}
+ {formatFieldValue(newValue, precision)}
</div>
)}
{changeType === 'removed' && (
<div className="text-sm text-red-600 dark:text-red-400 line-through">
{formatFieldValue(oldValue)}
{formatFieldValue(oldValue, precision)}
</div>
)}
{changeType === 'modified' && (
<div className="flex items-center gap-2 text-sm">
<span className="text-red-600 dark:text-red-400 line-through">
{formatFieldValue(oldValue)}
{formatFieldValue(oldValue, oldPrecision || precision)}
</span>
<ArrowRight className="h-3 w-3 text-muted-foreground" />
<span className="text-green-600 dark:text-green-400">
{formatFieldValue(newValue)}
{formatFieldValue(newValue, newPrecision || precision)}
</span>
</div>
)}