mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 05:51:23 -05:00
Fix: Extract correct entity ID for validation
This commit is contained in:
@@ -23,6 +23,23 @@ export function ValidationSummary({ item, onValidationChange, compact = false, v
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [manualTriggerCount, setManualTriggerCount] = useState(0);
|
||||
|
||||
// Helper to extract the correct entity ID based on entity type
|
||||
const getEntityId = (itemType: string, itemData: any, fallbackId?: string): string | undefined => {
|
||||
// Try entity-specific ID fields first
|
||||
const entityIdField = `${itemType}_id`;
|
||||
if (itemData[entityIdField]) {
|
||||
return itemData[entityIdField];
|
||||
}
|
||||
|
||||
// For companies, check company_id
|
||||
if (['manufacturer', 'designer', 'operator', 'property_owner'].includes(itemType) && itemData.company_id) {
|
||||
return itemData.company_id;
|
||||
}
|
||||
|
||||
// Fall back to generic id field or provided fallback
|
||||
return itemData.id || fallbackId;
|
||||
};
|
||||
|
||||
// Create stable reference for item_data to prevent unnecessary re-validations
|
||||
const itemDataString = useMemo(
|
||||
() => JSON.stringify(item.item_data),
|
||||
@@ -49,10 +66,13 @@ export function ValidationSummary({ item, onValidationChange, compact = false, v
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await validateEntityData(
|
||||
item.item_type as ValidEntityType,
|
||||
{ ...item.item_data, id: item.item_data.id || item.id }
|
||||
);
|
||||
const result = await validateEntityData(
|
||||
item.item_type as ValidEntityType,
|
||||
{
|
||||
...item.item_data,
|
||||
id: getEntityId(item.item_type, item.item_data, item.id)
|
||||
}
|
||||
);
|
||||
|
||||
setValidationResult(result);
|
||||
onValidationChange?.(result);
|
||||
|
||||
Reference in New Issue
Block a user