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

Refactor Address Suggestion Logic to Improve Readability and Align with Addressing Standards. Fixes #10541 #10561

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all 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
9 changes: 8 additions & 1 deletion modules/ui/fields/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +60 to +61
Copy link
Collaborator

@1ec5 1ec5 Nov 27, 2024

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 prioritizes name:en over name. 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.

: 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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}`;
Expand Down