Skip to content

Commit 3a0538e

Browse files
committed
front: be able to select a via on the map even when pf failed
1 parent 80973c5 commit 3a0538e

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
6161
>
6262
<small className="font-weight-bold text-muted mr-1">{index + 1}</small>
6363
<small data-testid="via-dropped-name" className="mr-1 text-nowrap">
64-
{`${via.name || `KM ${via.positionOnPath && (Math.round(via.positionOnPath) / 1000000).toFixed(3)}`}`}
64+
{`${via.name || (via.positionOnPath && `KM ${(Math.round(via.positionOnPath) / 1000000).toFixed(3)}`) || `Via n°${index + 1}`}`}
6565
</small>
6666
{via.ch && <small data-testid="via-dropped-ch">{via.ch}</small>}
6767
{'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)