From 60832797d05069428c7146d9a064e0ed8ff1b358 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 31 Jan 2024 08:06:21 +0100 Subject: [PATCH] feat: adapt browser counter to the currently displayed features --- umap/static/umap/js/umap.browser.js | 7 +++++-- umap/tests/integration/test_browser.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.browser.js b/umap/static/umap/js/umap.browser.js index 177ccb8f..01e2dcda 100644 --- a/umap/static/umap/js/umap.browser.js +++ b/umap/static/umap/js/umap.browser.js @@ -62,8 +62,6 @@ L.U.Browser = L.Class.extend({ container.id = `browse_data_datalayer_${datalayer.umap_id}` datalayer.renderToolbox(headline) L.DomUtil.add('span', '', headline, datalayer.options.name) - const counter = L.DomUtil.add('span', 'datalayer-counter', headline, datalayer.count()) - counter.title = L._('{count} features in this layer', {count: datalayer.count()}) const ul = L.DomUtil.create('ul', '', container) L.DomUtil.classIf(container, 'off', !datalayer.isVisible()) @@ -82,6 +80,11 @@ L.U.Browser = L.Class.extend({ } build() + let total = datalayer.count(), + current = ul.querySelectorAll('li').length, + count = total == current ? total : `${current}/${total}` + const counter = L.DomUtil.add('span', 'datalayer-counter', headline, count) + counter.title = L._('Features in this layer: {count}', {count: count}) datalayer.on('datachanged', build) datalayer.map.ui.once('panel:closed', () => { datalayer.off('datachanged', build) diff --git a/umap/tests/integration/test_browser.py b/umap/tests/integration/test_browser.py index f0a8c727..42a7353b 100644 --- a/umap/tests/integration/test_browser.py +++ b/umap/tests/integration/test_browser.py @@ -71,6 +71,7 @@ def test_data_browser_should_be_open(live_server, page, bootstrap, map): def test_data_browser_should_be_filterable(live_server, page, bootstrap, map): 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) @@ -78,6 +79,8 @@ def test_data_browser_should_be_filterable(live_server, page, bootstrap, map): filter_ = page.locator("input[name='filter']") expect(filter_).to_be_visible() filter_.type("poly") + expect(page.get_by_title("Features in this layer: 1/3")).to_be_visible() + expect(page.get_by_title("Features in this layer: 1/3")).to_have_text("1/3") expect(page.get_by_text("one point in france")).to_be_hidden() expect(page.get_by_text("one line in new zeland")).to_be_hidden() expect(page.get_by_text("one polygon in greenland")).to_be_visible()