From c58964d797d45d1982e74cb627a6838e9ba86e05 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 10 Sep 2024 10:02:41 +0200 Subject: [PATCH] fix: filter feature by displayName by default fix #2106 --- umap/static/umap/js/modules/data/features.js | 7 ++++++- umap/static/umap/js/modules/data/layer.js | 2 +- umap/tests/integration/test_browser.py | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/modules/data/features.js b/umap/static/umap/js/modules/data/features.js index 0b334c81..4d4f0f83 100644 --- a/umap/static/umap/js/modules/data/features.js +++ b/umap/static/umap/js/modules/data/features.js @@ -508,7 +508,12 @@ class Feature { matchFilter(filter, keys) { filter = filter.toLowerCase() - if (Utils.hasVar(keys)) { + // When user hasn't touched settings, when a feature has no name + // it will use the datalayer's name, so let's make the filtering + // consistent. + // Also, if the user has defined a labelKey with vars, let's + // compute before filtering + if (Utils.hasVar(keys) || keys === 'displayName') { return this.getDisplayName().toLowerCase().indexOf(filter) !== -1 } keys = keys.split(',') diff --git a/umap/static/umap/js/modules/data/layer.js b/umap/static/umap/js/modules/data/layer.js index f1f7e627..f174d824 100644 --- a/umap/static/umap/js/modules/data/layer.js +++ b/umap/static/umap/js/modules/data/layer.js @@ -1115,7 +1115,7 @@ export class DataLayer { if (this.map.options.filterKey) return this.map.options.filterKey if (this.getOption('labelKey')) return this.getOption('labelKey') if (this.map.options.sortKey) return this.map.options.sortKey - return 'name' + return 'displayName' } renderLegend(container) { diff --git a/umap/tests/integration/test_browser.py b/umap/tests/integration/test_browser.py index 835b769f..9adad27f 100644 --- a/umap/tests/integration/test_browser.py +++ b/umap/tests/integration/test_browser.py @@ -176,6 +176,26 @@ def test_filter_works_with_variable_in_labelKey(live_server, page, map): expect(paths).to_have_count(1) # Only polygon +def test_filter_works_with_missing_name(live_server, page, map): + map.settings["properties"]["onLoadPanel"] = "databrowser" + map.save() + data = deepcopy(DATALAYER_DATA) + del data["features"][0]["properties"]["name"] + DataLayerFactory(map=map, data=data, name="foobar") + page.goto(f"{live_server.url}{map.get_absolute_url()}") + expect(page.get_by_title("Features in this layer: 3")).to_be_visible() + markers = page.locator(".leaflet-marker-icon") + paths = page.locator(".leaflet-overlay-pane path") + expect(markers).to_have_count(1) + expect(paths).to_have_count(2) + page.locator(".filters summary").click() + filter_ = page.locator("input[name='filter']") + expect(filter_).to_be_visible() + filter_.type("foob") + expect(markers).to_have_count(1) + expect(paths).to_have_count(0) + + def test_data_browser_can_show_only_visible_features(live_server, page, bootstrap, map): # Zoom on France page.goto(f"{live_server.url}{map.get_absolute_url()}#6/51.000/2.000")