mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 03:51:12 -05:00
Fix founded year/date handling
This commit is contained in:
@@ -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>
|
||||
)}
|
||||
|
||||
@@ -186,6 +186,11 @@ function StatusFieldDisplay({ change, compact }: { change: FieldChange; compact:
|
||||
}
|
||||
|
||||
function DateFieldDisplay({ change, compact }: { change: FieldChange; compact: boolean }) {
|
||||
// Extract precision from metadata
|
||||
const precision = change.metadata?.precision;
|
||||
const oldPrecision = change.metadata?.oldPrecision;
|
||||
const newPrecision = change.metadata?.newPrecision;
|
||||
|
||||
if (compact) {
|
||||
return (
|
||||
<Badge variant="outline" className="text-teal-600 dark:text-teal-400">
|
||||
@@ -204,29 +209,34 @@ function DateFieldDisplay({ change, compact }: { change: FieldChange; compact: b
|
||||
<div className="text-sm font-medium flex items-center gap-2">
|
||||
<Calendar className="h-4 w-4" />
|
||||
{formatFieldName(change.field)}
|
||||
{precision && (
|
||||
<Badge variant="outline" className="text-xs ml-2">
|
||||
{precision === 'year' ? 'Year Only' : precision === 'month' ? 'Month & Year' : 'Full Date'}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{change.changeType === 'modified' && (
|
||||
<div className="flex items-center gap-3 text-sm">
|
||||
<span className="text-red-600 dark:text-red-400 line-through">
|
||||
{formatFieldValue(change.oldValue)}
|
||||
{formatFieldValue(change.oldValue, oldPrecision || precision)}
|
||||
</span>
|
||||
<ArrowRight className="h-3 w-3 text-muted-foreground" />
|
||||
<span className="text-green-600 dark:text-green-400">
|
||||
{formatFieldValue(change.newValue)}
|
||||
{formatFieldValue(change.newValue, newPrecision || precision)}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{change.changeType === 'added' && (
|
||||
<div className="text-sm text-green-600 dark:text-green-400">
|
||||
+ {formatFieldValue(change.newValue)}
|
||||
+ {formatFieldValue(change.newValue, precision)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{change.changeType === 'removed' && (
|
||||
<div className="text-sm text-red-600 dark:text-red-400 line-through">
|
||||
{formatFieldValue(change.oldValue)}
|
||||
{formatFieldValue(change.oldValue, precision)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user