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: fix displayed op on manchette #10334

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -15,38 +15,53 @@ export const upsertMapWaypointsInOperationalPoints = (
t: TFunction
): OperationalPoint[] => {
let waypointCounter = 1;
const HIGHEST_PRIORITY_WEIGHT = 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be outside of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


return path.reduce(
(operationalPointsWithAllWaypoints, step, i) => {
if (!('track' in step)) return operationalPointsWithAllWaypoints;

const positionOnPath = pathItemsPositions[i];
const indexToInsert = operationalPointsWithAllWaypoints.findIndex(
(op) => op.position >= positionOnPath
);

const formattedStep: OperationalPoint = {
id: step.id,
extensions: {
identifier: {
name: t('requestedPoint', { count: waypointCounter }),
uic: 0,
},
},
part: { track: step.track, position: step.offset },
position: positionOnPath,
weight: null,
};

waypointCounter += 1;

// If we can't find any op position greater than the current step position, we add it at the end
if (indexToInsert === -1) {
operationalPointsWithAllWaypoints.push(formattedStep);
} else {
operationalPointsWithAllWaypoints.splice(indexToInsert, 0, formattedStep);
if ('uic' in step) {
const matchedOP = operationalPoints.find(
(op) =>
'uic' in step &&
'secondary_code' in step &&
step.uic === op.extensions?.identifier?.uic &&
step.secondary_code === op.extensions?.sncf?.ch
);
if (matchedOP)
operationalPointsWithAllWaypoints.push({ ...matchedOP, weight: HIGHEST_PRIORITY_WEIGHT });
return operationalPointsWithAllWaypoints;
}

if ('track' in step) {
const positionOnPath = pathItemsPositions[i];
const indexToInsert = operationalPointsWithAllWaypoints.findIndex(
(op) => op.position >= positionOnPath
);

const formattedStep: OperationalPoint = {
id: step.id,
extensions: {
identifier: {
name: t('requestedPoint', { count: waypointCounter }),
uic: 0,
},
},
part: { track: step.track, position: step.offset },
position: positionOnPath,
weight: HIGHEST_PRIORITY_WEIGHT,
};

waypointCounter += 1;

// If we can't find any op position greater than the current step position, we add it at the end
if (indexToInsert === -1) {
operationalPointsWithAllWaypoints.push(formattedStep);
} else {
operationalPointsWithAllWaypoints.splice(indexToInsert, 0, formattedStep);
}

return operationalPointsWithAllWaypoints;
}
return operationalPointsWithAllWaypoints;
},
[...operationalPoints]
Expand Down
3 changes: 0 additions & 3 deletions front/src/modules/pathfinding/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,4 @@ export const isVia = (
{ withKP = false } = {}
) => vias.some((via) => pathStepMatchesOp(via, op, withKP));

export const isStation = (chCode: string): boolean =>
chCode === 'BV' || chCode === '00' || chCode === '';

export const isPathStepInvalid = (step: PathStep | null): boolean => step?.isInvalid || false;
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const ManchetteWithSpaceTimeChartWrapper = ({
position: waypoint.position,
name: waypoint.extensions?.identifier?.name,
secondaryCode: waypoint.extensions?.sncf?.ch,
weight: waypoint.weight ?? 0,
}));
}, [waypointsPanelData, operationalPoints]);

Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where it comes from, but there is a white screen if we try to switch to linear mode in the manchette

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
type TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
import { useOsrdConfSelectors } from 'common/osrdContext';
import { isStation } from 'modules/pathfinding/utils';

const useGetProjectedTrainOperationalPoints = (
trainScheduleUsedForProjection?: TrainScheduleResult,
Expand Down Expand Up @@ -76,14 +75,8 @@ const useGetProjectedTrainOperationalPoints = (
operationalPointsWithUniqueIds = JSON.parse(stringifiedSavedWaypoints) as NonNullable<
PathProperties['operational_points']
>;
} else {
// If the manchette hasn't been saved, we want to display by default only
// the waypoints with CH BV/00/'' and the ones added by map click
operationalPointsWithUniqueIds = operationalPointsWithUniqueIds.filter((op) =>
op.extensions?.sncf ? isStation(op.extensions.sncf.ch) : true
);
}
setFilteredOperationalPoints(operationalPointsWithUniqueIds);
setFilteredOperationalPoints(operationalPointsWithAllWaypoints);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should change this. Otherwise, we won't have any waypoint checked in the waypoint panel.
We should ask @Tguisnet if on linear mode of the manchette, we now want to view all points or just some of them if a weight superior than a specific number etc

}
};
getOperationalPoints();
Expand Down
Loading