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

Handle both invalid trigrams and uics as invalid op #10471

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from 2 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 @@ -10,6 +10,7 @@ import {
type TrainScheduleResult,
type PathfindingResult,
type SearchResultItemOperationalPoint,
type PathfindingInputError,
} from 'common/api/osrdEditoastApi';
import { useOsrdConfActions } from 'common/osrdContext';
import buildOpSearchQuery from 'modules/operationalPoint/helpers/buildOpSearchQuery';
Expand Down Expand Up @@ -74,8 +75,13 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
const [postSearch] = osrdEditoastApi.endpoints.postSearch.useMutation();

useEffect(() => {
const fetchPathStepsCoordinates = async (trainSchedule: TrainScheduleResult) => {
// get track sections
const fetchPathStepsCoordinates = async (
trainSchedule: TrainScheduleResult,
invalidPathItems: Extract<
PathfindingInputError,
{ error_type: 'invalid_path_items' }
>['items'] = []
) => {
const trackSectionIds: string[] = [];
trainSchedule.path.forEach((step) => {
if ('track' in step) {
Expand All @@ -97,6 +103,7 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
const pathStepsWithCoordinates = trainSchedule.path.map((step, index) => {
let coordinates: Position | undefined;
let name: string | undefined;
let uic: number | undefined;

if ('track' in step) {
const track = tracks[step.track];
Expand All @@ -107,19 +114,21 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
let op: SearchResultItemOperationalPoint | undefined;
if ('uic' in step) {
op = ops.find((o) => o.uic === step.uic);
uic = step.uic;
} else if ('trigram' in step) {
op = ops.find((o) => o.trigram === step.trigram);
} else {
} else if ('operational_point' in step) {
op = ops.find((o) => o.obj_id === step.operational_point);
}
coordinates = op?.geographic.coordinates;
name = `${op?.name}`;
name = `${op?.name || uic?.toString()}`;
emersion marked this conversation as resolved.
Show resolved Hide resolved
}

return {
...computeBasePathStep(trainSchedule, index),
coordinates,
name,
isInvalid: invalidPathItems.some((item) => item.index === index),
};
});

Expand Down Expand Up @@ -153,7 +162,13 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
};
const pathfindingResult = await postPathfindingBlocks(params).unwrap();
if (pathfindingResult.status !== 'success') {
fetchPathStepsCoordinates(trainSchedule);
const invalidPathItems =
pathfindingResult.failed_status === 'pathfinding_input_error' &&
pathfindingResult.error_type === 'invalid_path_items'
? pathfindingResult.items
: [];

fetchPathStepsCoordinates(trainSchedule, invalidPathItems);
return null;
}
const pathPropertiesParams: PostInfraByInfraIdPathPropertiesApiArg = {
Expand Down
Loading