-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
75a99d4
to
4cd0d42
Compare
There was a problem hiding this 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
front/src/modules/pathfinding/components/Itinerary/DisplayItinerary/Vias.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 ^^
front/src/modules/pathfinding/components/Itinerary/DisplayItinerary/Vias.tsx
Outdated
Show resolved
Hide resolved
front/src/modules/pathfinding/components/Itinerary/DisplayItinerary/Vias.tsx
Outdated
Show resolved
Hide resolved
b1b4715
to
5653974
Compare
name, | ||
}; | ||
}); | ||
dispatch(updatePathSteps(updatedSteps)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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).
acc[`87${op.ci}`] = op.name; | ||
acc[op.trigram] = op.name; | ||
acc[op.obj_id] = op.name; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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.
acc[`87${op.ci}`] = op.name; | ||
acc[op.trigram] = op.name; | ||
acc[op.obj_id] = op.name; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
5653974
to
09d32d8
Compare
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.