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 operational points names display in itinerary #10949

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

RomainValls
Copy link
Contributor

close #10117

The title says the issue happened after a viriato import.
In fact, it was happening with all types of files during import when the name wasn't given in the file.

@RomainValls RomainValls requested a review from a team as a code owner February 25, 2025 09:25
@github-actions github-actions bot added the area:front Work on Standard OSRD Interface modules label Feb 25, 2025
@RomainValls RomainValls requested review from Synar and clarani February 25, 2025 09:25
@RomainValls RomainValls self-assigned this Feb 25, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.89%. Comparing base (4e88804) to head (c8c2869).
Report is 4 commits behind head on dev.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #10949      +/-   ##
==========================================
+ Coverage   80.86%   80.89%   +0.02%     
==========================================
  Files        1118     1119       +1     
  Lines      112736   112894     +158     
  Branches      759      759              
==========================================
+ Hits        91164    91322     +158     
  Misses      21517    21517              
  Partials       55       55              
Flag Coverage Δ
editoast 72.61% <ø> (ø)
front 89.91% <100.00%> (+0.02%) ⬆️
gateway 2.49% <ø> (ø)
osrdyne 2.53% <ø> (ø)
railjson_generator 87.58% <ø> (ø)
tests 88.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RomainValls RomainValls force-pushed the rvs/front-fix-op-name-display branch from 75a99d4 to 4cd0d42 Compare February 25, 2025 09:26
Copy link
Contributor

@clarani clarani left a comment

Choose a reason for hiding this comment

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

Thank you for your PR @RomainValls 🙏

It's exactly what should be done, but I think it might be better to move this code in usePathfinding, what do you think ?
If there is no pathfindingInput, then we should call your code to retrieve the additional data of the path steps, even if we can't launch a pathfinding

Copy link
Contributor

@Synar Synar left a comment

Choose a reason for hiding this comment

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

Nice work, this was an annoying issue indeed ^^

@RomainValls RomainValls force-pushed the rvs/front-fix-op-name-display branch from b1b4715 to 5653974 Compare February 27, 2025 16:24
name,
};
});
dispatch(updatePathSteps(updatedSteps));
Copy link
Member

Choose a reason for hiding this comment

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

As a more general comment: I don't really like the pattern where a useEffect() listens for pathSteps changes, then transforms the data and overwrites path steps again by calling updatePathSteps(). It's very complicated to reason about the data flow (since pathSteps may be mutated basically anywhere in the app) and it might result in infinite feedback loops.

In fact, doesn't this PR make the app search for OPs in an infinite loop?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see a useCallback, not a useEffect, so it should be fine, beyond redefining the function often. Unless you're talking about a different useEffect deeper in the code.

Copy link
Member

Choose a reason for hiding this comment

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

I thought the callback was invoked from a useEffect(), but it seems like that's not the case.

if (!infraId || !pathSteps.length) return;

const searchPayload = buildOpSearchQuery(infraId, [
{ path: pathSteps.filter((step): step is PathStep => step !== null) } as TrainScheduleResult,
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of casting (and sending a value which isn't actually a TrainScheduleResult), we can adapt buildOpSearchQuery() to take as input a list of path steps instead of TrainScheduleResult[] (ideally in a separate commit before this call is added here).

Comment on lines +91 to +93
acc[`87${op.ci}`] = op.name;
acc[op.trigram] = op.name;
acc[op.obj_id] = op.name;
Copy link
Member

Choose a reason for hiding this comment

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

This can result in conflicts: OP IDs might collide with trigrams and UICs.

Moreover, the input list may contain multiple path steps with the same trigram/UIC, but with a different secondary_code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that having 3 dicts/a struct of dicts would be cleaner to avoid collisions, though I'm unsure they're possible in practice.

For the same primary identifier but different secondary code case, won't these steps share the same name though?

Copy link
Member

Choose a reason for hiding this comment

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

They're maybe not happening with the France infrastructure, but may happen if another country decides to use numerical IDs for OP IDs for instance.

For the same primary identifier but different secondary code case, won't these steps share the same name though?

I don't believe that's guaranteed by the data model. Each OP object is independent in the database and has its own name.

Copy link
Member

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 need any kind of map/record here. We can just iterate over all results instead. The number of results should be low™: it cannot exceed the number of path steps.)

} catch (error) {
console.error('Error fetching operational points:', error);
}
}, [infraId, pathSteps]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The caller of this function takes pathSteps as an argument, not a dependency. I believe we should either do the same (using the functional form of set state if we really want to be cautious), or update the dependency array of the caller.

Comment on lines +91 to +93
acc[`87${op.ci}`] = op.name;
acc[op.trigram] = op.name;
acc[op.obj_id] = op.name;
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that having 3 dicts/a struct of dicts would be cleaner to avoid collisions, though I'm unsure they're possible in practice.

For the same primary identifier but different secondary code case, won't these steps share the same name though?


const opMap = results.reduce(
(acc, op) => {
acc[`87${op.ci}`] = op.name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to ignore, but I'm curious, is the 87 in front of a ci to give an uic a sncf thing? Is it something general?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's a sncf thing :/ the pr's uic is 87 + the pr's ci in France (87 is an id for SNCF, see https://fr.wikipedia.org/wiki/Liste_des_codes_pays_UIC)

Copy link
Contributor

@Synar Synar Mar 5, 2025

Choose a reason for hiding this comment

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

Thanks! So ideally we would need to know the op's country in order to correctly match with a path step, but that seems painful.

Another stupid question way beyond this pr, but why do we use a ci to identify each op and not directly an uic in the first place?

@RomainValls RomainValls force-pushed the rvs/front-fix-op-name-display branch from 5653974 to 09d32d8 Compare March 17, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:front Work on Standard OSRD Interface modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Name of waypoints not properly displayed afterViriato import
5 participants