take location into account for default values from regional fields

This commit is contained in:
Martin Raifer
2025-03-16 15:10:45 +01:00
parent 78f94632d7
commit 8b1c37bdaf
2 changed files with 11 additions and 5 deletions
+1
View File
@@ -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
+10 -5
View File
@@ -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 [];
}