-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Refactor Address Suggestion Logic to Improve Readability and Align with Addressing Standards. Fixes #10541 #10561
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,14 @@ export function uiFieldAddress(field, context) { | |
dist = geoSphericalDistance(choice.loc, l); | ||
} | ||
|
||
const value = resultProp && d.tags[resultProp] ? d.tags[resultProp] : d.tags.name; | ||
const value = resultProp && d.tags[resultProp] | ||
? d.tags[resultProp] | ||
: d.tags['name:en'] | ||
? d.tags['name:en'] // Fallback to English name | ||
: d.tags.name | ||
? d.tags.name.split(';')[0].trim() // Use the first part of name (split by delimiter `;`) | ||
: null; // Default to null if no valid value exists | ||
Comment on lines
+58
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code would be clearer if you first refactor the line to use if/else statements instead of a ternary. Nested ternaries are very difficult to reason about. (Besides, without parentheses, I wouldn’t know at a glance whether the order of precedence is actually what you’ve implied using whitespace.) |
||
|
||
let title = value; | ||
if (type === 'street') { | ||
title = `${addrField.t('placeholders.street')}: ${title}`; | ||
|
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.
If I’m reading this code correctly, it doesn’t fall back to
name:en
, it prioritizesname:en
overname
. But not every region speaks English; that was just an example I gave. I gave some more details about how you might solve this problem in #10541 (comment). However, the simplest solution may just be to truncate on the first semicolon; we could leave #10541 open to address the linguistic problem separately.