From 29d4ab6866f9ded6a3a4a7a04c76ad1bf0bda8fd Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Wed, 25 May 2022 10:51:01 +0200 Subject: [PATCH] search presets by tag "key=value" syntax closes #8869 --- CHANGELOG.md | 2 ++ modules/presets/collection.js | 12 +++++++++++- test/spec/presets/collection.js | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0643249c0..539220387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/modules/presets/collection.js b/modules/presets/collection.js index 3f4715b01..4caf173de 100644 --- a/modules/presets/collection.js +++ b/modules/presets/collection.js @@ -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) { diff --git a/test/spec/presets/collection.js b/test/spec/presets/collection.js index b2cb84e85..04a369a95 100644 --- a/test/spec/presets/collection.js +++ b/test/spec/presets/collection.js @@ -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) + }); }); });