Merge pull request #861 from Tria-plc/freight_feature/usermanagement

Update IntercityCapacity to allow null values and handle formatting i…
This commit is contained in:
marshal
2026-07-21 09:50:49 +03:00
committed by GitHub
2 changed files with 22 additions and 7 deletions

View File

@@ -29,7 +29,10 @@ const parseError = (error: unknown, fallback: string) => {
return message || (error as Error)?.message || fallback;
};
function fmt(n: number): string {
// A capacity axis can be null when the schedule's locomotive has no limit
// configured for it — render "—" instead of crashing on toFixed.
function fmt(n: number | null | undefined): string {
if (n == null) return "—";
return Number.isInteger(n) ? String(n) : n.toFixed(1);
}
@@ -43,13 +46,22 @@ function CapacityBadges({ capacity }: { capacity: IntercityCapacity | null }) {
}
return (
<Group gap="xs">
<Badge variant="light" color={capacity.wagons > 0 ? "teal" : "red"}>
<Badge
variant="light"
color={capacity.wagons == null ? "gray" : capacity.wagons > 0 ? "teal" : "red"}
>
{fmt(capacity.wagons)} wagons free
</Badge>
<Badge variant="light" color={capacity.weightTons > 0 ? "teal" : "red"}>
<Badge
variant="light"
color={capacity.weightTons == null ? "gray" : capacity.weightTons > 0 ? "teal" : "red"}
>
{fmt(capacity.weightTons)} t free
</Badge>
<Badge variant="light" color={capacity.lengthMeters > 0 ? "teal" : "red"}>
<Badge
variant="light"
color={capacity.lengthMeters == null ? "gray" : capacity.lengthMeters > 0 ? "teal" : "red"}
>
{fmt(capacity.lengthMeters)} m free
</Badge>
</Group>

View File

@@ -879,9 +879,12 @@ export interface CompositionRemovalEntry {
// the train's remaining wagon/weight/length capacity.
export interface IntercityCapacity {
wagons: number;
weightTons: number;
lengthMeters: number;
// Each axis can be null when the schedule's train/locomotive has no limit
// configured for it (e.g. no max length on the loco) — the API passes the
// gap through rather than inventing a number.
wagons: number | null;
weightTons: number | null;
lengthMeters: number | null;
}
export interface IntercityBookingRow {