Skip to content

Commit 065d07e

Browse files
committed
front: fix wrong mass value in rs editor conversions
Signed-off-by: Alice Khoudli <[email protected]>
1 parent 9a71fc8 commit 065d07e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

front/src/applications/rollingStockEditor/components/ParametersForm.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ type RollingStockEditorParameterFormProps = {
2626
) => void;
2727
};
2828

29+
type RollingStockEditorParameterFormColumnProps = RollingStockEditorParameterFormProps & {
30+
lastNonZeroMass: MultiUnitsParameter;
31+
setLastNonZeroMass: (lastNonZeroMass: React.SetStateAction<MultiUnitsParameter>) => void;
32+
};
33+
2934
// TODO: make the conditional return clearer
3035
const RollingStockEditorParameterFormColumn = ({
3136
rollingStockValues,
3237
setRollingStockValues,
38+
lastNonZeroMass,
39+
setLastNonZeroMass,
3340
propertiesList,
34-
}: RollingStockEditorParameterFormProps & {
41+
}: RollingStockEditorParameterFormColumnProps & {
3542
propertiesList: SchemaProperty[];
3643
}) => {
3744
const { t } = useTranslation('translation', { keyPrefix: 'rollingStock' });
38-
// The mass is sets by default to its min for a new rolling stock, so it should always be defined on first render
39-
const [lastNonZeroMass, setLastNonZeroMass] = useState(rollingStockValues.mass!);
4045

4146
/** Handle change in value or unit in a multiunit input */
4247
const handleMultiUnitParamChange = <U extends MultiUnit>(
@@ -225,6 +230,8 @@ const RollingStockEditorParameterForm = ({
225230
effortCurves: EffortCurveForms | null;
226231
}) => {
227232
const { t } = useTranslation('translation', { keyPrefix: 'rollingStock' });
233+
// The mass is sets by default to its min for a new rolling stock, so it should always be defined on first render
234+
const [lastNonZeroMass, setLastNonZeroMass] = useState(rollingStockValues.mass!);
228235
const refListOfProperties = Object.keys(RollingStockEditorParameter);
229236

230237
const {
@@ -240,13 +247,17 @@ const RollingStockEditorParameterForm = ({
240247
rollingStockValues={rollingStockValues}
241248
setRollingStockValues={setRollingStockValues}
242249
propertiesList={leftSideList}
250+
lastNonZeroMass={lastNonZeroMass}
251+
setLastNonZeroMass={setLastNonZeroMass}
243252
/>
244253
</div>
245254
<div className="col-xl-4 rollingstock-editor-input-container mb-3">
246255
<RollingStockEditorParameterFormColumn
247256
rollingStockValues={rollingStockValues}
248257
setRollingStockValues={setRollingStockValues}
249258
propertiesList={middleSideList}
259+
lastNonZeroMass={lastNonZeroMass}
260+
setLastNonZeroMass={setLastNonZeroMass}
250261
/>
251262
</div>
252263
<div className="d-flex flex-column justify-content-between col-xl-4 pb-3">
@@ -258,6 +269,8 @@ const RollingStockEditorParameterForm = ({
258269
rollingStockValues={rollingStockValues}
259270
setRollingStockValues={setRollingStockValues}
260271
propertiesList={rightSideList}
272+
lastNonZeroMass={lastNonZeroMass}
273+
setLastNonZeroMass={setLastNonZeroMass}
261274
/>
262275
</div>
263276
</div>

0 commit comments

Comments
 (0)