mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-13 12:55:05 +02:00
take location into account for default values from regional fields
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user