mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 03:38:17 +00:00
fix search
This commit is contained in:
@@ -41,6 +41,19 @@ export const IMPORT_TRAIN_OPTIONS = Object.values(TRAIN_RUN_PAIRS).map((run) =>
|
||||
value: run,
|
||||
}));
|
||||
|
||||
/**
|
||||
* Options for filtering a list by run — one entry per pair, labelled
|
||||
* "export-import" (8001-8002). The value is the odd EXPORT run, which uniquely
|
||||
* identifies the pair; the API matches a wagon whose export OR import run
|
||||
* equals it, so the whole train's wagons come back.
|
||||
*/
|
||||
export const TRAIN_RUN_FILTER_OPTIONS = Object.entries(TRAIN_RUN_PAIRS).map(
|
||||
([exportRun, importRun]) => ({
|
||||
label: `${exportRun}-${importRun}`,
|
||||
value: exportRun,
|
||||
}),
|
||||
);
|
||||
|
||||
/** The import run implied by an export run; empty string when unset/unknown. */
|
||||
export const importRunFor = (exportRun: unknown): string =>
|
||||
TRAIN_RUN_PAIRS[String(exportRun ?? "")] ?? "";
|
||||
|
||||
@@ -59,6 +59,7 @@ const FleetResourcePage = () => {
|
||||
const status = listFilterValues.status;
|
||||
const currentYardId = listFilterValues.currentYardId;
|
||||
const availability = listFilterValues.availability;
|
||||
const trainNumber = listFilterValues.trainNumber;
|
||||
if (status && status !== "ALL") {
|
||||
(filters as { status?: string }).status = status;
|
||||
}
|
||||
@@ -68,6 +69,9 @@ const FleetResourcePage = () => {
|
||||
if (availability && availability !== "ALL") {
|
||||
(filters as { availability?: string }).availability = availability;
|
||||
}
|
||||
if (trainNumber && trainNumber !== "ALL") {
|
||||
(filters as { trainNumber?: string }).trainNumber = trainNumber;
|
||||
}
|
||||
if (slug !== "locomotives" && search.trim()) {
|
||||
filters.search = search.trim();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { Freight } from "@edr/types";
|
||||
import type { ColumnFormat, FormFieldDef } from "@/pages/ruleEngine/config/resources";
|
||||
import { IMPORT_TRAIN_OPTIONS, exportRunFor } from "@/constants/trainRuns";
|
||||
import {
|
||||
IMPORT_TRAIN_OPTIONS,
|
||||
TRAIN_RUN_FILTER_OPTIONS,
|
||||
exportRunFor,
|
||||
} from "@/constants/trainRuns";
|
||||
import { vehiclesConfig, VEHICLE_TYPE_OPTIONS, FUEL_TYPE_OPTIONS, VEHICLE_STATUS_OPTIONS } from "./vehicles";
|
||||
import { driversConfig, DRIVER_STATUS_OPTIONS } from "./drivers";
|
||||
|
||||
@@ -68,7 +72,7 @@ export interface FleetFormFieldDef extends FormFieldDef {
|
||||
}
|
||||
|
||||
export interface FleetListFilterDef {
|
||||
key: "status" | "availability" | "currentYardId" | "wagonTypeId" | "trainId";
|
||||
key: "status" | "availability" | "currentYardId" | "wagonTypeId" | "trainId" | "trainNumber";
|
||||
label: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
allLabel?: string;
|
||||
@@ -274,6 +278,12 @@ export const FLEET_RESOURCES: FleetResourceConfig[] = [
|
||||
allLabel: "All yards",
|
||||
dynamicOptions: "yards",
|
||||
},
|
||||
{
|
||||
key: "trainNumber",
|
||||
label: "Train number",
|
||||
allLabel: "All trains",
|
||||
options: TRAIN_RUN_FILTER_OPTIONS,
|
||||
},
|
||||
],
|
||||
cardTitleKey: "wagonNumber",
|
||||
cardSubtitleKey: "currentYard",
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface WagonListFilters {
|
||||
currentYardId?: string;
|
||||
wagonTypeId?: string;
|
||||
trainId?: string;
|
||||
/** Run number — matches a wagon whose export OR import run equals it. */
|
||||
trainNumber?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +77,7 @@ export const wagonService = {
|
||||
if (filters.currentYardId) params.set('currentYardId', filters.currentYardId);
|
||||
if (filters.wagonTypeId) params.set('wagonTypeId', filters.wagonTypeId);
|
||||
if (filters.trainId) params.set('trainId', filters.trainId);
|
||||
if (filters.trainNumber) params.set('trainNumber', filters.trainNumber);
|
||||
const qs = params.toString();
|
||||
return apiClient.get<Wagon[]>(`/wagons${qs ? `?${qs}` : ''}`);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user