From 8b1c37bdaf364b2aec815135a73172ef8436254d Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Sun, 16 Mar 2025 15:10:45 +0100 Subject: [PATCH] take location into account for default values from regional fields --- CHANGELOG.md | 1 + modules/presets/preset.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0679f94f8..a3684fe13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ _Breaking developer changes, which may affect downstream projects or sites that #### :mortar_board: Walkthrough / Help #### :rocket: Presets * Don't inherit fields which the current preset already has a dedicated field for +* Take location into account when setting a presets default values from regional fields #### :hammer: Development [#10805]: https://github.com/openstreetmap/iD/pull/10805 diff --git a/modules/presets/preset.js b/modules/presets/preset.js index 1f5f3d338..e8ab9ee3c 100644 --- a/modules/presets/preset.js +++ b/modules/presets/preset.js @@ -296,7 +296,7 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { fieldIDs.forEach(fieldID => { const match = fieldID.match(referenceRegex); if (match !== null) { // a presetID wrapped in braces {} - resolved = resolved.concat(inheritFields(allPresets[match[1]], which)); + resolved = resolved.concat(inheritFields(allPresets[match[1]], which, loc)); } else if (allFields[fieldID]) { // a normal fieldID resolved.push(allFields[fieldID]); } else { @@ -321,21 +321,26 @@ export function presetPreset(presetID, preset, addable, allFields, allPresets) { })]; } } - resolved = inheritFields(parent, which); + resolved = inheritFields(parent, which, loc); } } + if (loc) { + const validHere = locationManager.locationSetsAt(loc); + resolved = resolved.filter(field => !field.locationSetID || validHere[field.locationSetID]); + } + return resolved; // returns an array of fields to inherit from the given presetID, if found - function inheritFields(parent, which) { + function inheritFields(parent, which, loc) { if (!parent) return []; if (which === 'fields') { - return parent.fields().filter(shouldInherit); + return parent.fields(loc).filter(shouldInherit); } else if (which === 'moreFields') { - return parent.moreFields().filter(shouldInherit); + return parent.moreFields(loc).filter(shouldInherit); } else { return []; }