search presets by tag "key=value" syntax

closes #8869
This commit is contained in:
Martin Raifer
2022-05-25 10:51:01 +02:00
parent d486ab197d
commit 29d4ab6866
3 changed files with 18 additions and 1 deletions
+2
View File
@@ -61,6 +61,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
* Don't show non-language tag-suffixes in multilingual name field ([#9124], thanks [@wcedmisten])
* Render horse riding centers like farmyards ([#9118])
* Support searching presets by their `aliases` ([#6139])
* Allow searching presets by their tag (`key=value`) ([#8869])
#### Other
* Redact more API tokens from custom imagery sources in changeset metadata tags ([#8976], thanks [@k-yle])
#### :hammer: Development
@@ -70,6 +71,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
[#6139]: https://github.com/openstreetmap/iD/issues/6139
[#8774]: https://github.com/openstreetmap/iD/pull/8774
[#8811]: https://github.com/openstreetmap/iD/issues/8811
[#8869]: https://github.com/openstreetmap/iD/issues/8869
[#8905]: https://github.com/openstreetmap/iD/issues/8905
[#8925]: https://github.com/openstreetmap/iD/issues/8925
[#8927]: https://github.com/openstreetmap/iD/issues/8927
+11 -1
View File
@@ -158,6 +158,15 @@ export function presetCollection(collection) {
});
});
// matches key=value to preset.tags
let leadingTagKeyValues = [];
if (value.includes('=')) {
leadingTagKeyValues = searchable.filter(a => a.tags &&
Object.keys(a.tags).some(key => key + '=' + a.tags[key] === value))
.concat(searchable.filter(a => a.tags &&
Object.keys(a.tags).some(key => leading(key + '=' + a.tags[key]))));
}
let results = leadingNames.concat(
leadingSuggestions,
leadingNamesStripped,
@@ -167,7 +176,8 @@ export function presetCollection(collection) {
leadingTagValues,
similarName,
similarSuggestions,
similarTerms
similarTerms,
leadingTagKeyValues
).slice(0, MAXRESULTS - 1);
if (geometry) {
+5
View File
@@ -131,5 +131,10 @@ describe('iD.presetCollection', function() {
var collection = iD.presetCollection([excluded, p.point]);
expect(collection.search('excluded', 'point').collection).not.to.include(excluded);
});
it('matches tag key=value', function() {
var result = c.search('landuse=grass', 'area').collection;
expect(result.indexOf(p.grass1)).to.eql(0); // 1. 'Grass' (by tag key=value)
});
});
});