Skip to content

Commit

Permalink
fix the network name being displayed twice
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Sep 22, 2021
1 parent 4979f47 commit a1e4b03
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ 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}"
direction: "{direction}"
network: "{network}"
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.reference().qid);
});

labelEnter
.append('button')
Expand Down
24 changes: 16 additions & 8 deletions modules/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +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 && entity.tags.ref && entity.tags.route) {
return t('inspector.display_name.ref_name', entity.tags);
}
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
9 changes: 8 additions & 1 deletion test/spec/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,16 @@ describe('iD.util', 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 to Midtown', ref: '25L', route: 'bus' }})).to.eql('25L: Lynfield to Midtown');
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

0 comments on commit a1e4b03

Please sign in to comment.