Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: be able to select a via on the map even when pf failed #8677

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading