-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathRollingStockCardDetail.tsx
203 lines (195 loc) · 7.12 KB
/
RollingStockCardDetail.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { isEmpty } from 'lodash';
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { RollingStockComfortType, RollingStock, osrdEditoastApi } from 'common/api/osrdEditoastApi';
import Loader from 'common/Loader';
import { setFailure } from 'reducers/main';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
import RollingStockCurves from '../RollingStockCurve';
type RollingStockCardDetailProps = {
id: number;
hideCurves?: boolean;
form?: string;
curvesComfortList: RollingStockComfortType[];
setCurvesComfortList: (curvesComfortList: RollingStockComfortType[]) => void;
};
export const listCurvesComfort = (curvesData: RollingStock['effort_curves']) => {
const comfortList: RollingStockComfortType[] = ['STANDARD'];
Object.keys(curvesData.modes).forEach((mode) => {
curvesData.modes[mode].curves.forEach((curve) => {
if (curve.cond?.comfort) {
if (!comfortList.includes(curve.cond.comfort)) comfortList.push(curve.cond.comfort);
}
});
});
return comfortList;
};
export default function RollingStockCardDetail({
id,
hideCurves,
form,
curvesComfortList,
setCurvesComfortList,
}: RollingStockCardDetailProps) {
const dispatch = useDispatch();
const { t } = useTranslation(['rollingstock']);
// we only fetch the whole rollingStock here, when we open the card and display its details
const { data: rollingStock, error } = osrdEditoastApi.useGetRollingStockByRollingStockIdQuery(
{ rollingStockId: id },
{
skip: !id,
}
);
useEffect(() => {
if (rollingStock) setCurvesComfortList(listCurvesComfort(rollingStock.effort_curves));
}, [rollingStock]);
useEffect(() => {
if (error) {
dispatch(
setFailure({
name: t('errorMessages.unableToRetrieveRollingStockMessage'),
message: t('errorMessages.unableToRetrieveRollingStock'),
})
);
}
}, [error]);
return rollingStock && !isEmpty(curvesComfortList) ? (
<div className={form ? 'px-4' : 'rollingstock-card-body'}>
<div className={`row pt-2 ${form}`}>
<div className="col-sm-6">
<table className="rollingstock-details-table">
<tbody>
<tr>
<td className="text-primary">{t('startupTime')}</td>
<td>
{rollingStock.startup_time}
<span className="small ml-1 text-muted">s</span>
</td>
</tr>
<tr>
<td className="text-primary">{t('startupAcceleration')}</td>
<td>
{rollingStock.startup_acceleration}
<span className="small ml-1 text-muted">m/s²</span>
</td>
</tr>
<tr>
<td className="text-primary">{t('comfortAcceleration')}</td>
<td>
{rollingStock.comfort_acceleration}
<span className="small ml-1 text-muted">m/s²</span>
</td>
</tr>
<tr>
<td className="text-primary">{t('inertiaCoefficient')}</td>
<td>{rollingStock.inertia_coefficient}</td>
</tr>
<tr>
<td className="text-primary">{t('gammaValue')}</td>
<td>
{rollingStock.gamma.value * -1}
<span className="small ml-1 text-muted">m/s²</span>
</td>
</tr>
<tr>
<td className="text-primary">{t('loadingGauge')}</td>
<td>{rollingStock.loading_gauge}</td>
</tr>
<tr>
<td className="text-primary">{t('basePowerClass')}</td>
<td>{rollingStock.base_power_class}</td>
</tr>
</tbody>
</table>
</div>
<div className="col-sm-6">
{rollingStock.features && rollingStock.features.length > 0 && (
<div className="pb-1">
{t('features')}
<span className="ml-1">{rollingStock.features.join(', ')}</span>
</div>
)}
{rollingStock.power_restrictions &&
Object.keys(rollingStock.power_restrictions).length !== 0 && (
<table className="rollingstock-details-table mb-1">
<tbody>
<tr>
<td className="text-primary text-nowrap pr-1">
{t('powerRestrictionsInfos', {
count: Object.keys(rollingStock.power_restrictions).length,
})}
</td>
<td>
{rollingStock.power_restrictions !== null &&
Object.keys(rollingStock.power_restrictions).join(' ')}
</td>
</tr>
</tbody>
</table>
)}
<div>
<div className={form ? 'formResistance ml-2' : ''}>{t('rollingResistance')}</div>
<div className={`text-primary text-muted ${form ? 'formResistance ml-4' : ''}`}>
{t('rollingResistanceFormula')}
</div>
</div>
<table className="rollingstock-details-table ml-2">
<tbody>
<tr>
<td>
{Math.floor(
rollingStock.rolling_resistance?.A
? (rollingStock.rolling_resistance.A * 10000) / 10000
: 0
)}
<span className="small ml-1 text-muted">N</span>
</td>
<td className="text-primary">{t('rollingResistanceA')}</td>
</tr>
<tr>
<td>
{Math.floor(
rollingStock.rolling_resistance?.B
? (rollingStock.rolling_resistance.B * 10000) / 10000
: 0
)}
<span className="small ml-1 text-muted">N/(m/s)</span>
</td>
<td className="text-primary">{t('rollingResistanceB')}</td>
</tr>
<tr>
<td>
{Math.floor(
rollingStock.rolling_resistance?.C
? (rollingStock.rolling_resistance.C * 10000) / 10000
: 0
)}
<span className="small ml-1 text-muted">N/(m/s)²</span>
</td>
<td className="text-primary">{t('rollingResistanceC')}</td>
</tr>
</tbody>
</table>
</div>
</div>
{!hideCurves && (
<>
<RollingStockCurves
data={rollingStock.effort_curves.modes}
curvesComfortList={curvesComfortList}
/>
<div className="rollingstock-detail-container-img">
<div className="rollingstock-detail-img">
<RollingStock2Img rollingStock={rollingStock} />
</div>
</div>
</>
)}
</div>
) : (
<div className="rollingstock-card-body">
<Loader />
</div>
);
}