mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 23:35:42 +00:00
add export/inport number
This commit is contained in:
@@ -271,8 +271,14 @@ const FleetFormDialog = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!validate()) return;
|
if (!validate()) return;
|
||||||
|
// Derived fields are never edited, so form state for them can be stale (or
|
||||||
|
// seeded from the record) — recompute before building the payload.
|
||||||
|
const submitted: Record<string, unknown> = { ...values };
|
||||||
|
fields.forEach((field) => {
|
||||||
|
if (field.derivedValue) submitted[field.name] = field.derivedValue(values);
|
||||||
|
});
|
||||||
const payload = Object.fromEntries(
|
const payload = Object.fromEntries(
|
||||||
Object.entries(values)
|
Object.entries(submitted)
|
||||||
.map(([key, value]) => {
|
.map(([key, value]) => {
|
||||||
if (value === FLEET_SELECT_NONE || value === "")
|
if (value === FLEET_SELECT_NONE || value === "")
|
||||||
return [key, undefined];
|
return [key, undefined];
|
||||||
@@ -294,6 +300,23 @@ const FleetFormDialog = ({
|
|||||||
// only by verification and never hand-edited.
|
// only by verification and never hand-edited.
|
||||||
const isDisabled = Boolean(field.disabled || field.faydaLocked);
|
const isDisabled = Boolean(field.disabled || field.faydaLocked);
|
||||||
|
|
||||||
|
// Computed from other fields (e.g. the import run implied by the export
|
||||||
|
// run) — read-only, and recomputed here rather than read from form state.
|
||||||
|
if (field.derivedValue) {
|
||||||
|
return (
|
||||||
|
<TextInput
|
||||||
|
key={field.name}
|
||||||
|
label={field.label}
|
||||||
|
description={field.description}
|
||||||
|
placeholder={field.placeholder}
|
||||||
|
value={field.derivedValue(values)}
|
||||||
|
readOnly
|
||||||
|
variant="filled"
|
||||||
|
error={error}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (field.type === "radio") {
|
if (field.type === "radio") {
|
||||||
return (
|
return (
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
@@ -319,6 +342,8 @@ const FleetFormDialog = ({
|
|||||||
<Select
|
<Select
|
||||||
key={field.name}
|
key={field.name}
|
||||||
label={field.label}
|
label={field.label}
|
||||||
|
description={field.description}
|
||||||
|
placeholder={field.placeholder}
|
||||||
data={field.options ?? []}
|
data={field.options ?? []}
|
||||||
value={
|
value={
|
||||||
value == null || value === ""
|
value == null || value === ""
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ export interface FleetResourceColumn {
|
|||||||
export interface FleetFormFieldDef extends FormFieldDef {
|
export interface FleetFormFieldDef extends FormFieldDef {
|
||||||
dynamicOptions?: FleetDynamicOptions;
|
dynamicOptions?: FleetDynamicOptions;
|
||||||
noneOption?: boolean;
|
noneOption?: boolean;
|
||||||
|
/**
|
||||||
|
* Read-only field whose value is computed from the other fields rather than
|
||||||
|
* typed. Rendered non-editable and recomputed on every change, so the stored
|
||||||
|
* form value for this field is never trusted — the function is the source of
|
||||||
|
* truth at both render and submit.
|
||||||
|
*/
|
||||||
|
derivedValue?: (values: Record<string, unknown>) => string;
|
||||||
/**
|
/**
|
||||||
* Field is owned by the Fayda identity — populated only by verification and
|
* Field is owned by the Fayda identity — populated only by verification and
|
||||||
* never hand-edited. Rendered disabled in the form.
|
* never hand-edited. Rendered disabled in the form.
|
||||||
@@ -116,6 +123,32 @@ const WAGON_STATUS_OPTIONS = [
|
|||||||
{ label: "Detained", value: Freight.WagonStatus.Detained },
|
{ label: "Detained", value: Freight.WagonStatus.Detained },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EDR run-number pairs, keyed by the odd EXPORT run (Ethiopia → Djibouti). The
|
||||||
|
* even IMPORT run (Djibouti → Ethiopia) is fixed by the export run, so choosing
|
||||||
|
* an export number fully determines the import one. Listed explicitly rather
|
||||||
|
* than computed as export+1, so a pair that ever breaks that convention stays
|
||||||
|
* correct here.
|
||||||
|
*/
|
||||||
|
const TRAIN_RUN_PAIRS: Record<string, string> = {
|
||||||
|
"8001": "8002",
|
||||||
|
"81001": "81002",
|
||||||
|
"82001": "82002",
|
||||||
|
"83001": "83002",
|
||||||
|
"84001": "84002",
|
||||||
|
"85001": "85002",
|
||||||
|
"86001": "86002",
|
||||||
|
"87001": "87002",
|
||||||
|
"88001": "88002",
|
||||||
|
"8901": "8902",
|
||||||
|
"9001": "9002",
|
||||||
|
};
|
||||||
|
|
||||||
|
const EXPORT_TRAIN_OPTIONS = Object.keys(TRAIN_RUN_PAIRS).map((run) => ({
|
||||||
|
label: run,
|
||||||
|
value: run,
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
||||||
@@ -272,13 +305,15 @@ export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
|||||||
],
|
],
|
||||||
formFields: [
|
formFields: [
|
||||||
// Run numbers are optional — a wagon sits in the fleet unassigned to any
|
// Run numbers are optional — a wagon sits in the fleet unassigned to any
|
||||||
// run until an operator fills these in.
|
// run until an operator picks an export run. The import run is fixed by
|
||||||
|
// that choice, so it is derived rather than typed.
|
||||||
{
|
{
|
||||||
name: "exportTrainNumber",
|
name: "exportTrainNumber",
|
||||||
label: "Export train number",
|
label: "Export train number",
|
||||||
type: "text",
|
type: "select",
|
||||||
description: "Odd — Ethiopia → Djibouti runs",
|
description: "Odd — Ethiopia → Djibouti runs",
|
||||||
placeholder: "e.g. 8001",
|
placeholder: "e.g. 8001",
|
||||||
|
options: EXPORT_TRAIN_OPTIONS,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "importTrainNumber",
|
name: "importTrainNumber",
|
||||||
@@ -286,6 +321,8 @@ export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
|||||||
type: "text",
|
type: "text",
|
||||||
description: "Even — Djibouti → Ethiopia runs",
|
description: "Even — Djibouti → Ethiopia runs",
|
||||||
placeholder: "e.g. 8002",
|
placeholder: "e.g. 8002",
|
||||||
|
derivedValue: (values) =>
|
||||||
|
TRAIN_RUN_PAIRS[String(values.exportTrainNumber ?? "")] ?? "",
|
||||||
},
|
},
|
||||||
{ name: "wagonNumber", label: "Wagon number", type: "text", required: true },
|
{ name: "wagonNumber", label: "Wagon number", type: "text", required: true },
|
||||||
{ name: "wagonTypeId", label: "Wagon type", type: "select", required: true, dynamicOptions: "wagonTypes" },
|
{ name: "wagonTypeId", label: "Wagon type", type: "select", required: true, dynamicOptions: "wagonTypes" },
|
||||||
|
|||||||
Reference in New Issue
Block a user