Skip to content

Commit 59f2560

Browse files
committed
front: be able to select a via on the map even when pf failed
1 parent 5038159 commit 59f2560

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

front/public/locales/en/operationalStudies/manageTrainSchedule.json

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"trainScheduleName": "Number, name",
141141
"trainScheduleStep": "Increment step",
142142
"trainUpdated": "Updated train",
143+
"unavailableDistance": "Unavailable distance",
143144
"updateTrainSchedule": "Edit train",
144145
"usingElectricalProfiles": "Use electrical profiles",
145146
"via": "Via",

front/public/locales/fr/operationalStudies/manageTrainSchedule.json

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"trainScheduleName": "Numéro, nom",
142142
"trainScheduleStep": "Pas d'incrément",
143143
"trainUpdated": "Train modifié",
144+
"unavailableDistance": "Distance indisponible",
144145
"updateTrainSchedule": "Modifier le train",
145146
"usingElectricalProfiles": "Utiliser les profils électriques",
146147
"via": "Étape",

front/src/modules/pathfinding/components/Itinerary/DisplayItinerary/v2/ViasV2.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { XCircle } from '@osrd-project/ui-icons';
44
import cx from 'classnames';
55
import type { Position } from 'geojson';
66
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
7+
import { useTranslation } from 'react-i18next';
78
import { useSelector } from 'react-redux';
89

910
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
@@ -18,6 +19,7 @@ type DisplayViasV2Props = {
1819
};
1920

2021
const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2Props) => {
22+
const { t } = useTranslation('operationalStudies/manageTrainSchedule');
2123
const { getViasV2 } = useOsrdConfSelectors();
2224
const dispatch = useAppDispatch();
2325
const vias = useSelector(getViasV2());
@@ -61,7 +63,7 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
6163
>
6264
<small className="font-weight-bold text-muted mr-1">{index + 1}</small>
6365
<small data-testid="via-dropped-name" className="mr-1 text-nowrap">
64-
{`${via.name || `KM ${via.positionOnPath && (Math.round(via.positionOnPath) / 1000000).toFixed(3)}`}`}
66+
{`${via.name || (via.positionOnPath && `KM ${(Math.round(via.positionOnPath) / 1000000).toFixed(3)}`) || t('unavailableDistance')}`}
6567
</small>
6668
{via.ch && <small data-testid="via-dropped-ch">{via.ch}</small>}
6769
{'uic' in via && (

front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/RenderPopup.tsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ type RenderPopupProps = {
2929
};
3030

3131
function RenderPopup({ pathProperties }: RenderPopupProps) {
32-
const { getFeatureInfoClick, getInfraID } = useOsrdConfSelectors();
32+
const { getFeatureInfoClick, getInfraID, getOriginV2, getDestinationV2 } = useOsrdConfSelectors();
3333
const osrdConfActions = useOsrdConfActions();
3434
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
3535
const featureInfoClick: FeatureInfoClickType = useSelector(getFeatureInfoClick);
3636
const infraId = useSelector(getInfraID);
37+
const origin = useSelector(getOriginV2);
38+
const destination = useSelector(getDestinationV2);
3739

3840
const [trackOffset, setTrackOffset] = useState(0);
3941

@@ -127,14 +129,18 @@ function RenderPopup({ pathProperties }: RenderPopupProps) {
127129
<RiMapPin2Fill />
128130
<span className="d-none">{t('origin')}</span>
129131
</button>
130-
<button
131-
className="btn btn-sm btn-info"
132-
type="button"
133-
onClick={() => setPointItiV2('via', pathStepProperties, osrdConfActions, pathProperties)}
134-
>
135-
<RiMapPin3Fill />
136-
<span className="d-none">{t('via')}</span>
137-
</button>
132+
{origin && destination && (
133+
<button
134+
className="btn btn-sm btn-info"
135+
type="button"
136+
onClick={() =>
137+
setPointItiV2('via', pathStepProperties, osrdConfActions, pathProperties)
138+
}
139+
>
140+
<RiMapPin3Fill />
141+
<span className="d-none">{t('via')}</span>
142+
</button>
143+
)}
138144
<button
139145
data-testid="map-destination-button"
140146
className="btn btn-sm btn-warning"

front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import type { ManageTrainSchedulePathProperties } from 'applications/operational
33
import type { ConfSliceActions } from 'reducers/osrdconf/osrdConfCommon';
44
import type { PathStep } from 'reducers/osrdconf/types';
55
import { store } from 'store';
6+
import { addElementAtIndex } from 'utils/array';
67

78
export function setPointItiV2(
89
pointType: 'origin' | 'destination' | 'via',
910
pathStep: PathStep,
1011
actions: ConfSliceActions,
1112
pathProperties?: ManageTrainSchedulePathProperties
1213
) {
13-
const { updateOriginV2, updateDestinationV2, addViaV2, updateFeatureInfoClick } = actions;
14+
const { updateOriginV2, updateDestinationV2, addViaV2, updatePathSteps, updateFeatureInfoClick } =
15+
actions;
16+
const { pathSteps } = store.getState().operationalStudiesConf;
1417

1518
switch (pointType) {
1619
case 'origin':
@@ -23,7 +26,11 @@ export function setPointItiV2(
2326
if (pathProperties) {
2427
store.dispatch(addViaV2({ newVia: pathStep, pathProperties }));
2528
} else {
26-
console.error('No pathProperties');
29+
store.dispatch(
30+
updatePathSteps({
31+
pathSteps: addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep),
32+
})
33+
);
2734
}
2835
}
2936
store.dispatch(updateFeatureInfoClick({ displayPopup: false }));

0 commit comments

Comments
 (0)