mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 20:10:56 +00:00
booking operations and trains scheduling also allocations
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { Badge, Text } from "@mantine/core";
|
||||
|
||||
import type { ColumnFormat } from "@/pages/ruleEngine/config/resources";
|
||||
import { formatCell as formatRuleEngineCell } from "@/components/ruleEngine/ruleEngineFormat";
|
||||
|
||||
export type FleetColumnFormat = ColumnFormat | "statusBadge";
|
||||
|
||||
const optionLabelMap = new Map<string, Map<string, string>>();
|
||||
|
||||
export const registerFleetOptionLabels = (
|
||||
fieldKey: string,
|
||||
options: { value: string; label: string }[],
|
||||
) => {
|
||||
optionLabelMap.set(fieldKey, new Map(options.map((o) => [o.value, o.label])));
|
||||
};
|
||||
|
||||
export const formatFleetCell = (
|
||||
value: unknown,
|
||||
format?: FleetColumnFormat,
|
||||
accessorKey?: string,
|
||||
): ReactNode => {
|
||||
if (format === "statusBadge") {
|
||||
const status = value == null || value === "" ? "—" : String(value);
|
||||
return (
|
||||
<Badge variant="light" color="gray" size="sm" radius="md">
|
||||
{status}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
||||
if (accessorKey && optionLabelMap.has(accessorKey)) {
|
||||
const label = optionLabelMap.get(accessorKey)?.get(String(value ?? ""));
|
||||
if (label) {
|
||||
return <Text size="sm">{label}</Text>;
|
||||
}
|
||||
}
|
||||
|
||||
return formatRuleEngineCell(value, format as ColumnFormat | undefined);
|
||||
};
|
||||
Reference in New Issue
Block a user