Skip to content

Commit

Permalink
front: stdcm max speed consist errors
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Nov 7, 2024
1 parent f0edf0f commit 10e5c5f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"negative": "Must be positive.",
"lowerThanTractionEngine": "Must not be less than engine length.",
"lowerThanConsist": "Must not be less than consist length."
},
"maxSpeed": {
"negative": "Must be positive."
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"negative": "Doit être positif.",
"lowerThanTractionEngine": "Ne doit pas être inférieur à la longueur de l'engin de traction.",
"lowerThanConsist": "Ne doit pas être inférieur à la longueur du convoi."
},
"maxSpeed": {
"negative": "Doit être positif."
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ const StdcmConfig = ({
<Button
label={t('simulation.getSimulation')}
onClick={startSimulation}
isDisabled={!!consistErrors.totalMass || !!consistErrors.totalLength}
isDisabled={
!!consistErrors.totalMass ||
!!consistErrors.totalLength ||
!!consistErrors.maxSpeed
}
/>
)}
{formErrors && (
Expand Down
24 changes: 21 additions & 3 deletions front/src/applications/stdcm/components/StdcmForm/StdcmConsist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import classNames from 'classnames';
import { useTranslation } from 'react-i18next';

import useStdcmTowedRollingStock from 'applications/stdcm/hooks/useStdcmTowedRollingStock';
import { validateTotalLength, validateTotalMass } from 'applications/stdcm/utils/consistValidation';
import {
validateMaxSpeed,
validateTotalLength,
validateTotalMass,
} from 'applications/stdcm/utils/consistValidation';
import type { LightRollingStockWithLiveries, TowedRollingStock } from 'common/api/osrdEditoastApi';
import { useOsrdConfActions } from 'common/osrdContext';
import SpeedLimitByTagSelector from 'common/SpeedLimitByTagSelector/SpeedLimitByTagSelector';
Expand Down Expand Up @@ -136,9 +140,10 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => {
updateConsistErrors({
totalMass: totalMassError,
totalLength: totalLengthError,
maxSpeed: validateMaxSpeed(maxSpeed),
})
);
}, [rollingStock, towedRollingStock, totalMass, totalLength]);
}, [rollingStock, towedRollingStock, totalMass, totalLength, maxSpeed]);

return (
<StdcmCard
Expand Down Expand Up @@ -228,7 +233,12 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => {
}
/>
</div>
<div className="stdcm-consist__properties">
<div
className={classNames({
'stdcm-consist__properties': !consistErrors.maxSpeed,
'stdcm-consist_with_errors__properties': !!consistErrors.maxSpeed,
})}
>
<SpeedLimitByTagSelector
disabled={disabled}
selectedSpeedLimitByTag={speedLimitByTag}
Expand All @@ -243,6 +253,14 @@ const StdcmConsist = ({ disabled = false }: StdcmConfigCardProps) => {
min={0}
value={maxSpeed ?? ''}
onChange={onMaxSpeedChange}
statusWithMessage={
consistErrors?.maxSpeed
? {
status: 'error',
message: t(consistErrors.maxSpeed),
}
: undefined
}
/>
</div>
</StdcmCard>
Expand Down
12 changes: 12 additions & 0 deletions front/src/applications/stdcm/utils/consistValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ export const validateTotalLength = (

return undefined;
};

export const validateMaxSpeed = (maxSpeed?: number) => {
if (!maxSpeed) {
return undefined;
}

if (!maxSpeed || maxSpeed < 1) {
return 'consist.errors.maxSpeed.negative';
}

return undefined;
};

0 comments on commit 10e5c5f

Please sign in to comment.