mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 09:30:59 +00:00
Refactor clearance terminology to document approval across services and UI components
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { IMPORT_TRAIN_OPTIONS } from "@/constants/trainRuns";
|
||||
import { api } from "@/services/api";
|
||||
|
||||
/** Dropdown-settings code holding the admin-managed IMPORT run numbers. */
|
||||
@@ -14,10 +13,11 @@ export interface ImportTrainNumberOption {
|
||||
}
|
||||
|
||||
/**
|
||||
* Selectable IMPORT run numbers for the Train Builder, sourced from the
|
||||
* admin-managed `import_train_numbers` dropdown setting (admins add new runs
|
||||
* from the Dropdown Settings editor). Falls back to the legacy hardcoded run
|
||||
* list while the setting is missing or has no options.
|
||||
* Selectable IMPORT run numbers for the Train Builder, sourced solely from the
|
||||
* admin-managed `import_train_numbers` dropdown setting — admins add and remove
|
||||
* runs from /dashboard/dropdown-settings and the pickers follow. There is no
|
||||
* hardcoded fallback on purpose: a missing setting must be visible (see
|
||||
* `settingMissing`) rather than masked by stale defaults.
|
||||
*
|
||||
* Numbers already claimed by an existing train are kept in the list but
|
||||
* disabled and tagged "in use". Pass `currentNumber` when editing a train so
|
||||
@@ -37,14 +37,13 @@ export function useImportTrainNumberOptions(currentNumber?: string | null) {
|
||||
);
|
||||
|
||||
const options = useMemo<ImportTrainNumberOption[]>(() => {
|
||||
const configured = [...(settingQuery.data?.children ?? [])]
|
||||
const base = [...(settingQuery.data?.children ?? [])]
|
||||
.filter((option) => !option.disabled)
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
.map((option) => ({
|
||||
value: option.value,
|
||||
label: option.label || option.value,
|
||||
}));
|
||||
const base = configured.length ? configured : IMPORT_TRAIN_OPTIONS;
|
||||
|
||||
const used = new Set(usedQuery.data?.importTrainNumbers ?? []);
|
||||
if (currentNumber) used.delete(currentNumber);
|
||||
@@ -60,8 +59,16 @@ export function useImportTrainNumberOptions(currentNumber?: string | null) {
|
||||
return items;
|
||||
}, [settingQuery.data, usedQuery.data, currentNumber]);
|
||||
|
||||
const settingMissing = settingQuery.isError;
|
||||
|
||||
return {
|
||||
options,
|
||||
isLoading: settingQuery.isLoading || usedQuery.isLoading,
|
||||
/** True when the dropdown setting is absent — surfaced instead of silently
|
||||
* falling back, so a broken config is visible rather than looking normal. */
|
||||
settingMissing,
|
||||
emptyMessage: settingMissing
|
||||
? `Dropdown setting "${IMPORT_TRAIN_NUMBERS_CODE}" is missing — create it in Dropdown Settings`
|
||||
: "No free run numbers — add more in Dropdown Settings",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user