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

Show ref in the name of route relations #8707

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@ en:
lock:
suggestion: 'The "{label}" field is locked because there is a Wikidata tag. You can delete it or edit the tags in the "Tags" section.'
display_name:
network_ref_name: "{network} {ref}: {name}"
ref_name: "{ref}: {name}"
k-yle marked this conversation as resolved.
Show resolved Hide resolved
direction: "{direction}"
network: "{network}"
from_to: "from {from} to {to}"
Expand Down
2 changes: 1 addition & 1 deletion dist/locales/en.min.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion modules/ui/sections/raw_membership_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ export function uiSectionRawMembershipEditor(context) {
labelLink
.append('span')
.attr('class', 'member-entity-name')
.html(function(d) { return utilDisplayName(d.relation); });
.html(function(d) {
const matched = presetManager.match(d.relation, context.graph());
// hide the network from the name if there is NSI match
return utilDisplayName(d.relation, matched.suggestion);
});

labelEnter
.append('button')
Expand Down
20 changes: 16 additions & 4 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,32 @@ export function utilGetAllNodes(ids, graph) {
}
}


export function utilDisplayName(entity) {
/**
* @param {boolean} hideNetwork If true, the `network` tag will not be used in the name to prevent
* it being shown twice (see PR #8707#discussion_r712658175)
*/
export function utilDisplayName(entity, hideNetwork) {
var localizedNameKey = 'name:' + localizer.languageCode().toLowerCase();
var name = entity.tags[localizedNameKey] || entity.tags.name || '';
if (name) return name;

var tags = {
name,
direction: entity.tags.direction,
from: entity.tags.from,
network: entity.tags.cycle_network || entity.tags.network,
network: hideNetwork ? undefined : (entity.tags.cycle_network || entity.tags.network),
ref: entity.tags.ref,
to: entity.tags.to,
via: entity.tags.via
};

// for routes, prefer `network+ref+name` or `ref+name` over `name`
if (name && tags.ref && entity.tags.route) {
return tags.network
? t('inspector.display_name.network_ref_name', tags)
: t('inspector.display_name.ref_name', tags);
}
if (name) return name;

var keyComponents = [];

if (tags.network) {
Expand Down
14 changes: 14 additions & 0 deletions test/spec/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ describe('iD.util', function() {
it('returns the name if tagged with a name', function() {
expect(iD.utilDisplayName({tags: {name: 'East Coast Greenway'}})).to.eql('East Coast Greenway');
});
it('returns just the name for non-routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Abyssinian Room', ref: '260-115' }})).to.eql('Abyssinian Room');
});
it('returns the name and the ref for routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', route: 'bus' }})).to.eql('25L: Lynfield Express');
expect(iD.utilDisplayName({tags: { name: 'Kāpiti Expressway', ref: 'SH1', route: 'road' }})).to.eql('SH1: Kāpiti Expressway');
});
it('returns the name, ref, and network for routes', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', network: 'AT', route: 'bus' }})).to.eql('AT 25L: Lynfield Express');
});
it('does not use the network tag if the hideNetwork argument is true', function() {
expect(iD.utilDisplayName({tags: { name: 'Lynfield Express', ref: '25L', network: 'AT', route: 'bus' }}, true)).to.eql('25L: Lynfield Express');
expect(iD.utilDisplayName({tags: { network: 'SORTA', ref: '3X' }}, true)).to.eql('3X');
});
it('distinguishes unnamed features by ref', function() {
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
});
Expand Down