Improve component stability and user experience with safety checks

Implement robust error handling, safety checks for data structures, and state management improvements across various components to prevent runtime errors and enhance user experience.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a71e826a-1d38-4b6e-a34f-fbf5ba1f1b25
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-10-08 19:27:31 +00:00
parent f21602b992
commit bfba3baf7e
12 changed files with 224 additions and 110 deletions

View File

@@ -26,6 +26,9 @@ const eventTypeConfig: Record<HistoryEventType, { icon: typeof Tag; color: strin
milestone: { icon: Milestone, color: 'text-pink-500', label: 'Milestone' },
};
// Fallback config for unknown event types
const defaultEventConfig = { icon: Tag, color: 'text-gray-500', label: 'Event' };
export function EntityHistoryTimeline({ events, entityName }: EntityHistoryTimelineProps) {
if (events.length === 0) {
return (
@@ -54,7 +57,10 @@ export function EntityHistoryTimeline({ events, entityName }: EntityHistoryTimel
<div className="absolute left-6 top-0 bottom-0 w-0.5 bg-border" />
{sortedEvents.map((event, index) => {
const config = eventTypeConfig[event.type];
// Safety check: verify event.type exists in eventTypeConfig, use fallback if not
const config = event.type && eventTypeConfig[event.type]
? eventTypeConfig[event.type]
: defaultEventConfig;
const Icon = config.icon;
return (
@@ -105,14 +111,25 @@ export function EntityHistoryTimeline({ events, entityName }: EntityHistoryTimel
}
function formatEventDate(dateString: string): string {
// Safety check: validate dateString exists and is a string
if (!dateString || typeof dateString !== 'string') {
return 'Unknown date';
}
try {
// Handle year-only dates
if (/^\d{4}$/.test(dateString)) {
return dateString;
}
// Handle full dates
// Validate date string before creating Date object
const date = new Date(dateString);
// Check if date is valid
if (isNaN(date.getTime())) {
return dateString;
}
return format(date, 'MMMM d, yyyy');
} catch {
return dateString;