Skip to content

Commit

Permalink
Avoid calling changeRole recursively
Browse files Browse the repository at this point in the history
(closes #5731)
  • Loading branch information
bhousel committed Jan 18, 2019
1 parent 4e3def9 commit 087c38e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
72 changes: 41 additions & 31 deletions modules/ui/raw_member_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export function uiRawMemberEditor(context) {
.expanded(true)
.updatePreference(false)
.on('toggled', function(expanded) {
if (expanded) { selection.node().parentNode.scrollTop += 200; }
if (expanded) {
selection.node().parentNode.scrollTop += 200;
}
})
.content(content)
);
Expand All @@ -133,26 +135,28 @@ export function uiRawMemberEditor(context) {
.each(unbind)
.remove();

var enter = items.enter()
var itemsEnter = items.enter()
.append('li')
.attr('class', 'member-row form-field')
.classed('member-incomplete', function(d) { return !d.member; });

enter
itemsEnter
.each(function(d) {
if (d.member) {
var item = d3_select(this);

// highlight the member feature in the map while hovering on the list item
d3_select(this).on('mouseover', function() {
utilHighlightEntity(d.id, true, context);
});
d3_select(this).on('mouseout', function() {
utilHighlightEntity(d.id, false, context);
});
var label = item
.append('label')
.attr('class', 'form-field-label');

var label = d3_select(this)
.append('label')
.attr('class', 'form-field-label');
if (d.member) {
// highlight the member feature in the map while hovering on the list item
item
.on('mouseover', function() {
utilHighlightEntity(d.id, true, context);
})
.on('mouseout', function() {
utilHighlightEntity(d.id, false, context);
});

var labelLink = label
.append('span')
Expand All @@ -176,18 +180,14 @@ export function uiRawMemberEditor(context) {

label
.append('button')
.attr('class', 'download-icon')
.attr('class', 'member-zoom')
.attr('title', t('icons.zoom_to'))
.attr('tabindex', -1)
.call(svgIcon('#iD-icon-geolocate'))
.on('click', zoomToMember);

} else {
var incompleteLabel = d3_select(this)
.append('label')
.attr('class', 'form-field-label');

var labelText = incompleteLabel
var labelText = label
.append('span')
.attr('class', 'label-text');

Expand All @@ -201,17 +201,17 @@ export function uiRawMemberEditor(context) {
.attr('class', 'member-entity-name')
.text(t('inspector.incomplete', { id: d.id }));

incompleteLabel
label
.append('button')
.attr('class', 'download-icon')
.attr('class', 'member-download')
.attr('title', t('icons.download'))
.attr('tabindex', -1)
.call(svgIcon('#iD-icon-load'))
.on('click', downloadMember);
}
});

var wrapEnter = enter
var wrapEnter = itemsEnter
.append('div')
.attr('class', 'form-field-input-wrap form-field-input-member');

Expand All @@ -221,24 +221,34 @@ export function uiRawMemberEditor(context) {
.property('type', 'text')
.attr('maxlength', 255)
.attr('placeholder', t('inspector.role'))
.call(utilNoAuto)
.property('value', function(d) { return d.role; })
.on('blur', changeRole)
.on('change', changeRole);
.call(utilNoAuto);

wrapEnter
.append('button')
.attr('tabindex', -1)
.attr('title', t('icons.remove'))
.attr('class', 'remove form-field-button member-delete')
.call(svgIcon('#iD-operation-delete'))
.on('click', deleteMember);
.call(svgIcon('#iD-operation-delete'));

if (taginfo) {
wrapEnter.each(bindTypeahead);
}


// update
items = items
.merge(itemsEnter);

items.select('input.member-role')
.property('value', function(d) { return d.role; })
.on('blur', changeRole)
.on('change', changeRole);

items.select('button.member-delete')
.on('click', deleteMember);



function bindTypeahead(d) {
var row = d3_select(this);
var role = row.selectAll('input.member-role');
Expand Down Expand Up @@ -301,9 +311,9 @@ export function uiRawMemberEditor(context) {
}


rawMemberEditor.entityID = function(_) {
rawMemberEditor.entityID = function(val) {
if (!arguments.length) return _entityID;
_entityID = _;
_entityID = val;
return rawMemberEditor;
};

Expand Down
11 changes: 8 additions & 3 deletions modules/ui/raw_membership_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function uiRawMembershipEditor(context) {
var nearbyCombo = uiCombobox(context, 'parent-relation')
.minItems(1)
.fetcher(fetchNearbyRelations);
var _inChange = false;
var _entityID;
var _showBlank;

Expand All @@ -44,16 +45,20 @@ export function uiRawMembershipEditor(context) {


function changeRole(d) {
if (d === 0) return; // called on newrow (shoudn't happen)
if (d === 0) return; // called on newrow (shoudn't happen)
if (_inChange) return; // avoid accidental recursive call #5731

var oldRole = d.member.role;
var newRole = d3_select(this).property('value');

if (oldRole !== newRole) {
_inChange = true;
context.perform(
actionChangeMember(d.relation.id, _extend({}, d.member, { role: newRole }), d.index),
t('operations.change_role.annotation')
);
}
_inChange = false;
}


Expand Down Expand Up @@ -383,9 +388,9 @@ export function uiRawMembershipEditor(context) {
}


rawMembershipEditor.entityID = function(_) {
rawMembershipEditor.entityID = function(val) {
if (!arguments.length) return _entityID;
_entityID = _;
_entityID = val;
_showBlank = false;
return rawMembershipEditor;
};
Expand Down

0 comments on commit 087c38e

Please sign in to comment.