mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 11:51:14 -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 [isExpanded, setIsExpanded] = useState(false);
|
||||||
const [manualTriggerCount, setManualTriggerCount] = useState(0);
|
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
|
// Create stable reference for item_data to prevent unnecessary re-validations
|
||||||
const itemDataString = useMemo(
|
const itemDataString = useMemo(
|
||||||
() => JSON.stringify(item.item_data),
|
() => JSON.stringify(item.item_data),
|
||||||
@@ -51,7 +68,10 @@ export function ValidationSummary({ item, onValidationChange, compact = false, v
|
|||||||
|
|
||||||
const result = await validateEntityData(
|
const result = await validateEntityData(
|
||||||
item.item_type as ValidEntityType,
|
item.item_type as ValidEntityType,
|
||||||
{ ...item.item_data, id: item.item_data.id || item.id }
|
{
|
||||||
|
...item.item_data,
|
||||||
|
id: getEntityId(item.item_type, item.item_data, item.id)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
setValidationResult(result);
|
setValidationResult(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user