Skip to content

Commit

Permalink
Don't call formFields.tagsChanged() when presetEditor.tags change
Browse files Browse the repository at this point in the history
(closes #5690)

This change also makes sure to use the latest copy of the entity in
field.isAllowed() to ensure the prerequisite field check works
and fieldsArr is filtered properly for #5583
  • Loading branch information
bhousel committed Jan 11, 2019
1 parent b575ee8 commit 09e5749
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
34 changes: 17 additions & 17 deletions modules/ui/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,38 +231,38 @@ export function uiField(context, presetField, entity, options) {
}
};


// A shown field has a visible UI, a non-shown field is in the 'Add field' dropdown
field.isShown = function() {
return _show || isPresent();
};


// An allowed field can appear in the UI or in the 'Add field' dropdown.
// A non-allowed field is hidden from the user altogether
field.isAllowed = function() {
if (!entity || isPresent()) return true; // a field with a value should always display

if (isPresent()) {
// always allow a field with a value to display
return true;
}
var latest = context.hasEntity(entity.id); // check the most current copy of the entity
if (!latest) return true;

var prerequisiteTag = field.prerequisiteTag;
if (prerequisiteTag && prerequisiteTag.key && field.entityID && context.hasEntity(field.entityID)) {
var value = context.entity(field.entityID).tags[prerequisiteTag.key];
if (value) {
if (prerequisiteTag.valueNot) {
return prerequisiteTag.valueNot !== value;
}
if (prerequisiteTag.value) {
return prerequisiteTag.value === value;
}
return true;
} else {
return false;
var require = field.prerequisiteTag;
if (require && require.key) {
var value = latest.tags[require.key];
if (!value) return false;

if (require.valueNot) {
return require.valueNot !== value;
}
if (require.value) {
return require.value === value;
}
return true;
}
return true;
};


field.focus = function() {
if (field.impl) {
field.impl.focus();
Expand Down
14 changes: 1 addition & 13 deletions modules/ui/form_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@ import { utilGetSetValue, utilNoAuto } from '../util';

export function uiFormFields(context) {
var moreCombo = uiCombobox(context, 'more-fields').minItems(1);
var _selection = d3_select(null);
var _fieldsArr = [];
var _state = '';
var _klass = '';


function formFields(selection) {
_selection = selection
.call(render);
}

formFields.tagsChanged = function() {
_selection
.call(render);
};


function render(selection) {
var allowedFields = _fieldsArr.filter(function(field) { return field.isAllowed(); });
var shown = allowedFields.filter(function(field) { return field.isShown(); });
var notShown = allowedFields.filter(function(field) { return !field.isShown(); });
Expand Down Expand Up @@ -111,7 +99,7 @@ export function uiFormFields(context) {
.on('accept', function (d) {
var field = d.field;
field.show();
render(selection);
selection.call(formFields); // rerender
if (field.type !== 'semiCombo' && field.type !== 'multiCombo') {
field.focus();
}
Expand Down
1 change: 0 additions & 1 deletion modules/ui/preset_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export function uiPresetEditor(context) {
presetEditor.tags = function(val) {
if (!arguments.length) return _tags;
_tags = val;
formFields.tagsChanged();
// Don't reset _fieldsArr here.
return presetEditor;
};
Expand Down

0 comments on commit 09e5749

Please sign in to comment.