mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-30 00:40:25 +02:00
Fix regression where explicit addable presets were not populating the default preset list
This commit is contained in:
@@ -314,13 +314,23 @@ export function presetIndex() {
|
||||
|
||||
|
||||
_this.defaults = (geometry, n, startWithRecents) => {
|
||||
let rec = [];
|
||||
let recents = [];
|
||||
if (startWithRecents) {
|
||||
rec = _this.recent().matchGeometry(geometry).collection.slice(0, 4);
|
||||
recents = _this.recent().matchGeometry(geometry).collection.slice(0, 4);
|
||||
}
|
||||
const def = utilArrayUniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1);
|
||||
let defaults;
|
||||
if (_addablePresetIDs) {
|
||||
defaults = Array.from(_addablePresetIDs).map(function(id) {
|
||||
var preset = _this.item(id);
|
||||
if (preset && preset.matchGeometry(geometry)) return preset;
|
||||
return null;
|
||||
}).filter(Boolean);
|
||||
} else {
|
||||
defaults = _defaults[geometry].collection.concat(_this.fallback(geometry));
|
||||
}
|
||||
|
||||
return presetCollection(
|
||||
utilArrayUniq(rec.concat(def).concat(_this.fallback(geometry)))
|
||||
utilArrayUniq(recents.concat(defaults)).slice(0, n - 1)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -181,7 +181,8 @@ describe('iD.presetIndex', function () {
|
||||
describe('#addablePresetIDs', function () {
|
||||
var testPresets = {
|
||||
residential: { tags: { highway: 'residential' }, geometry: ['line'] },
|
||||
park: { tags: { leisure: 'park' }, geometry: ['point', 'area'] }
|
||||
park: { tags: { leisure: 'park' }, geometry: ['point', 'area'] },
|
||||
bench: { tags: { amenity: 'bench' }, geometry: ['point', 'line'] }
|
||||
};
|
||||
|
||||
it('addablePresetIDs is initially null', function (done) {
|
||||
@@ -210,6 +211,29 @@ describe('iD.presetIndex', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('addablePresetIDs are default presets', function (done) {
|
||||
iD.fileFetcher.cache().preset_presets = testPresets;
|
||||
var presets = iD.presetIndex();
|
||||
presets.ensureLoaded().then(function() {
|
||||
var ids = new Set(['bench', 'residential']); // can only add presets with these IDs
|
||||
presets.addablePresetIDs(ids);
|
||||
|
||||
var areaDefaults = presets.defaults('area', 10).collection;
|
||||
expect(areaDefaults.length).to.eql(0);
|
||||
|
||||
var pointDefaults = presets.defaults('point', 10).collection;
|
||||
expect(pointDefaults.length).to.eql(1);
|
||||
expect(pointDefaults[0].id).to.eql('bench');
|
||||
|
||||
var lineDefaults = presets.defaults('line', 10).collection;
|
||||
expect(lineDefaults.length).to.eql(2);
|
||||
expect(lineDefaults[0].id).to.eql('bench');
|
||||
expect(lineDefaults[1].id).to.eql('residential');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user