mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
Refactor wagon specifications to rely on wagon type; remove tare weight and max payload from wagon entity and related components
This commit is contained in:
@@ -107,6 +107,10 @@ const normalizePayload = (values: Record<string, FormValue>) =>
|
||||
.filter(([, value]) => value !== '' && !(Array.isArray(value) && value.length === 0)),
|
||||
);
|
||||
|
||||
/** Render a spec value inherited from the wagon type; em dash when the type isn't loaded. */
|
||||
const fmtTypeSpec = (value: number | undefined | null, unit: string) =>
|
||||
value == null ? '—' : `${Number(value)} ${unit}`;
|
||||
|
||||
const extractBackendErrors = (error: unknown) => {
|
||||
const responseData = (error as { response?: { data?: unknown } })?.response?.data;
|
||||
const data = responseData && typeof responseData === 'object' ? responseData as Record<string, unknown> : undefined;
|
||||
@@ -922,7 +926,17 @@ export function WagonsCrudPage() {
|
||||
? `${wagon.currentLocationYard.label ?? wagon.currentLocationYard.code} (${wagon.currentLocationYard.country ?? '-'})`
|
||||
: '-',
|
||||
},
|
||||
{ key: 'maxPayloadWeight', label: 'Max payload' },
|
||||
{
|
||||
// Read-only: the spec lives on the wagon type, so it is displayed, never edited here.
|
||||
key: 'tareWeight',
|
||||
label: 'Tare weight',
|
||||
render: (wagon) => fmtTypeSpec(wagon.wagonType?.tareWeightTons, 't'),
|
||||
},
|
||||
{
|
||||
key: 'maxPayloadWeight',
|
||||
label: 'Max payload',
|
||||
render: (wagon) => fmtTypeSpec(wagon.wagonType?.capacityTons, 't'),
|
||||
},
|
||||
{ key: 'status', label: 'Status', render: (wagon) => statusBadge(wagon.status) },
|
||||
]}
|
||||
fields={[
|
||||
@@ -933,11 +947,6 @@ export function WagonsCrudPage() {
|
||||
type: 'select',
|
||||
required: true,
|
||||
options: wagonTypeOptions,
|
||||
onValueChange: (value, current) => {
|
||||
const selectedType = wagonTypes.find((type: any) => type.id === value);
|
||||
if (!selectedType || Number(current.maxPayloadWeight) > 0) return {};
|
||||
return { maxPayloadWeight: Number(selectedType.capacityTons) };
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'currentLocationYardId',
|
||||
@@ -946,8 +955,6 @@ export function WagonsCrudPage() {
|
||||
required: true,
|
||||
options: yardOptions,
|
||||
},
|
||||
{ key: 'tareWeight', label: 'Tare weight', type: 'number', required: true },
|
||||
{ key: 'maxPayloadWeight', label: 'Max payload weight', type: 'number', required: true },
|
||||
{
|
||||
key: 'status',
|
||||
label: 'Status',
|
||||
@@ -963,7 +970,7 @@ export function WagonsCrudPage() {
|
||||
},
|
||||
{ key: 'notes', label: 'Notes' },
|
||||
]}
|
||||
emptyValues={{ wagonNumber: '', wagonTypeId: '', currentLocationYardId: '', tareWeight: 0, maxPayloadWeight: 0, status: 'AVAILABLE', notes: '' }}
|
||||
emptyValues={{ wagonNumber: '', wagonTypeId: '', currentLocationYardId: '', status: 'AVAILABLE', notes: '' }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -263,17 +263,16 @@ export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
||||
cardSubtitleKey: "currentYard",
|
||||
searchKeys: ["wagonNumber", "wagonTypeId", "trainId", "status", "currentYardId"],
|
||||
columns: [
|
||||
// Tare weight and payload capacity are not wagon columns — they belong to the
|
||||
// wagon type and are shown through it (see WagonsCrudPage in FleetCrudPages).
|
||||
{ id: "wagonNumber", header: "Number", accessorKey: "wagonNumber", format: "code" },
|
||||
{ id: "wagonTypeId", header: "Type", accessorKey: "wagonTypeId", format: "entityLabel" },
|
||||
{ id: "maxPayloadWeight", header: "Max payload", accessorKey: "maxPayloadWeight", format: "number" },
|
||||
{ id: "currentYard", header: "Current Yard", accessorKey: "currentYard", format: "entityLabel" },
|
||||
{ id: "status", header: "Status", accessorKey: "status", format: "statusBadge" },
|
||||
],
|
||||
formFields: [
|
||||
{ name: "wagonNumber", label: "Wagon number", type: "text", required: true },
|
||||
{ name: "wagonTypeId", label: "Wagon type", type: "select", required: true, dynamicOptions: "wagonTypes" },
|
||||
{ name: "tareWeight", label: "Tare weight", type: "number", required: true },
|
||||
{ name: "maxPayloadWeight", label: "Max payload weight", type: "number", required: true },
|
||||
{ name: "currentYardId", label: "Current Yard", type: "select", dynamicOptions: "yards" },
|
||||
{ name: "status", label: "Status", type: "select", required: true, options: WAGON_STATUS_OPTIONS },
|
||||
{ name: "notes", label: "Notes", type: "textarea" },
|
||||
@@ -281,8 +280,6 @@ export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
||||
emptyValues: {
|
||||
wagonNumber: "",
|
||||
wagonTypeId: "",
|
||||
tareWeight: 0,
|
||||
maxPayloadWeight: 0,
|
||||
currentYardId: "",
|
||||
status: Freight.WagonStatus.Available,
|
||||
notes: "",
|
||||
|
||||
Reference in New Issue
Block a user