fix: promote vehicle display utils to core with null safety (refs #165)

Create shared getVehicleLabel/getVehicleSubtitle in core/utils with
VehicleLike interface. Replace all direct year/make/model concatenation
across 17 consumer files to prevent null values in vehicle names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eric Gullickson
2026-02-13 19:32:40 -06:00
parent 75e4660c58
commit 325cf08df0
23 changed files with 63 additions and 51 deletions

View File

@@ -0,0 +1,27 @@
/** Vehicle-like object with minimal fields for display purposes */
export interface VehicleLike {
year?: number | null;
make?: string | null;
model?: string | null;
trimLevel?: string | null;
nickname?: string | null;
vin?: string | null;
id?: string | null;
}
/** Primary display name with fallback chain: nickname -> year/make/model -> VIN -> ID */
export const getVehicleLabel = (vehicle: VehicleLike | undefined): string => {
if (!vehicle) return 'Unknown Vehicle';
if (vehicle.nickname?.trim()) return vehicle.nickname.trim();
const parts = [vehicle.year, vehicle.make, vehicle.model, vehicle.trimLevel].filter(Boolean);
if (parts.length > 0) return parts.join(' ');
if (vehicle.vin) return vehicle.vin;
return vehicle.id ? `${vehicle.id.substring(0, 8)}...` : 'Unknown Vehicle';
};
/** Subtitle line: "Year Make Model" with null safety. Returns empty string if insufficient data. */
export const getVehicleSubtitle = (vehicle: VehicleLike | undefined): string => {
if (!vehicle) return '';
const parts = [vehicle.year?.toString(), vehicle.make, vehicle.model].filter(Boolean);
return parts.length >= 2 ? parts.join(' ') : '';
};