Fix: Detect location changes and new entity creation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-06 14:20:07 +00:00
parent 035f332912
commit 6919f396e6
2 changed files with 72 additions and 7 deletions

View File

@@ -203,16 +203,47 @@ interface LocationDiffProps {
}
export function LocationDiff({ oldLocation, newLocation, compact = false }: LocationDiffProps) {
// Check if we're creating a new location entity
const isCreatingNewLocation = oldLocation?.location_id && !oldLocation?.city && newLocation?.city;
const formatLocation = (loc: any) => {
if (!loc) return 'None';
if (typeof loc === 'string') return loc;
// Handle location_id reference
if (loc.location_id && !loc.city) {
return `Location ID: ${loc.location_id.substring(0, 8)}...`;
}
if (typeof loc === 'object') {
const parts = [loc.city, loc.state_province, loc.country].filter(Boolean);
return parts.join(', ') || 'Unknown';
const parts = [];
if (loc.city) parts.push(loc.city);
if (loc.state_province) parts.push(loc.state_province);
if (loc.country && loc.country !== loc.state_province) parts.push(loc.country);
if (loc.postal_code) parts.push(loc.postal_code);
let locationStr = parts.join(', ') || 'Unknown';
// Add coordinates if available
if (loc.latitude && loc.longitude) {
const lat = Number(loc.latitude).toFixed(6);
const lng = Number(loc.longitude).toFixed(6);
locationStr += ` (${lat}°, ${lng}°)`;
}
return locationStr;
}
return String(loc);
};
// Check if only coordinates changed
const onlyCoordinatesChanged = oldLocation?.city === newLocation?.city &&
oldLocation?.state_province === newLocation?.state_province &&
oldLocation?.country === newLocation?.country &&
oldLocation?.postal_code === newLocation?.postal_code &&
(Number(oldLocation?.latitude) !== Number(newLocation?.latitude) ||
Number(oldLocation?.longitude) !== Number(newLocation?.longitude));
if (compact) {
const oldLoc = formatLocation(oldLocation);
const newLoc = formatLocation(newLocation);
@@ -235,14 +266,24 @@ export function LocationDiff({ oldLocation, newLocation, compact = false }: Loca
return (
<Badge variant="outline" className="text-amber-600 dark:text-amber-400">
Location: {oldLoc} {newLoc}
Location{isCreatingNewLocation && ' (New Entity)'}
{onlyCoordinatesChanged && ' (GPS Refined)'}
: {oldLoc} {newLoc}
</Badge>
);
}
return (
<div className="flex flex-col gap-1 p-2 rounded-md bg-muted/50">
<div className="text-sm font-medium">Location</div>
<div className="text-sm font-medium">
Location
{isCreatingNewLocation && (
<Badge variant="secondary" className="ml-2">New location entity</Badge>
)}
{onlyCoordinatesChanged && (
<Badge variant="outline" className="ml-2">GPS coordinates refined</Badge>
)}
</div>
<div className="flex items-center gap-2 text-sm">
{oldLocation && (