mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 23:28:11 +00:00
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:
@@ -29,7 +29,10 @@ const parseError = (error: unknown, fallback: string) => {
|
|||||||
return message || (error as Error)?.message || fallback;
|
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);
|
return Number.isInteger(n) ? String(n) : n.toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,13 +46,22 @@ function CapacityBadges({ capacity }: { capacity: IntercityCapacity | null }) {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Group gap="xs">
|
<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
|
{fmt(capacity.wagons)} wagons free
|
||||||
</Badge>
|
</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
|
{fmt(capacity.weightTons)} t free
|
||||||
</Badge>
|
</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
|
{fmt(capacity.lengthMeters)} m free
|
||||||
</Badge>
|
</Badge>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -879,9 +879,12 @@ export interface CompositionRemovalEntry {
|
|||||||
// the train's remaining wagon/weight/length capacity.
|
// the train's remaining wagon/weight/length capacity.
|
||||||
|
|
||||||
export interface IntercityCapacity {
|
export interface IntercityCapacity {
|
||||||
wagons: number;
|
// Each axis can be null when the schedule's train/locomotive has no limit
|
||||||
weightTons: number;
|
// configured for it (e.g. no max length on the loco) — the API passes the
|
||||||
lengthMeters: number;
|
// gap through rather than inventing a number.
|
||||||
|
wagons: number | null;
|
||||||
|
weightTons: number | null;
|
||||||
|
lengthMeters: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IntercityBookingRow {
|
export interface IntercityBookingRow {
|
||||||
|
|||||||
Reference in New Issue
Block a user