Skip to content

Commit

Permalink
front: rename allWaypoints to pathStepsAndSuggestedOPs
Browse files Browse the repository at this point in the history
This list doesn't only contain waypoints, it also contains all
suggested OPs.

Signed-off-by: Simon Ser <contact@emersion.fr>
  • Loading branch information
emersion committed Jan 3, 2025
1 parent 661b5fc commit 53ed0cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ManageTrainScheduleContextType = {
pathfindingState: PathfindingState;
infraInfo: { infra?: InfraWithState; reloadCount: number };
/** Operational points along the path (including origin and destination) and vias added by clicking on map */
allWaypoints?: SuggestedOP[];
pathStepsAndSuggestedOPs?: SuggestedOP[];
} | null;

const ManageTrainScheduleContext = createContext<ManageTrainScheduleContextType>(null);
Expand All @@ -45,7 +45,7 @@ export const ManageTrainScheduleContextProvider = ({
[pathProperties]
);

const allWaypoints = useMemo(() => {
const pathStepsAndSuggestedOPs = useMemo(() => {
if (!pathProperties) return undefined;
return upsertPathStepsInOPs(pathProperties.suggestedOperationalPoints, compact(pathSteps));
}, [pathProperties?.suggestedOperationalPoints, pathSteps]);
Expand All @@ -58,7 +58,7 @@ export const ManageTrainScheduleContextProvider = ({
launchPathfinding,
pathfindingState,
infraInfo,
allWaypoints,
pathStepsAndSuggestedOPs,
}),
[
pathProperties,
Expand All @@ -67,7 +67,7 @@ export const ManageTrainScheduleContextProvider = ({
launchPathfinding,
pathfindingState,
infraInfo,
allWaypoints,
pathStepsAndSuggestedOPs,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type ManageTrainScheduleProps = {

const ManageTrainSchedule = ({ trainIdToEdit }: ManageTrainScheduleProps) => {
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
const { pathProperties, voltageRanges, allWaypoints } = useManageTrainScheduleContext();
const { pathProperties, voltageRanges, pathStepsAndSuggestedOPs } =
useManageTrainScheduleContext();

const { getOrigin, getDestination, getPathSteps } = useOsrdConfSelectors();
const origin = useSelector(getOrigin);
Expand Down Expand Up @@ -120,7 +121,7 @@ const ManageTrainSchedule = ({ trainIdToEdit }: ManageTrainScheduleProps) => {
// If pathProperties is defined we know that pathSteps won't have any null values
content: (
<TimesStopsInput
allWaypoints={allWaypoints}
pathStepsAndSuggestedOPs={pathStepsAndSuggestedOPs}
startTime={new Date(startTime)}
pathSteps={compact(pathSteps)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Itinerary = () => {
const { t } = useTranslation('operationalStudies/manageTrainSchedule');
const { openModal } = useModal();

const { pathProperties, setPathProperties, launchPathfinding, allWaypoints } =
const { pathProperties, setPathProperties, launchPathfinding, pathStepsAndSuggestedOPs } =
useManageTrainScheduleContext();

const zoomToFeaturePoint = (lngLat?: Position) => {
Expand Down Expand Up @@ -119,15 +119,15 @@ const Itinerary = () => {
>
<Route />
</button>
{allWaypoints && (
{pathStepsAndSuggestedOPs && (
<button
data-testid="add-waypoints-button"
className="col ml-1 my-1 text-white btn bg-info btn-sm"
type="button"
onClick={() =>
openModal(
<ModalSuggestedVias
suggestedVias={allWaypoints}
suggestedVias={pathStepsAndSuggestedOPs}
launchPathfinding={launchPathfinding}
/>
)
Expand Down
26 changes: 15 additions & 11 deletions front/src/modules/timesStops/TimesStopsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ type ClearButtonProps = {
removeVia: () => void;
rowIndex: number;
rowData: TimesStopsInputRow;
allWaypoints?: SuggestedOP[];
pathStepsAndSuggestedOPs?: SuggestedOP[];
pathSteps: PathStep[];
};

const createClearViaButton = ({
removeVia,
rowIndex,
rowData,
allWaypoints,
pathStepsAndSuggestedOPs,
pathSteps,
}: ClearButtonProps) => {
const isClearBtnShown =
allWaypoints &&
pathStepsAndSuggestedOPs &&
rowIndex > 0 &&
rowIndex < allWaypoints.length - 1 &&
rowIndex < pathStepsAndSuggestedOPs.length - 1 &&
isVia(pathSteps || [], rowData, { withKP: true }) &&
(!isNil(rowData.stopFor) ||
rowData.theoreticalMargin !== undefined ||
Expand All @@ -59,12 +59,16 @@ const createClearViaButton = ({
};

type TimesStopsInputProps = {
allWaypoints?: SuggestedOP[];
pathStepsAndSuggestedOPs?: SuggestedOP[];
startTime: Date;
pathSteps: PathStep[];
};

const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInputProps) => {
const TimesStopsInput = ({
pathStepsAndSuggestedOPs,
startTime,
pathSteps,
}: TimesStopsInputProps) => {
const dispatch = useAppDispatch();
const { t } = useTranslation('timesStops');
const { updatePathSteps, upsertSeveralViasFromSuggestedOP } =
Expand Down Expand Up @@ -128,10 +132,10 @@ const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInput

useEffect(() => {
const fetchAndFormatRows = async () => {
if (allWaypoints) {
const trackIds = allWaypoints.map((op) => op.track);
if (pathStepsAndSuggestedOPs) {
const trackIds = pathStepsAndSuggestedOPs.map((op) => op.track);
const trackSections = await getTrackSectionsByIds(trackIds);
const suggestedOPsWithTrackNames = allWaypoints.map((op) => ({
const suggestedOPsWithTrackNames = pathStepsAndSuggestedOPs.map((op) => ({
...op,
trackName: trackSections[op.track]?.extensions?.sncf?.track_name,
}));
Expand All @@ -147,7 +151,7 @@ const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInput
};

fetchAndFormatRows();
}, [allWaypoints, pathSteps, startTime]);
}, [pathStepsAndSuggestedOPs, pathSteps, startTime]);

return (
<TimesStops
Expand All @@ -159,7 +163,7 @@ const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInput
removeVia: () => clearPathStep(rowData),
rowIndex,
rowData,
allWaypoints,
pathStepsAndSuggestedOPs,
pathSteps,
}),
}}
Expand Down

0 comments on commit 53ed0cf

Please sign in to comment.