mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 00:10:57 +00:00
- Introduced new yard distances resource with CRUD operations. - Created migration for yard distances table with necessary constraints. - Implemented service and repository for yard distances handling. - Added controller for API endpoints to manage yard distances. - Updated rule engine configuration to include yard distances. - Enhanced rule engine resource page to support yard distance selection. - Updated contracts and train builder pages to handle new yard distance logic. - Added error handling utility for better error message extraction.
72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import type { CSSProperties } from "react";
|
|
|
|
import type { BuiltTrainStatus } from "@/services/trainBuilder.service";
|
|
|
|
/** Badge color per built-train lifecycle status (Mantine palette keys). */
|
|
export const trainStatusColor = (status: BuiltTrainStatus | string): string => {
|
|
switch (status) {
|
|
case "AVAILABLE":
|
|
return "edr-green";
|
|
case "SCHEDULED":
|
|
return "blue";
|
|
case "IN_SERVICE":
|
|
return "teal";
|
|
case "UNDER_MAINTENANCE":
|
|
return "yellow";
|
|
case "OUT_OF_SERVICE":
|
|
return "red";
|
|
case "DEACTIVATED":
|
|
return "gray";
|
|
default:
|
|
return "gray";
|
|
}
|
|
};
|
|
|
|
export const trainStatusLabel = (status: BuiltTrainStatus | string): string =>
|
|
String(status)
|
|
.toLowerCase()
|
|
.replace(/_/g, " ")
|
|
.replace(/^\w/, (c) => c.toUpperCase());
|
|
|
|
/** Statuses that block a deactivated train from reactivating (mirrors the API gate). */
|
|
export const UNFIT_LOCOMOTIVE_STATUSES = new Set(["MAINTENANCE", "OUT_OF_SERVICE", "UNAVAILABLE"]);
|
|
|
|
/** Badge color per locomotive status (Mantine palette keys). */
|
|
export const locomotiveStatusColor = (status: string): string => {
|
|
switch (status) {
|
|
case "AVAILABLE":
|
|
case "IMPORT_READY":
|
|
case "EXPORT_READY":
|
|
return "edr-green";
|
|
case "ASSIGNED":
|
|
return "blue";
|
|
case "MAINTENANCE":
|
|
return "yellow";
|
|
case "OUT_OF_SERVICE":
|
|
case "UNAVAILABLE":
|
|
return "red";
|
|
default:
|
|
return "gray";
|
|
}
|
|
};
|
|
|
|
export const locomotiveStatusLabel = (status: string): string =>
|
|
String(status)
|
|
.toLowerCase()
|
|
.replace(/_/g, " ")
|
|
.replace(/^\w/, (c) => c.toUpperCase());
|
|
|
|
/** Badge color per trade direction (Mantine palette keys). */
|
|
export const directionColor = (direction?: string | null): string =>
|
|
direction === "IMPORT" ? "blue" : direction === "EXPORT" ? "orange" : "gray";
|
|
|
|
/** Row background tint for a train whose active schedule runs in `direction`. */
|
|
export const directionRowStyle = (
|
|
direction?: string | null,
|
|
): CSSProperties | undefined =>
|
|
direction === "IMPORT"
|
|
? { backgroundColor: "var(--mantine-color-blue-0)" }
|
|
: direction === "EXPORT"
|
|
? { backgroundColor: "var(--mantine-color-orange-0)" }
|
|
: undefined;
|