Skip to content

Commit

Permalink
front: be able to select a via on the map even when pf failed
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahBellaha committed Sep 5, 2024
1 parent 189d404 commit 1b14ae3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"trainScheduleName": "Number, name",
"trainScheduleStep": "Increment step",
"trainUpdated": "Updated train",
"unavailableDistance": "Unavailable distance",
"updateTrainSchedule": "Edit train",
"usingElectricalProfiles": "Use electrical profiles",
"via": "Via",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"trainScheduleName": "Numéro, nom",
"trainScheduleStep": "Pas d'incrément",
"trainUpdated": "Train modifié",
"unavailableDistance": "Distance indisponible",
"updateTrainSchedule": "Modifier le train",
"usingElectricalProfiles": "Utiliser les profils électriques",
"via": "Étape",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { XCircle } from '@osrd-project/ui-icons';
import cx from 'classnames';
import type { Position } from 'geojson';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

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

const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2Props) => {
const { t } = useTranslation('operationalStudies/manageTrainSchedule');
const { getViasV2 } = useOsrdConfSelectors();
const dispatch = useAppDispatch();
const vias = useSelector(getViasV2());
Expand Down Expand Up @@ -61,7 +63,7 @@ const ViasV2 = ({ zoomToFeaturePoint, shouldManageStopDuration }: DisplayViasV2P
>
<small className="font-weight-bold text-muted mr-1">{index + 1}</small>
<small data-testid="via-dropped-name" className="mr-1 text-nowrap">
{`${via.name || `KM ${via.positionOnPath && (Math.round(via.positionOnPath) / 1000000).toFixed(3)}`}`}
{`${via.name || (via.positionOnPath && `KM ${(Math.round(via.positionOnPath) / 1000000).toFixed(3)}`) || t('unavailableDistance')}`}
</small>
{via.ch && <small data-testid="via-dropped-ch">{via.ch}</small>}
{'uic' in via && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ type RenderPopupProps = {
};

function RenderPopup({ pathProperties }: RenderPopupProps) {
const { getFeatureInfoClick, getInfraID } = useOsrdConfSelectors();
const { getFeatureInfoClick, getInfraID, getOriginV2, getDestinationV2 } = useOsrdConfSelectors();
const osrdConfActions = useOsrdConfActions();
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
const featureInfoClick: FeatureInfoClickType = useSelector(getFeatureInfoClick);
const infraId = useSelector(getInfraID);
const origin = useSelector(getOriginV2);
const destination = useSelector(getDestinationV2);

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

Expand Down Expand Up @@ -127,14 +129,18 @@ function RenderPopup({ pathProperties }: RenderPopupProps) {
<RiMapPin2Fill />
<span className="d-none">{t('origin')}</span>
</button>
<button
className="btn btn-sm btn-info"
type="button"
onClick={() => setPointItiV2('via', pathStepProperties, osrdConfActions, pathProperties)}
>
<RiMapPin3Fill />
<span className="d-none">{t('via')}</span>
</button>
{origin && destination && (
<button
className="btn btn-sm btn-info"
type="button"
onClick={() =>
setPointItiV2('via', pathStepProperties, osrdConfActions, pathProperties)
}
>
<RiMapPin3Fill />
<span className="d-none">{t('via')}</span>
</button>
)}
<button
data-testid="map-destination-button"
className="btn btn-sm btn-warning"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import type { ManageTrainSchedulePathProperties } from 'applications/operational
import type { ConfSliceActions } from 'reducers/osrdconf/osrdConfCommon';
import type { PathStep } from 'reducers/osrdconf/types';
import { store } from 'store';
import { addElementAtIndex } from 'utils/array';

export function setPointItiV2(
pointType: 'origin' | 'destination' | 'via',
pathStep: PathStep,
actions: ConfSliceActions,
pathProperties?: ManageTrainSchedulePathProperties
) {
const { updateOriginV2, updateDestinationV2, addViaV2, updateFeatureInfoClick } = actions;
const { updateOriginV2, updateDestinationV2, addViaV2, updatePathSteps, updateFeatureInfoClick } =
actions;
const { pathSteps } = store.getState().operationalStudiesConf;

switch (pointType) {
case 'origin':
Expand All @@ -23,7 +26,11 @@ export function setPointItiV2(
if (pathProperties) {
store.dispatch(addViaV2({ newVia: pathStep, pathProperties }));
} else {
console.error('No pathProperties');
store.dispatch(
updatePathSteps({
pathSteps: addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep),
})
);
}
}
store.dispatch(updateFeatureInfoClick({ displayPopup: false }));
Expand Down

0 comments on commit 1b14ae3

Please sign in to comment.