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

debug client: support stop ids in from / to inputs #6133

Merged

Conversation

richardkoszegi
Copy link
Contributor

Summary

Added support for location ids in from/to fields in debug client.

Implementation Details:

  • Added locationConverter: converts strings to Location objects and back based on LocationStringParser class.
  • LocationInputField: a value state introduced for the input field. The new useEffect hook updates this state when location parameter changes. On the onBlur event, this component fires the new onLocationChange event if a valid location can be parsed from the input.
  • SearchBar: updates tripQueryVariables based on the changed location.

@richardkoszegi richardkoszegi requested a review from a team as a code owner October 9, 2024 13:55
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.71%. Comparing base (e595147) to head (bc1bca0).
Report is 79 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6133      +/-   ##
=============================================
- Coverage      69.71%   69.71%   -0.01%     
+ Complexity     17698    17693       -5     
=============================================
  Files           2008     2008              
  Lines          75830    75827       -3     
  Branches        7764     7762       -2     
=============================================
- Hits           52867    52862       -5     
- Misses         20248    20255       +7     
+ Partials        2715     2710       -5     

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


🚨 Try these New Features:

@leonardehrenfried
Copy link
Member

We talked about it and @t2gran has requested that you look up the coordinate of the stop and place the flag icon on the map. Would that be too much to ask?

I personally like this change but @testower is the React expert and needs to review it.

@t2gran t2gran added this to the 2.7 (next release) milestone Oct 16, 2024
@richardkoszegi
Copy link
Contributor Author

We talked about it and @t2gran has requested that you look up the coordinate of the stop and place the flag icon on the map. Would that be too much to ask?

I personally like this change but @testower is the React expert and needs to review it.

I hope it won't be a big change, so it can be implemented in this pr. 🙂

I think I just need to write a stopId -> coordinates resolver using the quay query and call it in the NavigationMarkers component to set the flags.

@@ -29,6 +29,26 @@ export function SearchBar({ onRoute, tripQueryVariables, setTripQueryVariables,
const [showServerInfo, setShowServerInfo] = useState(false);
const target = useRef(null);

const setFromLocation = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is perfectly fine pattern, but we have done it slightly differently - passing tripQueryVariables and setTripQueryVariables into the input components, and calling them there. I suggest keeping to this for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved these functions to the LocationInputField component.

client/src/util/locationConverter.ts Show resolved Hide resolved
@richardkoszegi
Copy link
Contributor Author

I implemented the stopId -> coordinate resolver with the quay query, and it works fine with stops, but not with stop places / stop-areas or any other nodes that have id (eg. vehicle rental stations).

I think it's not the frontend's job to decide, which query has to be called to resolve the coordinates, so it would be nice, if the graphql api has a generic place query, that resolves the coordinates for any id. What do you think about it?

longitude,
latitude,
Copy link
Member

@t2gran t2gran Oct 22, 2024

Choose a reason for hiding this comment

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

My knowledge of JS is limited - but it looks like the arguments order is swapped according to the interface definition above. As a practice to avoid errors I like to always do lat, long never long, lat (doc, params, args, execution order and so on).

Copy link
Contributor

Choose a reason for hiding this comment

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

These are named object properties, order actually doesn't matter. But I agree in principle to keep them consistently ordered anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the order of the params to follow the convention. (Although it wasn't a bug, because I used here the JavaScript's property shorthand syntax).

@testower
Copy link
Contributor

There are still unresolved issues in this PR imho. Maybe need to discuss in developer meeting? Although I'm unable to join until week after next week.

@testower testower added the OTP Debug UI The OTP bundled client label Nov 6, 2024

const LAT_LON_PATTERN = '(' + DOUBLE_PATTERN + ')(\\s*,\\s*|\\s+)(' + DOUBLE_PATTERN + ')';

const ID_SEPARATOR = ':';
Copy link
Member

Choose a reason for hiding this comment

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

Sorry it took me a while to review this, but in the Transmodel API the IDs are not required to have a colon in it (although in practise they very often do).

Do we need the check for the valid feed id? We could simply say that if it's not a coordinate, then it's quay id, couldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the ID checking part, so any input, that not a valid coordinate pair is processed as an ID input.

On the other hand, I needed to implement error handling around the coordinate and trip plan query, because if the id was invalid, the queries threw an error. The simplest fix was a try-catch around them and an error console log (until a more precise error handling is implemented).

@t2gran
Copy link
Member

t2gran commented Nov 18, 2024

I implemented the stopId -> coordinate resolver with the quay query, and it works fine with stops, but not with stop places / stop-areas or any other nodes that have id (eg. vehicle rental stations).

Does the Debug UI lookup stop by name and uses the coordinate for the plan/trip query? If so, that is not what we want - instead the ID of the stop should be used as input to the trip-query. There are differences in the logic on the server when coordinates are provided and stop/station/multi-modal-stops/group-of-stop-plases ids are provided. It is important to be able to test that.

@leonardehrenfried
Copy link
Member

I implemented the stopId -> coordinate resolver with the quay query, and it works fine with stops, but not with stop places / stop-areas or any other nodes that have id (eg. vehicle rental stations).

Does the Debug UI lookup stop by name and uses the coordinate for the plan/trip query? If so, that is not what we want - instead the ID of the stop should be used as input to the trip-query. There are differences in the logic on the server when coordinates are provided and stop/station/multi-modal-stops/group-of-stop-plases ids are provided. It is important to be able to test that.

No, you have to paste the ID of the stop (not station) into the search bar. The lookup is necessary because we want to show a pin on the map, not because we want to know the name.

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

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

I just tried this and can't actually paste anything into the search bars. DOes it work for you, @richardkoszegi ?

@richardkoszegi
Copy link
Contributor Author

I just tried this and can't actually paste anything into the search bars. DOes it work for you, @richardkoszegi ?

Yes, it works for me. (I checked it in Chrome, Firefox, Opera, and Edge). Are the inputs not editable, or the query not runs automatically?

Copy link
Member

@leonardehrenfried leonardehrenfried left a comment

Choose a reason for hiding this comment

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

I must have been stupid. I cannot reproduce, so will approve.

Copy link
Contributor

@testower testower left a comment

Choose a reason for hiding this comment

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

There are still comments that have not been addressed - EDIT: which may be because I didn't submit the review until now 🤦 sorry about that

client/src/components/SearchBar/LocationInputField.tsx Outdated Show resolved Hide resolved
client/src/util/locationConverter.ts Show resolved Hide resolved
client/src/util/locationConverter.ts Show resolved Hide resolved
client/src/util/locationConverter.ts Outdated Show resolved Hide resolved
longitude,
latitude,
Copy link
Contributor

Choose a reason for hiding this comment

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

These are named object properties, order actually doesn't matter. But I agree in principle to keep them consistently ordered anyway.

client/src/util/locationConverter.ts Outdated Show resolved Hide resolved
@testower
Copy link
Contributor

I tested this locally - seems to work as advertised!

@leonardehrenfried leonardehrenfried merged commit 9aed1e3 into opentripplanner:dev-2.x Nov 22, 2024
6 checks passed
@flaktack flaktack deleted the debug-ui-place-id-planning branch November 22, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OTP Debug UI The OTP bundled client Skip Changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants