mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 11:08:12 +00:00
add yard distances management to rule engine
- 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.
This commit is contained in:
@@ -244,7 +244,12 @@ const RuleEngineResourcePage = () => {
|
||||
const { data: wagonTypeOptions, isLoading: wagonTypeOptionsLoading } =
|
||||
useWagonTypeOptions(usesWagonTypeField);
|
||||
const usesYardField = Boolean(
|
||||
config?.formFields.some((f) => f.name === "originYardId"),
|
||||
config?.formFields.some(
|
||||
(f) =>
|
||||
f.name === "originYardId" ||
|
||||
f.name === "fromYardId" ||
|
||||
f.name === "toYardId",
|
||||
),
|
||||
);
|
||||
const { data: yardOptions, isLoading: yardOptionsLoading } =
|
||||
useYardOptions(usesYardField);
|
||||
@@ -347,6 +352,19 @@ const RuleEngineResourcePage = () => {
|
||||
// trade actually sits in, so an import can't be configured as if it
|
||||
// started inland. Resolved per keystroke because the legal set changes
|
||||
// with the direction the admin picks.
|
||||
// Yard-distance endpoints have no country restriction — any yard can pair
|
||||
// with any other; the other end is just excluded so A↔A can't be entered.
|
||||
if (field.name === "fromYardId" || field.name === "toYardId") {
|
||||
const otherEnd = field.name === "fromYardId" ? "toYardId" : "fromYardId";
|
||||
return {
|
||||
...field,
|
||||
type: "select" as const,
|
||||
optionsFromValues: (values: Record<string, unknown>) =>
|
||||
(yardOptions ?? [])
|
||||
.filter(({ value }) => value !== String(values[otherEnd] ?? ""))
|
||||
.map(({ label, value }) => ({ label, value })),
|
||||
};
|
||||
}
|
||||
if (field.name === "originYardId" || field.name === "destinationYardId") {
|
||||
const end = field.name === "originYardId" ? "origin" : "destination";
|
||||
return {
|
||||
@@ -604,7 +622,7 @@ const RuleEngineResourcePage = () => {
|
||||
title={config.label}
|
||||
subtitle={config.subtitle}
|
||||
action={
|
||||
canManage ? (
|
||||
canManage && config.slug !== "container-types" ? (
|
||||
<Button leftSection={<Plus size={18} />} onClick={openCreate}>
|
||||
{addLabel}
|
||||
</Button>
|
||||
|
||||
@@ -348,6 +348,7 @@ export const RULE_ENGINE_RESOURCES: RuleEngineResourceConfig[] = [
|
||||
activeColumn,
|
||||
],
|
||||
formFields: [
|
||||
{ name: "code", label: "Code", type: "text", required: true },
|
||||
{ name: "name", label: "Name", type: "text", required: true },
|
||||
{ name: "capacityTons", label: "Capacity (tons)", type: "number", required: true },
|
||||
{ name: "lengthMeters", label: "Length (meters)", type: "number", required: true },
|
||||
@@ -370,6 +371,34 @@ export const RULE_ENGINE_RESOURCES: RuleEngineResourceConfig[] = [
|
||||
{ name: "isActive", label: "Active", type: "boolean" },
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: "yard-distances",
|
||||
label: "Yard Distances",
|
||||
category: "configuration",
|
||||
subtitle: "Rail distance between yard pairs — routes read their segment km from here",
|
||||
searchPlaceholder: "Search by yard name or code...",
|
||||
supportsSearch: true,
|
||||
cardTitleKey: "fromYardLabel",
|
||||
cardSubtitleKey: "toYardLabel",
|
||||
columns: [
|
||||
{ id: "fromYardLabel", header: "From yard", accessorKey: "fromYardLabel" },
|
||||
{ id: "toYardLabel", header: "To yard", accessorKey: "toYardLabel" },
|
||||
{ id: "distanceKm", header: "Distance (km)", accessorKey: "distanceKm", format: "number" },
|
||||
],
|
||||
formFields: [
|
||||
// Options injected at render from useYardOptions (RuleEngineResourcePage).
|
||||
{ name: "fromYardId", label: "From yard", type: "select", required: true, placeholder: "Select yard" },
|
||||
{ name: "toYardId", label: "To yard", type: "select", required: true, placeholder: "Select yard" },
|
||||
{
|
||||
name: "distanceKm",
|
||||
label: "Distance (km)",
|
||||
type: "number",
|
||||
required: true,
|
||||
description:
|
||||
"Symmetric — one entry covers both directions. Route segments between these yards use this value.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: "priority-configs",
|
||||
label: "Priority Rules",
|
||||
|
||||
Reference in New Issue
Block a user