From 78f94632d7a9868c864cfd3832034e1417a36e47 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Sun, 16 Mar 2025 13:48:31 +0100 Subject: [PATCH] don't inherit fields for tags that the preset already has a field for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is useful if a preset wants to inherit some fields from another preset, but wants to replace some of the fields with special versions of the field (e.g. a `…_yes` field for an added default value), or to change the `fields`/`moreFields` classification of a field --- CHANGELOG.md | 2 ++ modules/presets/preset.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c52f5712f..0679f94f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :earth_asia: Localization #### :hourglass: Performance #### :mortar_board: Walkthrough / Help +#### :rocket: Presets +* Don't inherit fields which the current preset already has a dedicated field for #### :hammer: Development [#10805]: https://github.com/openstreetmap/iD/pull/10805 diff --git a/modules/presets/preset.js b/modules/presets/preset.js index 13c1f487c..1f5f3d338 100644 --- a/modules/presets/preset.js +++ b/modules/presets/preset.js @@ -325,7 +325,7 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { } } - return utilArrayUniq(resolved); + return resolved; // returns an array of fields to inherit from the given presetID, if found @@ -335,7 +335,7 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { if (which === 'fields') { return parent.fields().filter(shouldInherit); } else if (which === 'moreFields') { - return parent.moreFields(); + return parent.moreFields().filter(shouldInherit); } else { return []; } @@ -349,6 +349,11 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { // inherit anyway if multiple values are allowed or just a checkbox f.type !== 'multiCombo' && f.type !== 'semiCombo' && f.type !== 'manyCombo' && f.type !== 'check' ) return false; + if (f.key && (_this.originalFields.some(originalField => f.key === allFields[originalField]?.key) + || _this.originalMoreFields.some(originalField => f.key === allFields[originalField]?.key))) { + // current preset already has a field for this field + return false; + } return true; }