-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathRollingStockHelpers.tsx
89 lines (85 loc) · 2.54 KB
/
RollingStockHelpers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from 'react';
import { IoIosSnow } from 'react-icons/io';
import { ImFire } from 'react-icons/im';
import {
RollingStockComfortType,
LightRollingStock,
RollingStock,
} from 'common/api/osrdEditoastApi';
import { BiLockAlt } from 'react-icons/bi';
const RollingStockUnit = ({ unit, detail }: { unit: string; detail: string }) => {
if (unit && unit !== 'US') {
return <span className={`rollingstock-info-unit ${unit}`}>{unit}</span>;
}
if (detail.search(/UM3/i) !== -1) {
return <span className="rollingstock-info-unit UM3">UM3</span>;
}
if (detail.search(/UM|MUX/i) !== -1) {
return <span className="rollingstock-info-unit UM2">UM2</span>;
}
return null;
};
interface RollingStockInfoProps {
rollingStock: RollingStock | LightRollingStock;
showSeries?: boolean;
showMiddle?: boolean;
showEnd?: boolean;
}
export const RollingStockInfo = ({
rollingStock,
showSeries = true,
showMiddle = true,
showEnd = true,
}: RollingStockInfoProps) => {
const { metadata } = rollingStock;
return (
<div className="d-flex">
{rollingStock.locked && (
<span className="pr-1">
<BiLockAlt />
</span>
)}
<div className="rollingstock-info w-100">
{showSeries ? (
<span className="rollingstock-info-begin">
<span className="rollingstock-info-series">
{metadata.series ? metadata.series : metadata.reference}
</span>
<RollingStockUnit unit={metadata.unit} detail={metadata.detail} />
<span className="rollingstock-info-subseries">
{metadata.series && metadata.series !== metadata.subseries
? metadata.subseries
: metadata.detail}
</span>
</span>
) : null}
{showMiddle && metadata.series ? (
<span className="rollingstock-info-middle">
{`${metadata.family} / ${metadata.type} / ${metadata.grouping}`}
</span>
) : null}
{showEnd ? <span className="rollingstock-info-end">{rollingStock.name}</span> : null}
</div>
</div>
);
};
export function comfort2pictogram(comfort: RollingStockComfortType | undefined) {
switch (comfort) {
case 'AC':
return (
<span className="comfort-AC">
<IoIosSnow />
</span>
);
case 'HEATING':
return (
<span className="comfort-HEATING">
<ImFire />
</span>
);
case 'STANDARD':
return <span className="comfort-STANDARD">S</span>;
default:
return null;
}
}