Merge pull request #1572 from umap-project/real-counters

feat: adapt browser counter to the currently displayed features
This commit is contained in:
Yohan Boniface 2024-02-01 08:52:54 +01:00 committed by GitHub
commit 79bac2c353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -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)

View file

@ -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()